1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Bip70\Test\Client; |
6
|
|
|
|
7
|
|
|
use Bip70\Client\Exception\ProtocolException; |
8
|
|
|
use Bip70\Client\GuzzleHttpClient; |
9
|
|
|
use Bip70\X509\RequestValidation; |
10
|
|
|
use Bip70\X509\TrustStoreLoader; |
11
|
|
|
use GuzzleHttp\Handler\MockHandler; |
12
|
|
|
use GuzzleHttp\HandlerStack; |
13
|
|
|
use GuzzleHttp\Middleware; |
14
|
|
|
use GuzzleHttp\Psr7\Response; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use X509\CertificationPath\PathValidation\PathValidationConfig; |
17
|
|
|
|
18
|
|
|
class RejectsInvalidPaymentRequestTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testThrowsIfRequestInvalid() |
21
|
|
|
{ |
22
|
|
|
$container = []; |
23
|
|
|
$history = Middleware::history($container); |
24
|
|
|
|
25
|
|
|
$handler = new MockHandler([ |
26
|
|
|
// response to our GET PAYMENTREQUEST request |
27
|
|
|
new Response(200, [ |
28
|
|
|
'Content-Type' => [ |
29
|
|
|
'application/bitcoin-paymentrequest', |
30
|
|
|
] |
31
|
|
|
], "GET") |
32
|
|
|
]); |
33
|
|
|
|
34
|
|
|
$stack = HandlerStack::create($handler); |
35
|
|
|
$stack->push($history); |
36
|
|
|
|
37
|
|
|
$mockClient = new \GuzzleHttp\Client([ |
38
|
|
|
'handler' => $stack, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$client = new GuzzleHttpClient($mockClient); |
42
|
|
|
|
43
|
|
|
$requestUrl = "https://development.bip70.local/invoice/1"; |
44
|
|
|
|
45
|
|
|
// 10/12/2017 ish |
46
|
|
|
$now = new \DateTimeImmutable(); |
47
|
|
|
$now = $now->setTimestamp(1509692666); |
48
|
|
|
|
49
|
|
|
$validationConfig = new PathValidationConfig($now, 10); |
50
|
|
|
$validator = new RequestValidation($validationConfig, TrustStoreLoader::fromSystem()); |
51
|
|
|
|
52
|
|
|
$this->expectException(ProtocolException::class); |
53
|
|
|
$this->expectExceptionMessage("Failed to decode payment request"); |
54
|
|
|
|
55
|
|
|
$client->getRequest($requestUrl, $validator); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|