@@ -79,7 +79,7 @@ public function testConsumeRememberMeCookieValid()
7979 $ this ->tokenProvider ->expects ($ this ->any ())
8080 ->method ('loadTokenBySeries ' )
8181 ->with ('series1 ' )
82- ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTimeImmutable ('-10 min ' )))
82+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , $ lastUsed = new \DateTimeImmutable ('-10 min ' )))
8383 ;
8484
8585 $ this ->tokenProvider ->expects ($ this ->once ())->method ('updateToken ' )->with ('series1 ' );
@@ -97,11 +97,41 @@ public function testConsumeRememberMeCookieValid()
9797
9898 $ this ->assertSame ($ rememberParts [0 ], $ cookieParts [0 ]); // class
9999 $ this ->assertSame ($ rememberParts [1 ], $ cookieParts [1 ]); // identifier
100- $ this ->assertSame ( $ rememberParts [ 2 ], $ cookieParts [2 ]); // expire
100+ $ this ->assertEqualsWithDelta ( $ lastUsed -> getTimestamp () + 31536000 , ( int ) $ cookieParts [2 ], 2 ); // expire
101101 $ this ->assertNotSame ($ rememberParts [3 ], $ cookieParts [3 ]); // value
102102 $ this ->assertSame (explode (': ' , $ rememberParts [3 ])[0 ], explode (': ' , $ cookieParts [3 ])[0 ]); // series
103103 }
104104
105+ public function testConsumeRememberMeCookieInvalidOwner ()
106+ {
107+ $ this ->tokenProvider ->expects ($ this ->any ())
108+ ->method ('loadTokenBySeries ' )
109+ ->with ('series1 ' )
110+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTime ('-10 min ' )))
111+ ;
112+
113+ $ rememberMeDetails = new RememberMeDetails (InMemoryUser::class, 'jeremy ' , 360 , 'series1:tokenvalue ' );
114+
115+ $ this ->expectException (AuthenticationException::class);
116+ $ this ->expectExceptionMessage ('The cookie \'s hash is invalid. ' );
117+ $ this ->handler ->consumeRememberMeCookie ($ rememberMeDetails );
118+ }
119+
120+ public function testConsumeRememberMeCookieInvalidValue ()
121+ {
122+ $ this ->tokenProvider ->expects ($ this ->any ())
123+ ->method ('loadTokenBySeries ' )
124+ ->with ('series1 ' )
125+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTime ('-10 min ' )))
126+ ;
127+
128+ $ rememberMeDetails = new RememberMeDetails (InMemoryUser::class, 'wouter ' , 360 , 'series1:tokenvalue:somethingelse ' );
129+
130+ $ this ->expectException (AuthenticationException::class);
131+ $ this ->expectExceptionMessage ('This token was already used. The account is possibly compromised. ' );
132+ $ this ->handler ->consumeRememberMeCookie ($ rememberMeDetails );
133+ }
134+
105135 public function testConsumeRememberMeCookieValidByValidatorWithoutUpdate ()
106136 {
107137 $ verifier = $ this ->createMock (TokenVerifierInterface::class);
0 commit comments