/** * Ensures the HTTP HMAC middleware timestamps requests correctly. */ public function testSetDefaultDateHeader() { $middleware = new HmacAuthMiddleware($this->authKey); $uri = 'http://example.com/resource/1?key=value'; $request = $middleware->signRequest(new Request('GET', $uri, [])); $timestamp = (int) $request->getHeaderLine('X-Authorization-Timestamp'); // It shouldn't take this test 10 seconds to run, but pad it since we // can not assume the time will be exactly the same. $difference = time() - $timestamp; $this->assertTrue($difference > -10); $this->assertTrue($difference < 10); }
/** * Initializes the middleware with a key, realm, and custom auth header. * * @param \Acquia\Hmac\KeyInterface $key * The key to sign requests with. * @param string $realm * The API realm/provider. * @param array $customHeaders * Custom headers to use in the signature. * @param \Acquia\Hmac\AuthorizationHeaderInterface $authHeader * The custom authorization header. */ public function __construct(KeyInterface $key, $realm, array $customHeaders, AuthorizationHeader $authHeader) { parent::__construct($key, $realm); $this->requestSigner = new MockRequestSigner($key, $realm, new Digest(), $authHeader); }