Skip to content

Commit

Permalink
Fix IterableAPICollection Auth Handling (#379)
Browse files Browse the repository at this point in the history
* Mark potentially major bug

* Fix to pull in the auth handling to the IterableApiCollection
  • Loading branch information
SecondeJK authored Feb 27, 2023
1 parent ccbbf9c commit dcce996
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/IterableAPICollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/Insights/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/Messages/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit dcce996

Please sign in to comment.