These are some of the required steps, tips and tricks when it comes to running an app on a 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.
- Newest .NET 5 SDK
- Newest Git
- A code editor - we like Visual Studio Code
- Also install recommended extensions (f.ex. C#)
- For Windows/MacOS Docker Desktop
- Update hosts file (C:/Windows/System32/drivers/etc/hosts) by adding the following values. On MacOS add the same values to values /private/etc/hosts using cmd
sudo nano /private/etc/hosts
.127.0.0.1 altinn3local.no
-
Clone the altinn-studio repository to a local folder
git clone https://github.com/Altinn/altinn-studio cd altinn-studio
-
Navigate to the
development
folder in the altinn-studio repocd src/development
-
Setting up loadbalancer
This is unfortunately different based on type of operating system you have on your machine.- Windows:
Start the loadbalancer container that routes between the local platform services and the appdocker-compose up -d --build
- Linux:
Install NGINXEdit the NGINX configurationsudo apt-get update sudo apt-get install nginx sudo service nginx start
Modify the default to this:cd /etc/nginx sudo nano nginx.conf
Save and go back to src/develpment folder in altinn-studioworker_processes 1; events { worker_connections 1024; } http { client_max_body_size 50M; sendfile on; upstream localtest { server 127.0.0.1:5101; } upstream app { server 127.0.0.1:5005; } server { listen 80; server_name altinn3local.no localhost; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location = / { proxy_pass http://localtest/Home/; } location / { proxy_pass http://app/; } location /Home/ { proxy_pass http://localtest/Home/; } location /localtestresources/ { proxy_pass http://localtest/localtestresources/; } } }
Reload NGINX configurationsudo nginx -s reload
- Windows:
-
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
- (defaultfile
) If set tohttp
, LocalTest will find the active app configuration and policy.xml using apis exposed onLocalAppUrl
. (note that this is a new setting needs to be added manually underLocalPlatformSettings
, it might also require updates to altinn dependencies for your apps in order to support this functionality)LocalAppUrl
- IfLocalAppMode
=="http"
, this URL will be used instead ofAppRepositoryBasePath
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 ifLocalAppMode
=="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>/src/development/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 theappsettings.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)
Run the command for each setting you want to change.
dotnet user-secrets set "LocalPlatformSettings:AppRepositoryBasePath" "C:\Repos"
- Alternatively edit the appsettings.json file directly:
- Open
appsettings.json
in theLocalTest
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.
- Open
-
Start the local platform services (make sure you are in the LocalTest folder)
dotnet run
-
Navigate to the app folder (specified in the step above)
cd \.\<path to app on disk>
-
Start the app locally
dotnet run -p App.csproj
The app and local platform services are now running locally. The app can be accessed on http://altinn3local.no.
Log in with a test user, using your app name and org name. This will redirect you to the app.
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.
This would be required if your app requires a higher than default authentication level. You can also use this to give the user a lower authentication level if you want to test the app behaviour for those.
- Open the
src/development/LocalTest/Controllers/HomeController.cs
in your preffered text editor or IDE. - Find the function
LogInTestUser
- Modify this line
claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, issuer));
, by exchanging"2"
for a string containing your required authentication level. - Save and close the file
- Restart LocalTest
This would be required if your app requires a role which none of the test users have.
- 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
- Find the correct
roles.json
file inC:\Repos\altinn-studio\src\development\TestData\authorization\roles
by navigating toUser_{userID}\party_{partyId}\roles.json
- Add a new entry in the list for the role you require
{
"Type": "altinn",
"value": "[Insert role code here]"
}
- Save and close the file
- Restart LocalTest