Mock Auth0 API login in Behat tests

174 Views Asked by At

In a large project based on symfony and API platform, I am migrating the authentication from a JWT bearer token to auth0 access token.

The migration is working well for users, but we have a lot of Behat tests to ensure the API is working. Currently these tests still uses the old authentication method, but we need to be able to migrate them as well in order to fully remove the old authentication method.

The problem is I haven't found any information on how to "mock" auth0 login for API testing with Behat. Has anyone relevant info on how to do so ?

For reference, here is the current behat implementation of the JWT bearer login :

CustomKernelApiContext.php
    /**
     * @Given I am authenticated as :username
     */
    public function iAmAuthenticatedAs(string $username): void
    {
        $user = $this->apiUserProvider->loadUserByUsername($username);

        $token = $this->kernel->getContainer()->get('lexik_jwt_authentication.jwt_manager')->create($user);
        $this->addRequestHeader('HTTP_AUTHORIZATION', 'Bearer ' . $token);
    }
0

There are 0 best solutions below