Example #1
0
 /**
  * Ensures the getters work as expected.
  */
 public function testGetters()
 {
     $id = 'efdde334-fe7b-11e4-a322-1697f925ec7b';
     $secret = 'W5PeGMxSItNerkNFqQMfYiJvH14WzVJMy54CPoTAYoI=';
     $key = new Key($id, $secret);
     $this->assertEquals($id, $key->getId());
     $this->assertEquals($secret, $key->getSecret());
 }
 /**
  * Ensures the correct headers are added when the response is signed.
  */
 public function testSignResponse()
 {
     $authId = 'efdde334-fe7b-11e4-a322-1697f925ec7b';
     $authSecret = 'W5PeGMxSItNerkNFqQMfYiJvH14WzVJMy54CPoTAYoI=';
     $realm = 'Pipet service';
     $nonce = 'd1954337-5319-4821-8427-115542e08d10';
     $timestamp = 1432075982;
     $signature = 'LusIUHmqt9NOALrQ4N4MtXZEFE03MjcDjziK+vVqhvQ=';
     $authKey = new Key($authId, $authSecret);
     $headers = ['X-Authorization-Timestamp' => $timestamp];
     $request = new Request('GET', 'http://example.com', $headers);
     $authHeaderBuilder = new AuthorizationHeaderBuilder($request, $authKey);
     $authHeaderBuilder->setRealm($realm);
     $authHeaderBuilder->setId($authKey->getId());
     $authHeaderBuilder->setNonce($nonce);
     $authHeader = $authHeaderBuilder->getAuthorizationHeader();
     $requestSigner = new MockRequestSigner($authKey, $realm, new Digest(), $authHeader);
     $signedRequest = $requestSigner->signRequest($request);
     $response = new Response();
     $responseSigner = new ResponseSigner($authKey, $signedRequest);
     $signedResponse = $responseSigner->signResponse($response);
     $this->assertTrue($signedResponse->hasHeader('X-Server-Authorization-HMAC-SHA256'));
     $this->assertEquals($signature, $signedResponse->getHeaderLine('X-Server-Authorization-HMAC-SHA256'));
 }
 public function testAuthorizationHeaderBuilder()
 {
     $key = new Key('e7fe97fa-a0c8-4a42-ab8e-2c26d52df059', 'bXlzZWNyZXRzZWNyZXR0aGluZ3Rva2VlcA==');
     $headers = ['X-Authorization-Timestamp' => '1432075982', 'Content-Type' => 'application/json'];
     $request = new Request('POST', 'http://example.com?test=true', $headers, 'body text');
     $builder = new AuthorizationHeaderBuilder($request, $key);
     $builder->setId($key->getId());
     $builder->setNonce('a9938d07-d9f0-480c-b007-f1e956bcd027');
     $builder->setVersion('2.0');
     $header = $builder->getAuthorizationHeader();
     $this->assertEquals($header->getId(), $key->getId());
     $this->assertEquals($header->getSignature(), 'f9G/Xu339hw1z2zHTOrHKNv1kWqvYHYI9Nu/phO5dPY=');
     $builder->setSignature('test');
     $header = $builder->getAuthorizationHeader();
     $this->assertEquals($header->getSignature(), 'test');
 }