Giter Club home page Giter Club logo

app-localtest's Introduction

Local testing of apps

These are some of the required steps, tips, and tricks when it comes to running an app on a local machine. The primary goal is to be able to iterate over changes and verifying them without needing to deploy the app to the test environment.

Prerequisites

  1. Newest .NET 6 SDK
  2. Newest Git
  3. A code editor - we like Visual Studio Code
  4. Podman Desktop/Podman (Linux users can also use native Docker) or Docker Desktop (Windows and Mac) This might require you to purchase a license. On mac with apple silicone (M1, M2, M3):
  5. vfkit

Setup

Clone the repository

git clone https://github.com/Altinn/app-localtest
cd app-localtest

Option A: Start the containers using podman

This mode supports running one app at a time. If you need to run multiple apps at once, stop the localtest container with podman stop localtest and follow the instructions below to run LocalTest locally outside Docker/Podman.

Important

If you are using an mac with either a M1, M2 or M3 chip you may need to use applehv instead of qemu as the podman machine driver. This can be done by setting the environment variable CONTAINERS_MACHINE_PROVIDER to applehv before running the command below. To add this to your zsh profile run the following command: echo "export CONTAINERS_MACHINE_PROVIDER=applehv" >> ~/.zprofile If you are using Podman Desktop you also need to add these lines in ~/.config/containers/containers.conf (check if the [machine] section already exists):

[machine]
  provider = "applehv"

Start the containers with the following command:

podman compose --file podman-compose.yml up -d --build

Optionally, if you want access to Grafana and a local monitoring setup based on OpenTelemetry:

podman compose --file podman-compose.yml --profile "monitoring" up -d --build
# Grafana should be available at http://local.altinn.cloud:8000/grafana
# Remember to enable the 'UseOpenTelemetry' configuration flag in the appsettings.json of the app

Note

If you are using linux or mac you can use the Makefile to build and run the containers.

make podman-start-localtest

Important

Are you running podman version < 4.7.0 you need to use the following command instead:

podman-compose --file podman-compose.yml up -d --build

or the make command:

make podman-compose-start-localtest

Localtest should now be runningn on port 8000 and can be accessed on http://local.altinn.cloud:8000.

Option B: Start the containers using Docker

This mode supports running one app at a time. If you need to run multiple apps at once, stop the localtest container with docker stop localtest and follow the instructions below to run LocalTest locally outside Docker.

docker compose up -d --build

Optionally, if you want access to Grafana and a local monitoring setup based on OpenTelemetry:

docker compose --profile "monitoring" up -d --build
# Grafana should be available at http://local.altinn.cloud/grafana
# Remember to enable the 'UseOpenTelemetry' configuration flag in the appsettings.json of the app

Note

If you are using linux or mac you can use the Makefile to build and run the containers.

make docker-start-localtest

Localtest should now be runningn on port 80 and can be accessed on http://local.altinn.cloud:80.

Option C (preview): Automatic detection

There is a preview helper script that will execute the correct commands in a cross-platform way. Either docker or podman must be installed.

./run.cmd

Optionally, if you want access to Grafana and a local monitoring setup based on OpenTelemetry:

./run.cmd -m

If the localtest setup is already running, it will restart.

To stop localtest

./run.cmd stop

Start your app

This step requires that you have already created an app, added a data model, and cloned the app to your local environment.

Move into the App folder of your application.

Example: If your application is named my-awesome-app and is located in the folder C:\my_applications, run the following command:

cd C:\my_applications\my-awasome-app\App

Run the application:

dotnet run

The app and local platform services are now running locally. The app can be accessed on http://local.altinn.cloud.

Log in with a test user, using your app name and org name. This will redirect you to the app.

Changing configuration

The Docker Compose config can be changed with local environment variables. There is a template file for the .env file here, rename it to .env and uncomment some variables that you want different values for.

Sometimes the local environment have another service running on port 80, so you might need to change this.

ALTINN3LOCAL_PORT=80

If you want to see the storage files on disk (instead of reading them through the browser), change this to a local path on your computer (ensure that it exists)

ALTINN3LOCALSTORAGE_PATH=C:/AltinnPlatformLocal/

If you want to use another domain than local.altinn.cloud for local testing you could do that this way:

TEST_DOMAIN=local.altinn.cloud

Multiple apps at the same time (running LocalTest locally)

The setup described above (LocalTest running in Docker) currently only supports one app at a time. If you find yourself needing to run multiple apps at the same time, or if you need to debug or develop LocalTest, a local setup is preferred.

