Updating our tests
Excellent, our application is now protected against unauthorized access. However, we need to make sure that our tests are updated as well. If we run our test suite now, we will see that all the tests are failing because they are also unable to access authentication-protected pages and API endpoints. So, we need to allow our tests to authenticate as well.
Enabling basic authentication
How can we authenticate our tests – and non-human users in general? We want to allow automation and scripts, like our tests, to access specific user data without having to go through the login process. There are a few methods for authenticating non-human users, and one of the most common and simplest is to use the so-called basic authentication. This is a standard HTTP authentication method, which allows us to restrict access to our server using the HTTP Basic
schema.
To put it very simply, the Basic
schema allows us to send a username and password in the HTTP request...