Altinn / app-localtest

Solution for testing apps locally on your own machine
8 stars 14 forks source link

Fix for local testing for `altinn-receipt` #91

Open khanrn opened 6 months ago

khanrn commented 6 months ago

Fix for local testing for altinn-receipt

Description

While this solution addresses local testing for altinn-receipt, I'm open to exploring alternative methods that don't involve modifying the docker-compose.yml file directly. If you have any ideas or suggestions, please provide your input here. 🙂

Related Issue(s)

Verification

Documentation

ivarne commented 6 months ago

Can you explain how and why this will fix anything? Does localtest need to call authorization endpoints over http?

You'll also need to fix https://github.com/Altinn/app-localtest/blob/main/podman-compose.yml

khanrn commented 6 months ago

@ivarne You are correct! This change need to reflect the podman-comose.yml as well. But I skipped that as I was quite certain(as I mentioned in the Slack discussion) that this PR would raise a discussion. Therefore I wanted to find the best approach to achieve this first before doing any further change. 🙂

Now the question is why this change?

When testing altinn-receipt in locally it calls the /authentication/api/v1/openid/.well-known/openid-configuration to get the OpenID configuration and that configuration is returned by app-localtest. And in that configuration if the address is localhost then altinn-receipt calls localhost:5101 which ends up calling it's own localhost. Here we want altinn-receipt to call host.docker.internal:5101. Therefore this change came.

Related Issue(s) and PR(s)

ivarne commented 6 months ago

What do you mean by testing altinn-receipt in locally. Do you run the https://github.com/Altinn/altinn-receipt project locally?

I don't see how changing the environment variables for the localtest mock project does anything to the receipt project?

khanrn commented 6 months ago

@ivarne Yes. You are correct I'm referring to testing https://github.com/Altinn/altinn-receipt project locally.

So when the altinn-receipt app is getting tested against app-localtest it gets the SocketException: Address not available (see the first screenshot) error as when it is reaching out to localhost:5101 it is actually going for it's own as this runs in an individual docker container. Then a it turns out that the values from the OpenID configuration (see the first screenshot) is creating the issue which is generated by app-localtest with the environment variables proposed here for change. Because this environment variable is actually giving the altinn-receipt the address localhost:5101. This proposed fix with the PR mentioned in the Related Issue(s) section of this PR fixed the issue.

I must admit that it is not the best way to fix it. It'd be better if we can have this in the .env configuration. Or can set the environment over CLI.🤔

  1. SocketException: Address not available

    Screenshot 2024-03-05 at 15 35 17

  2. openid-configuration

    Screenshot 2024-03-05 at 15 36 23

ivarne commented 6 months ago

Aha, Now I understand. This "fix" will likely break apps that use this endpoint to get the json web keys to verify cookies when running outside of docker (all of them), so we need a better solution.

ivarne commented 6 months ago

Maybe @tjololo has some ideas for how the openIdConnect endpoint can reply with an url for the keys that works both inside and outside docker?

SandGrainOne commented 6 months ago

@ivarne I'm unable to test an app locally on my machine without changes for podman. I get it working by adding:

  "AuthnGeneralSettings": {
    "PlatformEndpoint": "http://local.altinn.cloud:5101/"
  },

to the appsettings.podman.json file.