|  | 
| 17 | 17 | use Symfony\Component\HttpFoundation\RequestStack; | 
| 18 | 18 | use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; | 
| 19 | 19 | use Symfony\Component\Security\Core\Authentication\RememberMe\TokenProviderInterface; | 
|  | 20 | +use Symfony\Component\Security\Core\Authentication\RememberMe\TokenVerifierInterface; | 
| 20 | 21 | use Symfony\Component\Security\Core\Exception\AuthenticationException; | 
| 21 | 22 | use Symfony\Component\Security\Core\Exception\CookieTheftException; | 
| 22 | 23 | use Symfony\Component\Security\Core\User\InMemoryUser; | 
| @@ -102,6 +103,42 @@ public function testConsumeRememberMeCookieValid() | 
| 102 | 103 |         $this->assertSame(explode(':', $rememberParts[3])[0], explode(':', $cookieParts[3])[0]); // series | 
| 103 | 104 |     } | 
| 104 | 105 | 
 | 
|  | 106 | +    public function testConsumeRememberMeCookieValidByValidatorWithoutUpdate() | 
|  | 107 | +    { | 
|  | 108 | +        $verifier = $this->createMock(TokenVerifierInterface::class); | 
|  | 109 | +        $handler = new PersistentRememberMeHandler($this->tokenProvider, 'secret', $this->userProvider, $this->requestStack, [], null, $verifier); | 
|  | 110 | + | 
|  | 111 | +        $persistentToken = new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('30 seconds')); | 
|  | 112 | + | 
|  | 113 | +        $this->tokenProvider->expects($this->any()) | 
|  | 114 | +            ->method('loadTokenBySeries') | 
|  | 115 | +            ->with('series1') | 
|  | 116 | +            ->willReturn($persistentToken) | 
|  | 117 | +        ; | 
|  | 118 | + | 
|  | 119 | +        $verifier->expects($this->any()) | 
|  | 120 | +            ->method('verifyToken') | 
|  | 121 | +            ->with($persistentToken, 'oldTokenValue') | 
|  | 122 | +            ->willReturn(true) | 
|  | 123 | +        ; | 
|  | 124 | + | 
|  | 125 | +        $rememberMeDetails = new RememberMeDetails(InMemoryUser::class, 'wouter', 360, 'series1:oldTokenValue'); | 
|  | 126 | +        $handler->consumeRememberMeCookie($rememberMeDetails); | 
|  | 127 | + | 
|  | 128 | +        // assert that the cookie has been updated with a new base64 encoded token value | 
|  | 129 | +        $this->assertTrue($this->request->attributes->has(ResponseListener::COOKIE_ATTR_NAME)); | 
|  | 130 | + | 
|  | 131 | +        /** @var Cookie $cookie */ | 
|  | 132 | +        $cookie = $this->request->attributes->get(ResponseListener::COOKIE_ATTR_NAME); | 
|  | 133 | + | 
|  | 134 | +        $cookieParts = explode(':', base64_decode($cookie->getValue()), 4); | 
|  | 135 | + | 
|  | 136 | +        $this->assertSame(InMemoryUser::class, $cookieParts[0]); // class | 
|  | 137 | +        $this->assertSame(base64_encode('wouter'), $cookieParts[1]); // identifier | 
|  | 138 | +        $this->assertSame('360', $cookieParts[2]); // expire | 
|  | 139 | +        $this->assertSame('series1:tokenvalue', $cookieParts[3]); // value | 
|  | 140 | +    } | 
|  | 141 | + | 
| 105 | 142 |     public function testConsumeRememberMeCookieInvalidToken() | 
| 106 | 143 |     { | 
| 107 | 144 |         $this->expectException(CookieTheftException::class); | 
|  | 
0 commit comments