|
@@ 39-59 (lines=21) @@
|
| 36 |
|
$this->grant = m::mock(GrantInterface::class); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
public function testSign() |
| 40 |
|
{ |
| 41 |
|
$h = new MockHandler([ |
| 42 |
|
function (RequestInterface $request, array $options) { |
| 43 |
|
$this->assertEquals('OAuth test', $request->getHeaderLine('Authorization')); |
| 44 |
|
return new Response(200); |
| 45 |
|
}, |
| 46 |
|
]); |
| 47 |
|
|
| 48 |
|
$token = new AccessToken('test'); |
| 49 |
|
$this->grant->shouldReceive('getToken') |
| 50 |
|
->andReturn($token); |
| 51 |
|
|
| 52 |
|
$stack = new HandlerStack($h); |
| 53 |
|
$stack->push(OAuth2Middleware::middleware($this->grant)); |
| 54 |
|
|
| 55 |
|
$comp = $stack->resolve(); |
| 56 |
|
|
| 57 |
|
$p = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya-oauth2']); |
| 58 |
|
$this->assertInstanceOf(PromiseInterface::class, $p); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public function testErrorThatIsNot401() |
| 62 |
|
{ |
|
@@ 61-81 (lines=21) @@
|
| 58 |
|
$this->assertInstanceOf(PromiseInterface::class, $p); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public function testErrorThatIsNot401() |
| 62 |
|
{ |
| 63 |
|
$h = new MockHandler([ |
| 64 |
|
function (RequestInterface $request, array $options) { |
| 65 |
|
$this->assertEquals('OAuth test', $request->getHeaderLine('Authorization')); |
| 66 |
|
return new Response(503); |
| 67 |
|
}, |
| 68 |
|
]); |
| 69 |
|
|
| 70 |
|
$token = new AccessToken('test'); |
| 71 |
|
$this->grant->shouldReceive('getToken') |
| 72 |
|
->andReturn($token); |
| 73 |
|
|
| 74 |
|
$stack = new HandlerStack($h); |
| 75 |
|
$stack->push(OAuth2Middleware::middleware($this->grant)); |
| 76 |
|
|
| 77 |
|
$comp = $stack->resolve(); |
| 78 |
|
|
| 79 |
|
$p = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya-oauth2']); |
| 80 |
|
$this->assertInstanceOf(PromiseInterface::class, $p); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
public function testErrorThatIsNotRetried() |
| 84 |
|
{ |
|
@@ 145-165 (lines=21) @@
|
| 142 |
|
$this->assertEquals(200, $response->getStatusCode()); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
public function testErrorThatIsNotOauthAuth() |
| 146 |
|
{ |
| 147 |
|
$h = new MockHandler([ |
| 148 |
|
function (RequestInterface $request, array $options) { |
| 149 |
|
$this->assertEquals('', $request->getHeaderLine('Authorization')); |
| 150 |
|
return new Response(401); |
| 151 |
|
}, |
| 152 |
|
]); |
| 153 |
|
|
| 154 |
|
$stack = new HandlerStack($h); |
| 155 |
|
$stack->push(OAuth2Middleware::middleware($this->grant)); |
| 156 |
|
|
| 157 |
|
$comp = $stack->resolve(); |
| 158 |
|
|
| 159 |
|
/** @var PromiseInterface $p */ |
| 160 |
|
$p = $comp(new Request('GET', 'https://example.com'), ['auth' => 'none']); |
| 161 |
|
$this->assertInstanceOf(PromiseInterface::class, $p); |
| 162 |
|
/** @var ResponseInterface $response */ |
| 163 |
|
$response = $p->wait(true); |
| 164 |
|
$this->assertEquals(401, $response->getStatusCode()); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
public function testErrorWhenNoTokenIsReturnedWillNotIntercept() |
| 168 |
|
{ |