@@ -44,29 +44,48 @@ protected function setUp(): void
44
44
$ this ->expiredLinkStorage = $ this ->createMock (ExpiredLoginLinkStorage::class);
45
45
}
46
46
47
- public function testCreateLoginLink ()
47
+ /**
48
+ * @dataProvider provideCreateLoginLinkData
49
+ */
50
+ public function testCreateLoginLink ($ user , array $ extraProperties )
48
51
{
49
- $ user = new TestLoginLinkHandlerUser ('weaverryan ' , 'ryan@symfonycasts.com ' , 'pwhash ' );
50
-
51
52
$ this ->router ->expects ($ this ->once ())
52
53
->method ('generate ' )
53
54
->with (
54
55
'app_check_login_link_route ' ,
55
- $ this ->callback (function ($ parameters ) {
56
+ $ this ->callback (function ($ parameters ) use ( $ extraProperties ) {
56
57
return 'weaverryan ' == $ parameters ['user ' ]
57
58
&& isset ($ parameters ['expires ' ])
58
59
&& isset ($ parameters ['hash ' ])
59
60
// make sure hash is what we expect
60
- && $ parameters ['hash ' ] === $ this ->createSignatureHash ('weaverryan ' , time () + 600 , [ ' ryan@symfonycasts.com ' , ' pwhash ' ] );
61
+ && $ parameters ['hash ' ] === $ this ->createSignatureHash ('weaverryan ' , time () + 600 , array_values ( $ extraProperties ) );
61
62
}),
62
63
UrlGeneratorInterface::ABSOLUTE_URL
63
64
)
64
65
->willReturn ('https://example.com/login/verify?user=weaverryan&hash=abchash&expires=1601235000 ' );
65
66
66
- $ loginLink = $ this ->createLinker ()->createLoginLink ($ user );
67
+ $ loginLink = $ this ->createLinker ([], array_keys ( $ extraProperties ) )->createLoginLink ($ user );
67
68
$ this ->assertSame ('https://example.com/login/verify?user=weaverryan&hash=abchash&expires=1601235000 ' , $ loginLink ->getUrl ());
68
69
}
69
70
71
+ public function provideCreateLoginLinkData ()
72
+ {
73
+ yield [
74
+ new TestLoginLinkHandlerUser ('weaverryan ' , 'ryan@symfonycasts.com ' , 'pwhash ' ),
75
+ ['emailProperty ' => 'ryan@symfonycasts.com ' , 'passwordProperty ' => 'pwhash ' ],
76
+ ];
77
+
78
+ yield [
79
+ new TestLoginLinkHandlerUser ('weaverryan ' , 'ryan@symfonycasts.com ' , 'pwhash ' ),
80
+ ['lastAuthenticatedAt ' => '' ],
81
+ ];
82
+
83
+ yield [
84
+ new TestLoginLinkHandlerUser ('weaverryan ' , 'ryan@symfonycasts.com ' , 'pwhash ' , new \DateTime ('2020-06-01 00:00:00 ' , new \DateTimeZone ('+0000 ' ))),
85
+ ['lastAuthenticatedAt ' => '2020-06-01T00:00:00+00:00 ' ],
86
+ ];
87
+ }
88
+
70
89
public function testConsumeLoginLink ()
71
90
{
72
91
$ expires = time () + 500 ;
@@ -167,14 +186,14 @@ private function createSignatureHash(string $username, int $expires, array $extr
167
186
return base64_encode (hash_hmac ('sha256 ' , implode (': ' , $ fields ), 's3cret ' ));
168
187
}
169
188
170
- private function createLinker (array $ options = []): LoginLinkHandler
189
+ private function createLinker (array $ options = [], array $ extraProperties = [ ' emailProperty ' , ' passwordProperty ' ] ): LoginLinkHandler
171
190
{
172
191
$ options = array_merge ([
173
192
'lifetime ' => 600 ,
174
193
'route_name ' => 'app_check_login_link_route ' ,
175
194
], $ options );
176
195
177
- return new LoginLinkHandler ($ this ->router , $ this ->userProvider , $ this ->propertyAccessor , [ ' emailProperty ' , ' passwordProperty ' ] , 's3cret ' , $ options , $ this ->expiredLinkStorage );
196
+ return new LoginLinkHandler ($ this ->router , $ this ->userProvider , $ this ->propertyAccessor , $ extraProperties , 's3cret ' , $ options , $ this ->expiredLinkStorage );
178
197
}
179
198
}
180
199
@@ -183,12 +202,14 @@ class TestLoginLinkHandlerUser implements UserInterface
183
202
public $ username ;
184
203
public $ emailProperty ;
185
204
public $ passwordProperty ;
205
+ public $ lastAuthenticatedAt ;
186
206
187
- public function __construct ($ username , $ emailProperty , $ passwordProperty )
207
+ public function __construct ($ username , $ emailProperty , $ passwordProperty, $ lastAuthenticatedAt = null )
188
208
{
189
209
$ this ->username = $ username ;
190
210
$ this ->emailProperty = $ emailProperty ;
191
211
$ this ->passwordProperty = $ passwordProperty ;
212
+ $ this ->lastAuthenticatedAt = $ lastAuthenticatedAt ;
192
213
}
193
214
194
215
public function getRoles ()
0 commit comments