From dcce996e9893c0741dfa3ed4fcd9cf71d1ca16a3 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Mon, 27 Feb 2023 14:12:32 +0000 Subject: [PATCH] Fix IterableAPICollection Auth Handling (#379) * Mark potentially major bug * Fix to pull in the auth handling to the IterableApiCollection --- src/Client.php | 7 +++++-- src/Entity/IterableAPICollection.php | 5 +++++ test/Insights/ClientTest.php | 5 +++++ test/Messages/ClientTest.php | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 544c0e43..02bc90f9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -141,8 +141,11 @@ class Client implements LoggerAwareInterface /** * Create a new API client using the provided credentials. */ - public function __construct(CredentialsInterface $credentials, $options = [], ?ClientInterface $client = null) - { + public function __construct( + CredentialsInterface $credentials, + $options = [], + ?ClientInterface $client = null + ) { if (is_null($client)) { // Since the user did not pass a client, try and make a client // using the Guzzle 6 adapter or Guzzle 7 (depending on availability) diff --git a/src/Entity/IterableAPICollection.php b/src/Entity/IterableAPICollection.php index dfd0e0a8..02211a46 100644 --- a/src/Entity/IterableAPICollection.php +++ b/src/Entity/IterableAPICollection.php @@ -474,6 +474,11 @@ protected function fetchPage($absoluteUri): void } $request = new Request($requestUri, 'GET'); + + if ($this->getApiResource()->getAuthHandler()) { + $this->getApiResource()->addAuth($request); + } + $response = $this->client->send($request); $this->getApiResource()->setLastRequest($request); diff --git a/test/Insights/ClientTest.php b/test/Insights/ClientTest.php index 69a9e4f4..07adef6c 100644 --- a/test/Insights/ClientTest.php +++ b/test/Insights/ClientTest.php @@ -49,6 +49,11 @@ public function setUp(): void { $this->vonageClient = $this->prophesize(Client::class); $this->vonageClient->getApiUrl()->willReturn('http://api.nexmo.com'); + $this->vonageClient->getCredentials()->willReturn( + new Client\Credentials\Container( + new Client\Credentials\Basic('abc', 'def'), + ) + ); $this->api = new APIResource(); $this->api->setIsHAL(false); diff --git a/test/Messages/ClientTest.php b/test/Messages/ClientTest.php index c762a29d..fd626347 100644 --- a/test/Messages/ClientTest.php +++ b/test/Messages/ClientTest.php @@ -645,7 +645,7 @@ public function testCanSendViberText(): void public function testThrowsRequestErrorOnBadRequest(): void { $this->expectException(Client\Exception\Request::class); - $this->expectErrorMessage('The request body did not contain valid JSON: Unexpected character (\'"\' (code 34)): was expecting comma to separate Object entries'); + $this->expectExceptionMessage('The request body did not contain valid JSON: Unexpected character (\'"\' (code 34)): was expecting comma to separate Object entries'); $payload = [ 'to' => '447700900000', @@ -671,7 +671,7 @@ public function testThrowsRequestErrorOnBadRequest(): void public function testThrowsRateLimit(): void { $this->expectException(Client\Exception\ThrottleException::class); - $this->expectErrorMessage('Rate Limit Hit: Please wait, then retry your request'); + $this->expectExceptionMessage('Rate Limit Hit: Please wait, then retry your request'); $payload = [ 'to' => '447700900000',