Пример #1
0
 /**
  * Initialize the server resources directory.
  */
 private function initializeDirectory()
 {
     $this->directory = new ResourcesDirectory($this->httpClient->unsignedRequest('GET', $this->directoryUrl, null, true));
 }
Пример #2
0
 public function testSignedRequestPayload()
 {
     $container = [];
     $stack = HandlerStack::create(new MockHandler([new Response(200, [], json_encode(['test' => 'ok']))]));
     $stack->push(Middleware::history($container));
     $keyPairGenerator = new KeyPairGenerator();
     $dataSigner = $this->getMockBuilder(DataSigner::class)->getMock();
     $dataSigner->expects($this->once())->method('signData')->willReturn('foobar');
     $client = new SecureHttpClient($keyPairGenerator->generateKeyPair(), new Client(['handler' => $stack]), new Base64SafeEncoder(), new KeyParser(), $dataSigner, $this->getMockBuilder(ServerErrorHandler::class)->getMock());
     $client->signedRequest('POST', '/acme/new-reg', ['contact' => '*****@*****.**'], true);
     // Check request object
     $this->assertCount(1, $container);
     /** @var RequestInterface $request */
     $request = $container[0]['request'];
     $this->assertInstanceOf(RequestInterface::class, $request);
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('/acme/new-reg', $request->getUri() instanceof Uri ? $request->getUri()->getPath() : $request->getUri());
     $body = \GuzzleHttp\Psr7\copy_to_string($request->getBody());
     $payload = @json_decode($body, true);
     $this->assertInternalType('array', $payload);
     $this->assertArrayHasKey('header', $payload);
     $this->assertArrayHasKey('alg', $payload['header']);
     $this->assertArrayHasKey('jwk', $payload['header']);
     $this->assertArrayHasKey('protected', $payload);
     $this->assertArrayHasKey('payload', $payload);
     $this->assertArrayHasKey('signature', $payload);
     $this->assertEquals('Zm9vYmFy', $payload['signature']);
 }