|
1
|
|
|
<?php |
|
2
|
|
|
namespace LE_ACME2Tests\Exception; |
|
3
|
|
|
|
|
4
|
|
|
use LE_ACME2; |
|
5
|
|
|
use LE_ACME2Tests\Connector\RawResponse; |
|
6
|
|
|
use LE_ACME2Tests\EnhancedTestCase; |
|
7
|
|
|
|
|
8
|
|
|
class ServiceUnavailableTest extends EnhancedTestCase { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers LE_ACME2\Exception\ServiceUnavailable |
|
12
|
|
|
* @covers LE_ACME2\Response\AbstractResponse::_isServiceUnavailable |
|
13
|
|
|
* @covers LE_ACME2\Response\AbstractResponse::__construct |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
public function test() { |
|
18
|
|
|
|
|
19
|
|
|
$raw = RawResponse::createDummyFrom( |
|
20
|
|
|
'HTTP/2 503 service unavailable' . "\r\n", |
|
21
|
|
|
'{ |
|
22
|
|
|
"type": "urn:ietf:params:acme:error:rateLimited", |
|
23
|
|
|
"detail": "Service busy; retry later." |
|
24
|
|
|
}', |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
/** @var LE_ACME2\Exception\RateLimitReached $exception */ |
|
28
|
|
|
$exception = $this->catchExpectedException(LE_ACME2\Exception\ServiceUnavailable::class, function() use($raw) { |
|
29
|
|
|
new LE_ACME2\Response\GetDirectory($raw); |
|
30
|
|
|
}); |
|
31
|
|
|
$this->assertIsObject($exception); |
|
32
|
|
|
$this->assertTrue(get_class($exception) == LE_ACME2\Exception\ServiceUnavailable::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @covers LE_ACME2\Exception\ServiceUnavailable |
|
37
|
|
|
* @covers LE_ACME2\Response\AbstractResponse::_isServiceUnavailable |
|
38
|
|
|
* @covers LE_ACME2\Response\AbstractResponse::__construct |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testRetryAfterHeader() { |
|
43
|
|
|
|
|
44
|
|
|
$raw = RawResponse::createDummyFrom( |
|
45
|
|
|
'HTTP/2 503 Too many requests' . "\r\n" . |
|
46
|
|
|
'Retry-After: 120', |
|
47
|
|
|
'{ |
|
48
|
|
|
"type": "urn:ietf:params:acme:error:rateLimited", |
|
49
|
|
|
"detail": "Service busy; retry later." |
|
50
|
|
|
}', |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
/** @var LE_ACME2\Exception\ServiceUnavailable $exception */ |
|
54
|
|
|
$exception = $this->catchExpectedException(LE_ACME2\Exception\ServiceUnavailable::class, function() use($raw) { |
|
55
|
|
|
new LE_ACME2\Response\GetDirectory($raw); |
|
56
|
|
|
}); |
|
57
|
|
|
$this->assertEquals('120', $exception->getRetryAfter()); |
|
58
|
|
|
} |
|
59
|
|
|
} |