API Testing with postman
To test API endpoints the tool postman enables easy configuration and setup of various HTTP requests, read more about postman here.
Several of the exposed APIs requires various cookies, for instance authentication and gitea information. To be able to do requests against these APIs the cookies have to be included in the HTTP request, and configured in postman. The cookies can be found in the following way:
- In your browser login to dev.altinn.studio/altin.studio/altinn3.no depending on what environment you are targeting
- Notice that the cookies AltinnStudioDesigner, AltinnStudioRuntime and i_like_gitea (among others) has been saved for the domain name you have logged in to.
- For Chrome cookies can be found under settings -> advanced -> cookies -> see all.
The two cookies AltinnStudioDesigner and AltinnStudioRuntime works as auth against the Designer and APP API respectively, so if you are targeting a Designer API you should include the AltinnStudioDesigner cookie, along with the i_like_gitea cookie, and if you are targeting a runtime API the AltinnStudioRuntime cookie should be included. Cookies are easily added to the postman requests under the slightly hidden cookies setting, see:
Set up postman tests
- Download and install postman native app.
- Import the files from src/test/Postman/Collection to the collections area in Postman.
- Import the environment .json file from src/test/Postman to the environments area in Postman.
How to write postman tests
- Find the area/collection where the new test has to be added.
- Add a new request of type GET/POST/PUT/DELETE under the right folder.
- Provide the endpoint, input for the request.
- Make sure the variable values are accessed from environments file.
- Tests should have one test to verify valid response code and another test to validate the content of the response.
Postman test pipeline in Azure Devops
Information about the postman collections
- Collections folder include postman collections for Platform API, Storage API, APP API.
- Platform API uses Platform.postman_environment as an environment file.
- Storage, App API and Negative tests uses App.postman_environment as an environment file.
- One has to fill in the values (testdata) in the environment file based on the environment under test.
- The collections has steps that would authenticate an user and set appropriate cookies.
Run Postman tests against a test environment.
- Open Postman and Import the Postman collection file and the corresponding envrinonment file.
- Select the environment file and fill in the necesary information for the required collection.
- Required Test data for App / Storage / Negative Tests Collection are envUrl, org(appOwner, app(level2-app), testUserName(level2LoginUser), testUserPassword(use same password for two users), level3-app, level1-app, testUserName2(level1LoginUser)
- Required Test data for Platform are envUrl, org(appOwner), app(level2-app), partyID, SSN, OrgNr, userID
- Open the Postman runner -> Select the collection and environment and click ‘Start Run’
Note: newman can be used to a Postman collection from command line interface.