Author: Jérémy Derussé (jeremy@derusse.com)
Ejemplo n.º 1
0
 public function test generateKeyPair generate random instance of KeyPair()
 {
     $result = $this->service->generateKeyPair(1024);
     $this->assertInstanceOf(KeyPair::class, $result);
     $this->assertContains('-----BEGIN PUBLIC KEY-----', $result->getPublicKey()->getPEM());
     $this->assertContains('-----BEGIN PRIVATE KEY-----', $result->getPrivateKey()->getPEM());
     $this->assertInternalType('resource', $result->getPublicKey()->getResource());
     $this->assertInternalType('resource', $result->getPrivateKey()->getResource());
 }
Ejemplo n.º 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']);
 }