Skip to content

Commit 437056c

Browse files
committed
Remove deprecations, fix up MultiChecker.
1 parent b015f8c commit 437056c

11 files changed

+200
-378
lines changed

src/Identifier/IdentifierInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
interface IdentifierInterface
2222
{
2323
/**
24-
* Identifies an user or service by the passed credentials
24+
* Identifies a user or service by the passed credentials
2525
*
2626
* @param array $credentials Authentication credentials
2727
* @return \ArrayAccess|array|null

tests/TestCase/Authenticator/AuthenticatorCollectionTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Authentication\Authenticator\AuthenticatorCollection;
2020
use Authentication\Authenticator\AuthenticatorInterface;
2121
use Authentication\Authenticator\FormAuthenticator;
22-
use Authentication\Identifier\IdentifierCollection;
2322
use Cake\TestSuite\TestCase;
2423

2524
class AuthenticatorCollectionTest extends TestCase
@@ -31,8 +30,7 @@ class AuthenticatorCollectionTest extends TestCase
3130
*/
3231
public function testConstruct()
3332
{
34-
$identifiers = $this->createMock(IdentifierCollection::class);
35-
$collection = new AuthenticatorCollection($identifiers, [
33+
$collection = new AuthenticatorCollection([
3634
'Authentication.Form' => [
3735
'identifier' => 'Authentication.Password',
3836
],
@@ -48,8 +46,7 @@ public function testConstruct()
4846
*/
4947
public function testLoad()
5048
{
51-
$identifiers = $this->createMock(IdentifierCollection::class);
52-
$collection = new AuthenticatorCollection($identifiers);
49+
$collection = new AuthenticatorCollection();
5350
$result = $collection->load('Authentication.Form', [
5451
'identifier' => 'Authentication.Password',
5552
]);
@@ -63,10 +60,9 @@ public function testLoad()
6360
*/
6461
public function testSet()
6562
{
66-
$identifiers = $this->createMock(IdentifierCollection::class);
6763
$authenticator = $this->createMock(AuthenticatorInterface::class);
6864

69-
$collection = new AuthenticatorCollection($identifiers);
65+
$collection = new AuthenticatorCollection();
7066
$collection->set('Form', $authenticator);
7167
$this->assertSame($authenticator, $collection->get('Form'));
7268
}
@@ -75,8 +71,7 @@ public function testLoadException()
7571
{
7672
$this->expectException('RuntimeException');
7773
$this->expectExceptionMessage('Authenticator class `Does-not-exist` was not found.');
78-
$identifiers = $this->createMock(IdentifierCollection::class);
79-
$collection = new AuthenticatorCollection($identifiers);
74+
$collection = new AuthenticatorCollection();
8075
$collection->load('Does-not-exist');
8176
}
8277

@@ -87,8 +82,7 @@ public function testLoadException()
8782
*/
8883
public function testIsEmpty()
8984
{
90-
$identifiers = $this->createMock(IdentifierCollection::class);
91-
$collection = new AuthenticatorCollection($identifiers);
85+
$collection = new AuthenticatorCollection();
9286
$this->assertTrue($collection->isEmpty());
9387

9488
$collection->load('Authentication.Form', [
@@ -104,10 +98,9 @@ public function testIsEmpty()
10498
*/
10599
public function testIterator()
106100
{
107-
$identifiers = $this->createMock(IdentifierCollection::class);
108101
$authenticator = $this->createMock(AuthenticatorInterface::class);
109102

110-
$collection = new AuthenticatorCollection($identifiers);
103+
$collection = new AuthenticatorCollection();
111104
$collection->set('Form', $authenticator);
112105

113106
$this->assertContains($authenticator, $collection);

tests/TestCase/Authenticator/CookieAuthenticatorTest.php

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use ArrayObject;
1919
use Authentication\Authenticator\CookieAuthenticator;
2020
use Authentication\Authenticator\Result;
21-
use Authentication\Identifier\IdentifierCollection;
21+
use Authentication\Identifier\IdentifierFactory;
2222
use Cake\Core\Configure;
2323
use Cake\Http\Cookie\Cookie;
2424
use 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

Comments
 (0)