mercredi 29 juillet 2020

Symfony Panther authentication seems not to be taken into account

I am using Symfony Panther for some testing.

When I want to log an User like this :

    protected function setUpPanther()
    {
        $client = static::createPantherClient(['readinessPath' => '/error']);
        $client->manage()->window()->maximize();
        $this->client = $client;
    }

    protected function loginPantherClient(Client $client, User $user)
    {
        $client->request('GET', '/error');

        $session = self::$container->get('session');

        $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
        $session->set('_security_main', serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());

        $client->getCookieJar()->set($cookie);
    }

    public function testUpdateProductDetails()
    {
        $this->setUpPanther();
        
        $admin = $this->getSuperAdminAccount();

        $this->loginPantherClient($this->client, $admin);
        $this->client->request('GET', '/');
        $this->assertSelectorExists('div.form-group');
    }

A strange phenomenon occurs.

  1. My client goes to the error page to initialize the cookie (required)

  2. And here I have the impression that the authentication of my client is not taken into account, because if you look closely, in my test, I then make a request on

$this->client->request('GET', '/');

But instead of redirecting me to the requested page, it redirects me to / login, as if during the request, the user was not authenticated, and therefore, was redirected to the login page, while in my code, I authenticate the user before

Has someone already had this problem ?

Sorry for my bad english, I'm French, I'm using Google traduction

Aucun commentaire:

Enregistrer un commentaire