@@ -80,7 +80,7 @@ public function testConsumeRememberMeCookieValid()
80
80
$ this ->tokenProvider ->expects ($ this ->any ())
81
81
->method ('loadTokenBySeries ' )
82
82
->with ('series1 ' )
83
- ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTime ('-10 min ' )))
83
+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , $ lastUsed = new \DateTime ('-10 min ' )))
84
84
;
85
85
86
86
$ this ->tokenProvider ->expects ($ this ->once ())->method ('updateToken ' )->with ('series1 ' );
@@ -98,11 +98,41 @@ public function testConsumeRememberMeCookieValid()
98
98
99
99
$ this ->assertSame ($ rememberParts [0 ], $ cookieParts [0 ]); // class
100
100
$ this ->assertSame ($ rememberParts [1 ], $ cookieParts [1 ]); // identifier
101
- $ this ->assertSame ( $ rememberParts [ 2 ], $ cookieParts [2 ]); // expire
101
+ $ this ->assertEqualsWithDelta ( $ lastUsed -> getTimestamp () + 31536000 , ( int ) $ cookieParts [2 ], 2 ); // expire
102
102
$ this ->assertNotSame ($ rememberParts [3 ], $ cookieParts [3 ]); // value
103
103
$ this ->assertSame (explode (': ' , $ rememberParts [3 ])[0 ], explode (': ' , $ cookieParts [3 ])[0 ]); // series
104
104
}
105
105
106
+ public function testConsumeRememberMeCookieInvalidOwner ()
107
+ {
108
+ $ this ->tokenProvider ->expects ($ this ->any ())
109
+ ->method ('loadTokenBySeries ' )
110
+ ->with ('series1 ' )
111
+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTime ('-10 min ' )))
112
+ ;
113
+
114
+ $ rememberMeDetails = new RememberMeDetails (InMemoryUser::class, 'jeremy ' , 360 , 'series1:tokenvalue ' );
115
+
116
+ $ this ->expectException (AuthenticationException::class);
117
+ $ this ->expectExceptionMessage ('The cookie \'s hash is invalid. ' );
118
+ $ this ->handler ->consumeRememberMeCookie ($ rememberMeDetails );
119
+ }
120
+
121
+ public function testConsumeRememberMeCookieInvalidValue ()
122
+ {
123
+ $ this ->tokenProvider ->expects ($ this ->any ())
124
+ ->method ('loadTokenBySeries ' )
125
+ ->with ('series1 ' )
126
+ ->willReturn (new PersistentToken (InMemoryUser::class, 'wouter ' , 'series1 ' , 'tokenvalue ' , new \DateTime ('-10 min ' )))
127
+ ;
128
+
129
+ $ rememberMeDetails = new RememberMeDetails (InMemoryUser::class, 'wouter ' , 360 , 'series1:tokenvalue:somethingelse ' );
130
+
131
+ $ this ->expectException (AuthenticationException::class);
132
+ $ this ->expectExceptionMessage ('This token was already used. The account is possibly compromised. ' );
133
+ $ this ->handler ->consumeRememberMeCookie ($ rememberMeDetails );
134
+ }
135
+
106
136
public function testConsumeRememberMeCookieValidByValidatorWithoutUpdate ()
107
137
{
108
138
$ verifier = $ this ->createMock (TokenVerifierInterface::class);
0 commit comments