You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Using $client->loginUser in KernelTestCase when sending multiple requests will only work for a single request and return 401/Unauthorized for all subsequent requests.
// Helper to login user
public function loginUser(KernelBrowser $client): KernelBrowser
{
/** @var UserRepositoryInterface $repository $repository */
$repository = static::getContainer()->get(UserRepositoryInterface::class);
// Get first user
$user = $repository->find(1);
$client->loginUser($user, static::$firewallContext);
return $client;
}
// Test case
public function testShouldReturn404() {
$this->loginUser($this->client);
$urls = [
"/api/v1/endpoint",
"/api/v1/endpoint",
];
$this->client->request("POST", $urls[0]);
// This assertion succeeds
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
$this->client->request("POST", $urls[1]);
// This assertion fails
$this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
I have also tried calling loginUser again but it returns the same result
How to reproduce
Create firewall protected endpoint
Send multiple requests to same endpoint with authenticated KernelBrowser
The text was updated successfully, but these errors were encountered:
crtl
changed the title
[Testing] Client::loginUser not working with subsequent requests
[Testing] KernelBrowser::loginUser not working with subsequent requests
Sep 2, 2021
Symfony version(s) affected: 5.3
Description
Using
$client->loginUser
in KernelTestCase when sending multiple requests will only work for a single request and return 401/Unauthorized for all subsequent requests.I have also tried calling
loginUser
again but it returns the same resultHow to reproduce
The text was updated successfully, but these errors were encountered: