/** * @return \Acquia\Hmac\Guzzle3\HmacAuthPlugin */ public function getPlugin() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); $plugin = new HmacAuthPlugin($signer, '1', 'secret-key'); return $plugin; }
/** * @expectedException \Acquia\Hmac\Exception\InvalidSignatureException */ public function testInvalidSignature() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); $request = new DummyRequest(); $request->headers = array('Content-Type' => 'text/plain', 'Date' => 'Fri, 19 Mar 1982 00:00:04 GMT', 'Authorization' => 'Acquia 1:badsignature', 'Custom1' => 'Value1'); $authenticator = new RequestAuthenticator($signer, 0); $authenticator->authenticate($request, new DummyKeyLoader()); }
/** * @expectedException \Acquia\Hmac\Exception\InvalidSignatureException */ public function testInvalidSignature() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); $headers = array('Content-Type' => 'text/plain', 'Date' => 'Fri, 19 Mar 1982 00:00:04 GMT', 'Authorization' => 'Acquia 1:badsignature', 'Custom1' => 'Value1'); $request = $this->newRequest(); // Add headers foreach ($headers as $header => $value) { $request = $request->withHeader($header, $value); } $authenticator = new RequestAuthenticator($signer, 0); $keyLoader = new DummyKeyLoader(); $authenticator = new RequestAuthenticatorAdapter($authenticator, $keyLoader); $authenticator($request, $this->response); }
public function testGetMessage() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); $request = new DummyRequest(); $request->headers = array('Content-Type' => 'text/plain', 'Date' => 'Fri, 19 Mar 1982 00:00:04 GMT', 'Custom1' => 'Value1'); $digest = new Digest(); $this->assertEquals(self::EXPECTED_HASH, $digest->get($signer, $request, 'secret-key')); // Change the secret key $this->assertNotEquals(self::EXPECTED_HASH, $digest->get($signer, $request, 'bad-key')); // Test case insensitive method. $request->method = 'gEt'; $this->assertEquals(self::EXPECTED_HASH, $digest->get($signer, $request, 'secret-key')); // Test case insensitive content type. $request->headers['Content-Type'] = 'TeXt/PlAiN'; $this->assertEquals(self::EXPECTED_HASH, $digest->get($signer, $request, 'secret-key')); // Test changing the algorithm $digest->setAlgorithm('sha256'); $this->assertNotEquals(self::EXPECTED_HASH, $digest->get($signer, $request, 'secret-key')); }
public function testgetAuthorization() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); $request = new DummyRequest(); $request->headers = array('Content-Type' => 'text/plain', 'Date' => 'Fri, 19 Mar 1982 00:00:04 GMT', 'Custom1' => 'Value1'); $expected = 'Acquia 1:' . DigestVersion1Test::EXPECTED_HASH; $this->assertEquals($expected, $signer->getAuthorization($request, '1', 'secret-key')); }
/** * @return \Acquia\Hmac\Guzzle\HmacAuthMiddleware */ public function getMiddleware() { $signer = new RequestSigner(); $signer->addCustomHeader('Custom1'); return new HmacAuthMiddleware($signer, '1', 'secret-key'); }