Skip to content

Commit

Permalink
Make sure we select region properly (#754)
Browse files Browse the repository at this point in the history
* make sure we select region properly

* Adding changelog
  • Loading branch information
Nyholm authored Aug 29, 2020
1 parent 259af62 commit e3e2cbf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## NOT RELEASED

## 1.4.1

### Fixed

- Make sure passing `@region` to an API operation has effect.
- Check that both AWS access id and secret exists before using them.

## 1.4.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function getEndpointMetadata(?string $region): array
protected function getEndpoint(string $uri, array $query, ?string $region): string
{
/** @var string $region */
$region = $region ?? $this->configuration->isDefault('region') ? null : $this->configuration->get('region');
$region = $region ?? ($this->configuration->isDefault('region') ? null : $this->configuration->get('region'));
if (!$this->configuration->isDefault('endpoint')) {
/** @var string $endpoint */
$endpoint = $this->configuration->get('endpoint');
Expand Down
54 changes: 54 additions & 0 deletions tests/Unit/AbstractApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace AsyncAws\Core\Tests\Unit;

use AsyncAws\Core\AbstractApi;
use AsyncAws\Core\Configuration;
use PHPUnit\Framework\TestCase;

class AbstractApiTest extends TestCase
{
public function testGetEndpointRegion()
{
$api = new DummyApi();

// Use default region
$endpoint = $api->getEndpoint('/some/path', [], null);
self::assertEquals('https://foobar.us-east-1.amazonaws.com/some/path', $endpoint);

$endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1');
self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint);

// Use region from config
$api = new DummyApi(['region' => 'eu-north-1']);
$endpoint = $api->getEndpoint('/some/path', [], null);
self::assertEquals('https://foobar.eu-north-1.amazonaws.com/some/path', $endpoint);

$endpoint = $api->getEndpoint('/some/path', [], 'eu-central-1');
self::assertEquals('https://foobar.eu-central-1.amazonaws.com/some/path', $endpoint);
}
}

class DummyApi extends AbstractApi
{
public function getEndpoint(string $uri, array $query, ?string $region): string
{
return parent::getEndpoint($uri, $query, $region);
}

protected function getEndpointMetadata(?string $region): array
{
if (null === $region) {
$region = Configuration::DEFAULT_REGION;
}

return [
'endpoint' => "https://foobar.$region.amazonaws.com",
'signRegion' => $region,
'signService' => 'foobar',
'signVersions' => ['v4'],
];
}
}

0 comments on commit e3e2cbf

Please sign in to comment.