ℹ️ If you're already running LocalTest in Docker, be sure to stop the container with docker stop localtest

Configuration of LocalTest The LocalTest application acts as an emulator of the Altinn 3 platform services. It provides things like authentication, authorization and storage. Everything your apps will need to run locally.

Settings (under LocalPlatformSettings):

  • LocalAppMode - (default file) If set to http, LocalTest will find the active app configuration and policy.xml using apis exposed on LocalAppUrl. (note that this is a new setting needs to be added manually under LocalPlatformSettings, it might also require updates to altinn dependencies for your apps in order to support this functionality)
  • LocalAppUrl - If LocalAppMode == "http", this URL will be used instead of AppRepositoryBasePath to find apps and their files. Typically the value will be "http://localhost:5005"
  • LocalTestingStorageBasePath - The folder to which LocalTest will store instances and data being created during testing.
  • AppRepositoryBasePath - The folder where LocalTest will look for apps and their files if LocalAppMode == "file". This is typically the parent directory where you checkout all your apps.
  • LocalTestingStaticTestDataPath - Test user data like profile, register and roles. (<path to altinn-studio repo>/testdata/)

The recommended way of changing settings for LocalTest is through user-secrets. User secrets is a set of developer specific settings that will overwrite values from the appsettings.json file when the application is started in developer "mode". The alternative is to edit the appsettings.json file directly. Just be careful not to commit developer specific changes back to the repository.

  • Define a user secret with the following command: (make sure you are in the LocalTest folder)
    dotnet user-secrets set "LocalPlatformSettings:AppRepositoryBasePath" "C:\Repos"
    Run the command for each setting you want to change.
  • Alternatively edit the appsettings.json file directly:
    • Open appsettings.json in the LocalTest folder in an editor, for example in Visual Studio Code
    • Change the setting "AppRepsitoryBasePath" to the full path to your app on the disk.
    • Change other settings as needed.
    • Save the file.

Finally, start the local platform services (make sure you are in the /src folder)

cd /src
dotnet run

Changing test data

In some cases your application might differ from the default setup and require custom changes to the test data available. This section contains the most common changes.

Add a missing role for a test user

This would be required if your app requires a role which none of the test users have.

  1. Identify the role list you need to modify by noting the userId of the user representing an entity, and the partyId of the entity you want to represent
  2. Find the correct roles.json file in testdata/authorization/roles by navigating to User_{userID}\party_{partyId}\roles.json
  3. Add a new entry in the list for the role you require
{
  "Type": "altinn",
  "value": "[Insert role code here]"
}
  1. Save and close the file
  2. Restart LocalTest

k6 testing

In the k6 folder there is a sample loadtest that can be adapted to run automated tests against a local app It was created to simulate workloads and test monitoring and instrumentation.

cp k6/loadtest.sample.js k6/loadtest.js
# Now make edits to k6/loadtest.js to fit your application

# To run, either
./run.cmd k6
# or 
docker run --rm -i --net=host grafana/k6:master-with-browser run - <k6/loadtest.js

For a decent editing experience, run npm install and use a editor with JS support.

Known issues

Localtest reports that the app is not running even though it is

If localtest and you app is running, but localtest reports that the app is not running, it might be that the port is not open in the firewall.

You can verify if the app is running by opening http://localhost:5005/<app-org-name>/<app-name>/swagger/index.html (remember to replace <app-org-name> and <app-name> with the correct values).

If this is the case you can open a Windows Powershell as administrator and run the script OpenAppPortInHyperVFirewall.ps1 located in the scripts folder.

app-localtest's People

Contributors

acn-dgopa avatar acn-sbuad avatar albertlarsen avatar allinox avatar altinnadmin avatar astromoskar avatar bjosttveit avatar chlenix avatar chrrust avatar danielskovli avatar dependabot[bot] avatar dskogan avatar hauklandj avatar henningnormann avatar hhegtun avatar ivarne avatar jeevananthank avatar lorang92 avatar magnusjerre avatar martinothamar avatar mijohansen avatar nkylstad avatar olemartinorg avatar renovate[bot] avatar ronnyb71 avatar sandgrainone avatar tba76 avatar thestokkan avatar thetecharch avatar tjololo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

app-localtest's Issues

Make "loadbalancer" build-free

Description

No need to build this image.

Additional Information

No response

Tasks

No response

Acceptance Criterias

