@@ -65,8 +65,8 @@ protected function setUp(): void
65
65
$ this ->mockTokenGenerator = $ this ->createMock (ResetPasswordTokenGenerator::class);
66
66
$ this ->mockCleaner = $ this ->createMock (ResetPasswordCleaner::class);
67
67
$ this ->mockResetRequest = $ this ->createMock (ResetPasswordRequestInterface::class);
68
- $ this ->randomToken = \bin2hex (\random_bytes (10 ));
69
- $ this ->mockUser = new class () {};
68
+ $ this ->randomToken = \bin2hex (\random_bytes (20 ));
69
+ $ this ->mockUser = new class {};
70
70
}
71
71
72
72
private function getPasswordResetHelper (): ResetPasswordHelper
@@ -173,7 +173,7 @@ public function testRemoveResetRequestRetrievesTokenFromRepository(): void
173
173
$ this ->mockRepo
174
174
->expects ($ this ->once ())
175
175
->method ('findResetPasswordRequest ' )
176
- ->with ($ this ->randomToken )
176
+ ->with (\substr ( $ this ->randomToken , 0 , 20 ) )
177
177
->willReturn ($ this ->mockResetRequest )
178
178
;
179
179
@@ -198,6 +198,14 @@ public function testRemoveResetRequestCallsRepositoryToRemoveResetRequestObject(
198
198
$ helper ->removeResetRequest ('1234 ' );
199
199
}
200
200
201
+ public function testExceptionThrownIfTokenLengthIsNotOfCorrectSize (): void
202
+ {
203
+ $ this ->expectException (InvalidResetPasswordTokenException::class);
204
+
205
+ $ helper = $ this ->getPasswordResetHelper ();
206
+ $ helper ->validateTokenAndFetchUser (\substr ($ this ->randomToken , 0 , 39 ));
207
+ }
208
+
201
209
public function testExceptionIsThrownIfTokenNotFoundDuringValidation (): void
202
210
{
203
211
$ this ->mockRepo
@@ -209,7 +217,7 @@ public function testExceptionIsThrownIfTokenNotFoundDuringValidation(): void
209
217
$ this ->expectException (InvalidResetPasswordTokenException::class);
210
218
211
219
$ helper = $ this ->getPasswordResetHelper ();
212
- $ helper ->validateTokenAndFetchUser (' 1234 ' );
220
+ $ helper ->validateTokenAndFetchUser ($ this -> randomToken );
213
221
}
214
222
215
223
public function testValidateTokenThrowsExceptionOnExpiredResetRequest (): void
@@ -223,7 +231,7 @@ public function testValidateTokenThrowsExceptionOnExpiredResetRequest(): void
223
231
$ this ->mockRepo
224
232
->expects ($ this ->once ())
225
233
->method ('findResetPasswordRequest ' )
226
- ->with ($ this ->randomToken )
234
+ ->with (\substr ( $ this ->randomToken , 0 , 20 ) )
227
235
->willReturn ($ this ->mockResetRequest )
228
236
;
229
237
@@ -256,7 +264,7 @@ public function testValidateTokenFetchesUserIfTokenNotExpired(): void
256
264
$ this ->mockRepo
257
265
->expects ($ this ->once ())
258
266
->method ('findResetPasswordRequest ' )
259
- ->with ($ this ->randomToken )
267
+ ->with (\substr ( $ this ->randomToken , 0 , 20 ) )
260
268
->willReturn ($ this ->mockResetRequest )
261
269
;
262
270
0 commit comments