8
8
use GuzzleHttp \HandlerStack ;
9
9
use GuzzleHttp \Middleware ;
10
10
use GuzzleHttp \Psr7 \Response as Psr7Response ;
11
- use GuzzleHttp \Psr7 \Request as Psr7Request ;
12
- use GuzzleHttp \Subscriber \Mock as MockResponder ;
13
11
use GuzzleHttp \Subscriber \History ;
14
12
15
13
use kamermans \OAuth2 \Utils \Helper ;
16
14
use kamermans \OAuth2 \OAuth2Middleware ;
17
- use kamermans \OAuth2 \Token \RawToken ;
18
- use kamermans \OAuth2 \Tests \BaseTestCase ;
19
15
20
16
class OAuth2MiddlewareTest extends BaseTestCase
21
17
{
22
-
23
18
public function setUp ()
24
19
{
25
20
if (Helper::guzzleIs ('< ' , 6 )) {
@@ -39,7 +34,6 @@ public function testConstruct()
39
34
40
35
public function testDoesNotTriggerForNonOAuthRequests ()
41
36
{
42
-
43
37
$ reauth_container = [];
44
38
$ reauth_history = Middleware::history ($ reauth_container );
45
39
@@ -97,14 +91,13 @@ public function testDoesNotTriggerForNonOAuthRequests()
97
91
$ this ->assertCount (1 , $ container );
98
92
99
93
$ this ->assertSame ('' , $ this ->getHeader ($ container [0 ]['request ' ], 'Authorization ' ), "The request should not have been signed " );
100
-
101
94
}
102
95
103
96
public function testTriggersSignerAndGrantDataProcessor ()
104
97
{
105
98
106
99
// A random access token helps avoid false pasitives due to caching
107
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
100
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
108
101
109
102
$ reauth_container = [];
110
103
$ reauth_history = Middleware::history ($ reauth_container );
@@ -167,7 +160,6 @@ public function testTriggersSignerAndGrantDataProcessor()
167
160
// This proves that the access_token received from the reauth_client was used to authenticate this response
168
161
$ expected_auth_value = "Bearer $ mock_access_token " ;
169
162
$ this ->assertSame ($ expected_auth_value , $ this ->getHeader ($ container [0 ]['request ' ], 'Authorization ' ));
170
-
171
163
}
172
164
173
165
/**
@@ -177,7 +169,7 @@ public function testOnErrorDoesNotTriggerForNonOAuthRequests()
177
169
{
178
170
179
171
// A random access token helps avoid false pasitives due to caching
180
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
172
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
181
173
182
174
$ reauth_container = [];
183
175
$ reauth_history = Middleware::history ($ reauth_container );
@@ -239,14 +231,13 @@ public function testOnErrorDoesNotTriggerForNonOAuthRequests()
239
231
240
232
$ this ->assertCount (0 , $ reauth_container );
241
233
$ this ->assertCount (1 , $ container );
242
-
243
234
}
244
235
245
236
public function testOnErrorDoesTriggerForOAuthRequests ()
246
237
{
247
238
248
239
// A random access token helps avoid false pasitives due to caching
249
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
240
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
250
241
251
242
$ reauth_container = [];
252
243
$ reauth_history = Middleware::history ($ reauth_container );
@@ -314,14 +305,13 @@ public function testOnErrorDoesTriggerForOAuthRequests()
314
305
// Note that if we didn't catch the HTTP 401, it would have thrown an exception
315
306
$ this ->assertSame (401 , $ container [0 ]['response ' ]->getStatusCode ());
316
307
$ this ->assertSame (200 , $ container [1 ]['response ' ]->getStatusCode ());
317
-
318
308
}
319
309
320
310
public function testOnErrorDoesNotTriggerForNon401Requests ()
321
311
{
322
312
323
313
// A random access token helps avoid false pasitives due to caching
324
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
314
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
325
315
326
316
$ reauth_container = [];
327
317
$ reauth_history = Middleware::history ($ reauth_container );
@@ -404,8 +394,8 @@ public function testTokenPersistenceIsUsed()
404
394
{
405
395
406
396
// A random access token helps avoid false pasitives due to caching
407
- $ mock_access_token_cached = md5 (microtime (true ).mt_rand (100000 ,999999 ));
408
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
397
+ $ mock_access_token_cached = md5 (microtime (true ).mt_rand (100000 , 999999 ));
398
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
409
399
410
400
$ cached_token = new \kamermans \OAuth2 \Token \RawToken ($ mock_access_token_cached );
411
401
@@ -478,13 +468,12 @@ public function testTokenPersistenceIsUsed()
478
468
// This proves that the access_token received from the Persistence was used to authenticate this response, not the one from reauth
479
469
$ expected_auth_value = "Bearer $ mock_access_token_cached " ;
480
470
$ this ->assertSame ($ expected_auth_value , $ this ->getHeader ($ container [0 ]['request ' ], 'Authorization ' ));
481
-
482
471
}
483
472
484
473
public function testOnErrorDoesNotLoop ()
485
474
{
486
475
// A random access token helps avoid false pasitives due to caching
487
- $ mock_access_token = md5 (microtime (true ).mt_rand (100000 ,999999 ));
476
+ $ mock_access_token = md5 (microtime (true ).mt_rand (100000 , 999999 ));
488
477
489
478
$ reauth_container = [];
490
479
$ reauth_history = Middleware::history ($ reauth_container );
@@ -597,5 +586,4 @@ public function __DISABLED__testOnErrorDoesNotLoop()
597
586
// Force an onError event, which triggers the signer and grant data processor
598
587
$ sub ->onError ($ event );
599
588
}
600
-
601
589
}
0 commit comments