No response

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update docker-compose non-major dependencies (grafana/grafana, grafana/tempo, otel/opentelemetry-collector-contrib)
  • chore(deps): update dependency @types/k6 to ^0.52.0
  • chore(deps): update grafana/grafana docker tag to v11
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
  • browserless/chrome 1-puppeteer-21.3.6
  • otel/opentelemetry-collector-contrib 0.98.0
  • grafana/tempo 2.4.1
  • grafana/mimir 2.12.0
  • grafana/loki 3.0.0
  • grafana/grafana 10.4.2
dockerfile
Dockerfile
  • mcr.microsoft.com/dotnet/sdk 6.0-alpine
  • mcr.microsoft.com/dotnet/aspnet 6.0-alpine
loadbalancer/Dockerfile
github-actions
.github/workflows/localtest-pr.yml
  • actions/checkout v3
  • actions/setup-dotnet v3
npm
package.json
  • @types/k6 ^0.50.1
nuget
src/LocalTest.csproj
  • Microsoft.Extensions.Http 7.0.0
  • Microsoft.Extensions.Caching.Memory 7.0.0
  • Microsoft.Extensions.Logging.Debug 7.0.0
  • libphonenumber-csharp 8.13.34
  • JWTCookieAuthentication 2.4.2
  • FluentValidation 11.8.0
  • AutoMapper.Extensions.Microsoft.DependencyInjection 12.0.0
  • Altinn.Platform.Storage.Interface 3.25.0
  • Altinn.Platform.Models 1.4.0
  • Altinn.Common.PEP 3.0.0
  • Altinn.Authorization.ABAC 0.0.8

  • Check this box to trigger a request for Renovate to run again on this repository

Missing implementation of LocalTest.Services.Storage.Implementation

Is your feature request related to a problem? Please describe

In OED we need to look up instances. Most of the methods in LocalTest.Services.Storage.Implementation are not implemented (throws NotImplementedException) - including all methods to search for instances.

Another problem is that the HomeController.GetTestOrgToken doesn't support setting read/write scopes need use APIs above.

Describe the solution you'd like

Implement the not implemented methods mentioned above, and add support for setting read/write scopes in GetTestOrgToken.

Describe alternatives you've considered

Additional context

Support using raw testdata from tenor in localtest

Description

Today there as, as far as I know, two possible ways testdata can be provided to localtest.

  1. Add the test data to the default set of testdata in the app-localtest repository
  2. Add a testData.json file and serve it from the application you are running locally

The testdata in localtest repo is separated in folders and multiple json files and in our own format.
The testData.json that can be added to an application is a concatenated version of the data from the folders in localtests testdata folders

https://testdata.skatteetaten.no (tenor) holds a rich set of testdata available for use in Altinns and IDportens test environments.
It is possible to download subsets of the testdata from tenor we should support using the json files from tenor directly with some additional metadata that Altinn needs to do authorisation decisions (if we need more?).

I belive this would be a nice addition and would make it possible/easy to use the same test persons/organisations in localtest as in tt02

Additional Information

No response

Change the name of `loadbalancer`

Description

The nginx thing running in localtest is not really a loadbalancer as it doesn't balance load. Its proabably more an ingress-controller. But unsure what a real good name would be to avoid misunderstandings.

Additional Information

No response

Make localtest work with podman desktop

Description

As Docker desktop is a paid product we should make localtest run nicely with podman desktop

Currently the main issue is the use of host-gateway in the docker-compose.yaml. Podman or compose fails to replace this with the ip address of the host.

The only place we actually need this is for the pdf service. We can work around this by changing a config value in the applications, but it would have been nice to not enforce any changes upon the app developers

Additional Information

Podman desktop

To low authentication level dont give expected feedback.

Description of the bug

When using to low authentication level when proceeding to app using localTest, it tells me that I don't have permission to start the services. This is not the expected message.
image

When testing the same app in tt02 or prod i get the expected message that tells me that I using too low sign-in method.
image

Steps To Reproduce

  1. open an app in local test http://local.altinn.cloud/ and select the authentication level that is too low.

Additional Information

No response

Create a very basic test in .NET

Description

Atm we doesn't have any tests in this repository, that have caused a lot of different issues for app developers. There should be at least one test that is run in pipeline that can verify that things are running smooth. This task is really to go from 0 test coverage to some test coverage.

Additional Information

No response

Tasks

No response

Acceptance Criterias

No response

Forhåndsvisning/testing av presentasjonsfelter i Localtest

