Arnouxor
1 month ago
122
0
Testing

Testing Passport and HTTP Requests maker

Posted 1 month ago by Arnouxor

Hello guys!

During my unit tests when I call two times the same Passport webservice with two differents access token (with two different Scope), Laravel seems to keep in memory my first access token even if I flush the headers.

This is my code:

        // first call with a superadmin access token, the return should be 200 and is 200
        $this->withToken($superAdminAccessToken)
            ->getJson("project.dev/contact")
            ->assertStatus(200);

        // second call with a user access token, the return should be 403 but I have a 200
        $this->flushHeaders()->withToken($userAccessToken)
            ->getJson("project.dev/contact")
            ->assertStatus(403);

If I change the order

        // first call with a User access token, the return should be 403 and is 403
        $this->withToken($userAccessToken)
            ->getJson("project.dev/contact")
            ->assertStatus(403);
        
        // second call with a superadmin access token, the return should be 200 and is 403
        $this->flushHeaders()
            ->withToken($superAdminAccessToken)
            ->getJson("project.dev/contact")
            ->assertStatus(200);

It's really weird because it seems to be okay when I look the header of the HTTP Request maker (the token is well changed in the bearer param). So it looks like the backend keep something in cache but I don't know what.

Do you have any idea?

Thank you for your help,

Please sign in or create an account to participate in this conversation.