-
Notifications
You must be signed in to change notification settings - Fork 27
Description
In chapter 13 is shown how to test your own APIs making use of the trick MS is using with respect to authentication as "Including the authentication in tests would be quite cumbersome" as I state in the following section (taken from chapter 13):
Authenticating the client
The next challenge is the authentication of the client as the service being called upon will require the client’s credentials. Including the authentication in tests would be quite cumbersome, and therefore the Microsoft Business Central team has chosen the practical approach, focusing on testing the API business logic and not validating the authentication. As such API tests are run in a database with no user and user-related data. In order to achieve this, the following needs to be done:
- Set up your Business Central environment to use Windows authentication.
- Remove all user and user-related data from the database.
- Deploy your extension(s) with your application and test code.
- Run the tests with standard test runner
Test Runner - Isol. Disabled(130451).
Note that with this approach, we ignore testing the authorization to the server.
Trade-off
The trade-off of using Windows authentication is that it is not (easily) possible to get your API tests run in a pipeline as most probably the various parts of the pipeline are not run/triggered in your domain.
Alternative trick
Triggered by my Dutch Dynamics Community presentation, and later my Areopa webinar, Automated testing of your Business Central API Arend-Jan Kauffmann - who else - suggested to use the following trick allowing the usage of basic authentication. In this we are assuming we're using a docker container.
- When building the docker container for testing the APIs the user and password are known
- Adjust the script in such a way that it:
a. adds an extension which introduces a table in BC - let's call itTest Setup- with a field in which the password can be stored
b. populates that field with the password - Design your API tests to make use of this password (combined with the user)