What needs to be solved?

Det er behov for funksjonalitet for forhåndsvisning/testing av presentasjonsfelter (som beskrevet her: https://docs.altinn.studio/nb/app/development/configuration/messagebox/presentationfields/) i Lokaltest.

How do you want it solved?

Få på plass en fungerende innboks på testbrukerne som ligger i lokaltest.

Alternative solutions

En eller annen måte i lokaltest å teste at presentasjonsfeltene oppfører seg slik man har "konfigurert" de.

Additional context

Not able to open test application when running app-localtest with podman

Description of the bug

I did the following:

  1. Created a test application as outlined in https://docs.altinn.studio/nb/app/app-dev-course/
  2. Cloned app-localtest and followed the podman instructions in README.md
  3. I tried opening http://local.altinn.cloud:8000/ but got an error message
    An exception occured while fetching applicationData
    No application running on http://host.docker.internal:5005
    Please start your an app on this adress. Typically run the following command in an app directory.
    
    dotnet run
    
    
  4. However the application has been started with "dotnet run" as outlined in README.md and is running, listening to port 5005
image
  1. Tried opening http://host.docker.internal:5005 with curl but got "could not resolve host host.docker.internal":
    EMEAAD+sbang@AAP-5CG32757DH:~$ curl --verbose http://host.docker.internal:5005
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Could not resolve host: host.docker.internal
    * Closing connection
    curl: (6) Could not resolve host: host.docker.internal
    EMEAAD+sbang@AAP-5CG32757DH:~$
    
  2. I tried adding host.docker.internal as an alias for localhost in c:\Windows\System32\Drivers\etc\hosts
    # localhost name resolution is handled within DNS itself.
            127.0.0.1       localhost, host.docker.internal
            ::1             localhost, host.docker.internal
    
  3. This made http://host.docker.internal:5005 work with curl (but got 404 on the root)
  4. But http://local.altinn.cloud:8000/ still got the same error message
  5. Deleted the containers in podman and ran "podman compose --file podman-compose.yml up -d --build" again
  6. After the containers were up, tried http://local.altinn.cloud:8000/ but still got the same error message

Steps To Reproduce

  1. Create an Altinn test application
  2. Clone test application to a windows 11 machine
  3. Install podman desktop as outlined in the app-localtest README
  4. Run app-localtest with podman as outlined in the app-localtest README
  5. Try opening http://local.altinn.cloud:8000/ in a web browser and get the error message

Additional Information

Windows 11 Enterprise, Microsoft .Net SDK 6.0.418, podman desktop 1.7.1, podman 4.9.2

instance.InstanceOwner.Username er alltid null i lokaltest

Description of the bug

Som overskrift, når man instansierer en app og ser på feltet instance.InstanceOwner.Username i InstantiationValidator, så er feltet alltid null

Steps To Reproduce

Start app i lokaltest

Ha breakpoint på instance.InstanceOwner.Username

Additional Information

No response

Fields in nested repeating groups cannot be used in or from in resource-files

Description of the bug

We have a nested repeating Group, and we would like to use a value from the inner Group in a text appearing in the same inner Group. However, this doesn't work and just displays the {0} directly on the page:

    {
      "id": "mellomliggende.norskutenlandsk.title",
      "value": "__{0}__",
      "variables": [
        {
          "key": "skjemainnhold.skjemadata.reellRettighetshaver[{0}].posisjonEierMellomliggendeVirksomhet[{1}].virksomhet.navn",
          "dataSource": "dataModel.Brønnøysundregistrene_ReelleRettighetshavere_M"
        }
      ]
    },

It does work if you set it up like this (note the hardcoded array-keys):

    {
      "id": "mellomliggende.norskutenlandsk.title",
      "value": "__{0}__",
      "variables": [
        {
          "key": "skjemainnhold.skjemadata.reellRettighetshaver[0].posisjonEierMellomliggendeVirksomhet[0].virksomhet.navn",
          "dataSource": "dataModel.Brønnøysundregistrene_ReelleRettighetshavere_M"
        }
      ]
    },

But as soon as you try to use any variable in the key-part of the variable, it just displays {0}. This does NOT work, for instance (note only one variable in the key):

    {
      "id": "mellomliggende.norskutenlandsk.title",
      "value": "__{0}__",
      "variables": [
        {
          "key": "skjemainnhold.skjemadata.reellRettighetshaver[{0}].posisjonEierMellomliggendeVirksomhet[0].virksomhet.navn",
          "dataSource": "dataModel.Brønnøysundregistrene_ReelleRettighetshavere_M"
        }
      ]
    },

And for fun, trying to use a nested list-element outside of a nested list does not work (as expected), BUT it does not display {0} on the page, it displays nothing (which is as expected).

This bug was discovered in https://altinn.studio/repos/brg/rrh-innrapportering, though the code that triggers it is not merged yet.

Steps To Reproduce

  1. Create a nested Group
  2. Try to use a variable from the dataModel within the inner Group in a text within the inner Group.

Additional Information

No response

Support an easy way of generating inbound app events

Description

As more and more applications rely on both sending and receiving events as part of their application flow, it would be good to have a way of generating inbound events to be sent to the application and not only sending events out of the application.

This would increase the application development experience and avoid relying on tools like Postman.

Additional Information

No response

Tasks

No response

Acceptance Criterias

No response

LocalTest is missing an implementation for "get many instances"

Is your feature request related to a problem? Please describe

The filtering mechanism in Storage for the "get many" instances endpoint isn't implemented in the controller, but in the InstanceRepository class. The result being that LocalTest doesn't have any form of filtering on the matching endpoint. It is currently actually resulting in a NotImplementedException.

Describe the solution you'd like

This could be fixed in LocalTest by reimplementing the query logic and applying that to a list of all instances. In Storage the query is made before the request is sent to CosmosDB, but in LocalTest the filtering can be done on the complete list of all instances. I hope it is possible to use the same IQueryBuilder in both cases.

Describe alternatives you've considered

As an addition to this we could rewrite of the logic in Storage as well as LocalTest. I would like to have moved the filtering logic out of InstanceRepository. The construction of the Query could be done in a helper class of some kind or a "business logic service".

Additional context

Add any other context or screenshots about the feature request here.

Support app-frontend v4 when replacing frontend version

The code to replace the frontend version at runtime does not work correctly when Index.cshtml uses any other path than /3/. We should at least support /4/, but it would be even better to support any pinned version of frontend.

Bind mounts not working on some setups with podman

Description of the bug

In some setup with podman the folders mounted as bind-mounts from the host gives Permission denied on all files and folders.
A hacky fix is just running some containers with podman run with the volumes mounted with the flag z.
Not sure if this is a problem related to selinux or not, but might be something we need to report back to podman

Steps To Reproduce

Experienced in Apple M3 and Fedora with selinx (not tested fedora without selinux)

  1. Start localtest on Apple M3 or Fedora with a fresh install of podman
  2. See that nginx returns the defualt nginx page
  3. run the hack function in Makefile
  4. restart nginx container, should now serve the localtest page

Additional Information

No response

When importing a person with a role in a NUF from Tenor in User administation, the app crashes.

Description of the bug

When importing a person who is "Daglig leder" or similar for a NUF from Tenor, the app crashes when you try to view testData.json or try using the app on local.altinn.cloud. Importing the NUFs themselves or even the UTLAs they reference do not cause this to happen.

Not 100% this is exclusive to NUF role havers, but it does happen with "KONGE FIKEN" and "MOBIL KJØTTBOLLE" from Tenor at the very least.

image

Steps To Reproduce

  1. Import a person with a role in a NUF.
  2. Try to use the app from local.altinn.cloud or view testData.json.

Additional Information

No response

Upgrade LocalTest to .NET 7

Description

We should decide if this is something we want to do, and then do it 😎

Additional Information

No response

Tasks

  • Upgrade to .NET 7 and fix any issues that arise.

Acceptance Criterias

No response

404 Response from local.altinn.cloud Despite Running Containers on Docker Desktop

Description of the bug

After cloning the project and ensuring all containers are successfully running on Docker Desktop, attempts to access the service at local.altinn.cloud result in a 404 Not Found response. This issue persists even after verifying container statuses and network configurations within Docker Desktop.

Steps To Reproduce

Clone the repository from GitHub.
Start all containers using Docker Desktop.
Verify all containers are running without errors.
Navigate to http://local.altinn.cloud in a web browser.

Additional Information

No modifications were made to the Docker configurations or the project's source code after cloning.
Network settings within Docker Desktop appear to be configured correctly, with no obvious conflicts or misconfigurations.
Other services running on Docker Desktop (if any) are functioning normally.
The issue persists even when switching to Rancher Desktop, indicating that the problem is not specific to Docker Desktop.
All necessary ports appear to be open and not in conflict with other services.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.