1818use ArrayObject ;
1919use Authentication \Authenticator \CookieAuthenticator ;
2020use Authentication \Authenticator \Result ;
21- use Authentication \Identifier \IdentifierCollection ;
21+ use Authentication \Identifier \IdentifierFactory ;
2222use Cake \Core \Configure ;
2323use Cake \Http \Cookie \Cookie ;
2424use Cake \Http \Response ;
@@ -59,9 +59,7 @@ public function setUp(): void
5959 */
6060 public function testAuthenticateInvalidTokenMissingUsername ()
6161 {
62- $ identifiers = new IdentifierCollection ([
63- 'Authentication.Password ' ,
64- ]);
62+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
6563
6664 $ request = ServerRequestFactory::fromGlobals (
6765 ['REQUEST_URI ' => '/testpath ' ],
@@ -72,7 +70,7 @@ public function testAuthenticateInvalidTokenMissingUsername()
7270 ],
7371 );
7472
75- $ authenticator = new CookieAuthenticator ($ identifiers );
73+ $ authenticator = new CookieAuthenticator ($ identifier );
7674 $ result = $ authenticator ->authenticate ($ request );
7775
7876 $ this ->assertInstanceOf (Result::class, $ result );
@@ -86,9 +84,7 @@ public function testAuthenticateInvalidTokenMissingUsername()
8684 */
8785 public function testAuthenticateSuccess ()
8886 {
89- $ identifiers = new IdentifierCollection ([
90- 'Authentication.Password ' ,
91- ]);
87+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
9288
9389 $ request = ServerRequestFactory::fromGlobals (
9490 ['REQUEST_URI ' => '/testpath ' ],
@@ -100,7 +96,7 @@ public function testAuthenticateSuccess()
10096 ],
10197 );
10298
103- $ authenticator = new CookieAuthenticator ($ identifiers );
99+ $ authenticator = new CookieAuthenticator ($ identifier );
104100 $ result = $ authenticator ->authenticate ($ request );
105101
106102 $ this ->assertInstanceOf (Result::class, $ result );
@@ -114,9 +110,7 @@ public function testAuthenticateSuccess()
114110 */
115111 public function testAuthenticateExpandedCookie ()
116112 {
117- $ identifiers = new IdentifierCollection ([
118- 'Authentication.Password ' ,
119- ]);
113+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
120114
121115 $ request = ServerRequestFactory::fromGlobals (
122116 ['REQUEST_URI ' => '/testpath ' ],
@@ -127,7 +121,7 @@ public function testAuthenticateExpandedCookie()
127121 ],
128122 );
129123
130- $ authenticator = new CookieAuthenticator ($ identifiers );
124+ $ authenticator = new CookieAuthenticator ($ identifier );
131125 $ result = $ authenticator ->authenticate ($ request );
132126
133127 $ this ->assertInstanceOf (Result::class, $ result );
@@ -143,9 +137,7 @@ public function testAuthenticateNoSalt()
143137 {
144138 Configure::delete ('Security.salt ' );
145139
146- $ identifiers = new IdentifierCollection ([
147- 'Authentication.Password ' ,
148- ]);
140+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
149141
150142 $ request = ServerRequestFactory::fromGlobals (
151143 ['REQUEST_URI ' => '/testpath ' ],
@@ -157,7 +149,7 @@ public function testAuthenticateNoSalt()
157149 ],
158150 );
159151
160- $ authenticator = new CookieAuthenticator ($ identifiers , ['salt ' => false ]);
152+ $ authenticator = new CookieAuthenticator ($ identifier , ['salt ' => false ]);
161153 $ result = $ authenticator ->authenticate ($ request );
162154
163155 $ this ->assertInstanceOf (Result::class, $ result );
@@ -171,9 +163,7 @@ public function testAuthenticateNoSalt()
171163 */
172164 public function testAuthenticateInvalidSalt ()
173165 {
174- $ identifiers = new IdentifierCollection ([
175- 'Authentication.Password ' ,
176- ]);
166+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
177167
178168 $ request = ServerRequestFactory::fromGlobals (
179169 ['REQUEST_URI ' => '/testpath ' ],
@@ -184,7 +174,7 @@ public function testAuthenticateInvalidSalt()
184174 ],
185175 );
186176
187- $ authenticator = new CookieAuthenticator ($ identifiers , ['salt ' => '' ]);
177+ $ authenticator = new CookieAuthenticator ($ identifier , ['salt ' => '' ]);
188178
189179 $ this ->expectException (InvalidArgumentException::class);
190180 $ authenticator ->authenticate ($ request );
@@ -197,9 +187,7 @@ public function testAuthenticateInvalidSalt()
197187 */
198188 public function testAuthenticateUnknownUser ()
199189 {
200- $ identifiers = new IdentifierCollection ([
201- 'Authentication.Password ' ,
202- ]);
190+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
203191
204192 $ request = ServerRequestFactory::fromGlobals (
205193 ['REQUEST_URI ' => '/testpath ' ],
@@ -210,7 +198,7 @@ public function testAuthenticateUnknownUser()
210198 ],
211199 );
212200
213- $ authenticator = new CookieAuthenticator ($ identifiers );
201+ $ authenticator = new CookieAuthenticator ($ identifier );
214202 $ result = $ authenticator ->authenticate ($ request );
215203
216204 $ this ->assertInstanceOf (Result::class, $ result );
@@ -224,15 +212,13 @@ public function testAuthenticateUnknownUser()
224212 */
225213 public function testCredentialsNotPresent ()
226214 {
227- $ identifiers = new IdentifierCollection ([
228- 'Authentication.Password ' ,
229- ]);
215+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
230216
231217 $ request = ServerRequestFactory::fromGlobals (
232218 ['REQUEST_URI ' => '/testpath ' ],
233219 );
234220
235- $ authenticator = new CookieAuthenticator ($ identifiers );
221+ $ authenticator = new CookieAuthenticator ($ identifier );
236222 $ result = $ authenticator ->authenticate ($ request );
237223
238224 $ this ->assertInstanceOf (Result::class, $ result );
@@ -246,9 +232,7 @@ public function testCredentialsNotPresent()
246232 */
247233 public function testAuthenticateInvalidToken ()
248234 {
249- $ identifiers = new IdentifierCollection ([
250- 'Authentication.Password ' ,
251- ]);
235+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
252236
253237 $ request = ServerRequestFactory::fromGlobals (
254238 ['REQUEST_URI ' => '/testpath ' ],
@@ -259,7 +243,7 @@ public function testAuthenticateInvalidToken()
259243 ],
260244 );
261245
262- $ authenticator = new CookieAuthenticator ($ identifiers );
246+ $ authenticator = new CookieAuthenticator ($ identifier );
263247 $ result = $ authenticator ->authenticate ($ request );
264248
265249 $ this ->assertInstanceOf (Result::class, $ result );
@@ -273,9 +257,7 @@ public function testAuthenticateInvalidToken()
273257 */
274258 public function testPersistIdentity ()
275259 {
276- $ identifiers = new IdentifierCollection ([
277- 'Authentication.Password ' ,
278- ]);
260+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
279261
280262 $ request = ServerRequestFactory::fromGlobals (
281263 ['REQUEST_URI ' => '/testpath ' ],
@@ -286,7 +268,7 @@ public function testPersistIdentity()
286268 $ response = new Response ();
287269
288270 Cookie::setDefaults (['samesite ' => 'None ' ]);
289- $ authenticator = new CookieAuthenticator ($ identifiers , [
271+ $ authenticator = new CookieAuthenticator ($ identifier , [
290272 'cookie ' => ['expires ' => '2030-01-01 00:00:00 ' ],
291273 ]);
292274
@@ -332,7 +314,7 @@ public function testPersistIdentity()
332314 $ request = $ request ->withParsedBody ([
333315 'other_field ' => 1 ,
334316 ]);
335- $ authenticator = new CookieAuthenticator ($ identifiers , [
317+ $ authenticator = new CookieAuthenticator ($ identifier , [
336318 'rememberMeField ' => 'other_field ' ,
337319 ]);
338320 $ result = $ authenticator ->persistIdentity ($ request , $ response , $ identity );
@@ -349,9 +331,7 @@ public function testPersistIdentity()
349331 */
350332 public function testPersistIdentityLoginUrlMismatch ()
351333 {
352- $ identifiers = new IdentifierCollection ([
353- 'Authentication.Password ' ,
354- ]);
334+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
355335
356336 $ request = ServerRequestFactory::fromGlobals (
357337 ['REQUEST_URI ' => '/testpath ' ],
@@ -361,7 +341,7 @@ public function testPersistIdentityLoginUrlMismatch()
361341 ]);
362342 $ response = new Response ();
363343
364- $ authenticator = new CookieAuthenticator ($ identifiers , [
344+ $ authenticator = new CookieAuthenticator ($ identifier , [
365345 'loginUrl ' => '/users/login ' ,
366346 ]);
367347
@@ -387,9 +367,7 @@ public function testPersistIdentityLoginUrlMismatch()
387367 */
388368 public function testPersistIdentityInvalidConfig ()
389369 {
390- $ identifiers = new IdentifierCollection ([
391- 'Authentication.Password ' ,
392- ]);
370+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
393371
394372 $ request = ServerRequestFactory::fromGlobals (
395373 ['REQUEST_URI ' => '/users/login ' ],
@@ -399,7 +377,7 @@ public function testPersistIdentityInvalidConfig()
399377 ]);
400378 $ response = new Response ();
401379
402- $ authenticator = new CookieAuthenticator ($ identifiers , [
380+ $ authenticator = new CookieAuthenticator ($ identifier , [
403381 'loginUrl ' => '/users/login ' ,
404382 ]);
405383
@@ -420,16 +398,14 @@ public function testPersistIdentityInvalidConfig()
420398 */
421399 public function testClearIdentity ()
422400 {
423- $ identifiers = new IdentifierCollection ([
424- 'Authentication.Password ' ,
425- ]);
401+ $ identifier = IdentifierFactory::create ('Authentication.Password ' );
426402
427403 $ request = ServerRequestFactory::fromGlobals (
428404 ['REQUEST_URI ' => '/testpath ' ],
429405 );
430406 $ response = new Response ();
431407
432- $ authenticator = new CookieAuthenticator ($ identifiers );
408+ $ authenticator = new CookieAuthenticator ($ identifier );
433409
434410 $ result = $ authenticator ->clearIdentity ($ request , $ response );
435411 $ this ->assertIsArray ($ result );
0 commit comments