1919use ArrayObject ;
2020use Authentication \Authenticator \Result ;
2121use Authentication \Authenticator \SessionAuthenticator ;
22- use Authentication\Identifier\IdentifierFactory;
23- use Authentication\Identifier\PasswordIdentifier;
2422use Authentication \Test \TestCase \AuthenticationTestCase as TestCase ;
2523use Cake \Http \Exception \UnauthorizedException ;
2624use Cake \Http \Response ;
@@ -42,11 +40,6 @@ class SessionAuthenticatorTest extends TestCase
4240 'core.Users ' ,
4341 ];
4442
45- /**
46- * @var \Authentication\Identifier\IdentifierInterface
47- */
48- protected $identifier;
49-
5043 protected $ sessionMock ;
5144
5245 /**
@@ -56,8 +49,6 @@ public function setUp(): void
5649 {
5750 parent ::setUp ();
5851
59- $this->identifier = IdentifierFactory::create('Authentication.Password');
60-
6152 $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
6253 ->disableOriginalConstructor ()
6354 ->onlyMethods (['read ' , 'write ' , 'delete ' , 'renew ' , 'check ' ])
@@ -83,91 +74,7 @@ public function testAuthenticateSuccess()
8374
8475 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
8576
86- $authenticator = new SessionAuthenticator($this->identifier);
87- $result = $authenticator->authenticate($request);
88-
89- $this->assertInstanceOf(Result::class, $result);
90- $this->assertSame(Result::SUCCESS, $result->getStatus());
91- }
92-
93- /**
94- * Test authentication
95- *
96- * @return void
97- */
98- public function testAuthenticateSuccessWithoutCollection()
99- {
100- $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
101-
102- $this->sessionMock->expects($this->once())
103- ->method('read')
104- ->with('Auth')
105- ->willReturn([
106- 'username' => 'mariano',
107- 'password' => 'password',
108- ]);
109-
110- $request = $request->withAttribute('session', $this->sessionMock);
111-
112- $authenticator = new SessionAuthenticator(null, [
113- 'identifier' => 'Authentication.Password',
114- ]);
115- $result = $authenticator->authenticate($request);
116-
117- $this->assertInstanceOf(Result::class, $result);
118- $this->assertSame(Result::SUCCESS, $result->getStatus());
119- }
120-
121- /**
122- * Test authentication
123- *
124- * @return void
125- */
126- public function testAuthenticateSuccessWithoutCollectionButObject()
127- {
128- $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
129-
130- $this->sessionMock->expects($this->once())
131- ->method('read')
132- ->with('Auth')
133- ->willReturn([
134- 'username' => 'mariano',
135- 'password' => 'password',
136- ]);
137-
138- $request = $request->withAttribute('session', $this->sessionMock);
139-
140- $authenticator = new SessionAuthenticator(null, [
141- 'identifier' => new PasswordIdentifier(),
142- ]);
143- $result = $authenticator->authenticate($request);
144-
145- $this->assertInstanceOf(Result::class, $result);
146- $this->assertSame(Result::SUCCESS, $result->getStatus());
147- }
148-
149- /**
150- * Test authentication
151- *
152- * @return void
153- */
154- public function testAuthenticateSuccessWithDirectCollection()
155- {
156- $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
157-
158- $this->sessionMock->expects($this->once())
159- ->method('read')
160- ->with('Auth')
161- ->willReturn([
162- 'username' => 'mariano',
163- 'password' => 'password',
164- ]);
165-
166- $request = $request->withAttribute('session', $this->sessionMock);
167-
168- $authenticator = new SessionAuthenticator(null, [
169- 'identifier' => IdentifierFactory::create('Authentication.Password'),
170- ]);
77+ $ authenticator = new SessionAuthenticator (null );
17178 $ result = $ authenticator ->authenticate ($ request );
17279
17380 $ this ->assertInstanceOf (Result::class, $ result );
@@ -190,7 +97,7 @@ public function testAuthenticateFailure()
19097
19198 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
19299
193- $authenticator = new SessionAuthenticator($this->identifier );
100+ $ authenticator = new SessionAuthenticator (null );
194101 $ result = $ authenticator ->authenticate ($ request );
195102
196103 $ this ->assertInstanceOf (Result::class, $ result );
@@ -207,7 +114,7 @@ public function testPersistIdentity()
207114 $ request = ServerRequestFactory::fromGlobals (['REQUEST_URI ' => '/ ' ]);
208115 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
209116 $ response = new Response ();
210- $authenticator = new SessionAuthenticator($this->identifier );
117+ $ authenticator = new SessionAuthenticator (null );
211118
212119 $ data = new ArrayObject (['username ' => 'florian ' ]);
213120
@@ -250,7 +157,7 @@ public function testClearIdentity()
250157 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
251158 $ response = new Response ();
252159
253- $authenticator = new SessionAuthenticator($this->identifier );
160+ $ authenticator = new SessionAuthenticator (null );
254161
255162 $ this ->sessionMock ->expects ($ this ->once ())
256163 ->method ('delete ' )
@@ -279,7 +186,7 @@ public function testImpersonate()
279186 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
280187 $ response = new Response ();
281188
282- $authenticator = new SessionAuthenticator($this->identifier );
189+ $ authenticator = new SessionAuthenticator (null );
283190 $ AuthUsers = TableRegistry::getTableLocator ()->get ('AuthUsers ' );
284191 $ impersonator = $ AuthUsers ->newEntity ([
285192 'username ' => 'mariano ' ,
@@ -318,7 +225,7 @@ public function testImpersonateAlreadyImpersonating()
318225 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
319226 $ response = new Response ();
320227
321- $authenticator = new SessionAuthenticator($this->identifier );
228+ $ authenticator = new SessionAuthenticator (null );
322229 $ impersonator = new ArrayObject ([
323230 'username ' => 'mariano ' ,
324231 'password ' => 'password ' ,
@@ -352,7 +259,7 @@ public function testStopImpersonating()
352259 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
353260 $ response = new Response ();
354261
355- $authenticator = new SessionAuthenticator($this->identifier );
262+ $ authenticator = new SessionAuthenticator (null );
356263
357264 $ impersonator = new ArrayObject ([
358265 'username ' => 'mariano ' ,
@@ -399,7 +306,7 @@ public function testStopImpersonatingNotImpersonating()
399306 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
400307 $ response = new Response ();
401308
402- $authenticator = new SessionAuthenticator($this->identifier );
309+ $ authenticator = new SessionAuthenticator (null );
403310
404311 $ this ->sessionMock ->expects ($ this ->once ())
405312 ->method ('check ' )
@@ -436,7 +343,7 @@ public function testIsImpersonating()
436343 $ request = ServerRequestFactory::fromGlobals (['REQUEST_URI ' => '/ ' ]);
437344 $ request = $ request ->withAttribute ('session ' , $ this ->sessionMock );
438345
439- $authenticator = new SessionAuthenticator($this->identifier );
346+ $ authenticator = new SessionAuthenticator (null );
440347
441348 $ this ->sessionMock ->expects ($ this ->once ())
442349 ->method ('check ' )
0 commit comments