diff --git a/src/HttpRequestWrapper.php b/src/HttpRequestWrapper.php index 49cd1c136312..0346ae52f9ef 100644 --- a/src/HttpRequestWrapper.php +++ b/src/HttpRequestWrapper.php @@ -110,7 +110,7 @@ public function send(RequestInterface $request, array $options = []) */ public function signRequest(RequestInterface $request) { - if (!$this->credentials || $credentials['expiry'] < time()) { + if (!$this->credentials || $this->credentials['expiry'] < time()) { $this->credentials = $this->fetchCredentials(); } diff --git a/tests/HttpRequestWrapperTest.php b/tests/HttpRequestWrapperTest.php new file mode 100644 index 000000000000..5df07867c323 --- /dev/null +++ b/tests/HttpRequestWrapperTest.php @@ -0,0 +1,50 @@ +getMock(RequestInterface::class); + $request->method('getUri')->willReturn('/'); + $request->method('getHeaders')->willReturn([]); + + $wrapper = new HttpRequestWrapper(); + $refl = new \ReflectionClass($wrapper); + + $token = 'some_generated_token'; + $credentials = $refl->getProperty('credentials'); + $credentials->setAccessible(true); + $credentials->setValue($wrapper, [ + 'expiry' => strtotime('+300 seconds'), + 'access_token' => $token + ]); + + $signedRequest = $wrapper->signRequest($request); + + $header = $signedRequest->getHeader('Authorization')[0]; + + $this->assertEquals("Bearer $token", $header); + } +}