Skip to content

Commit

Permalink
Fix host name to support ports
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Sep 21, 2022
1 parent de626ea commit 4bc11d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

- [#218](https://github.com/Shopify/shopify-api-php/pull/218) Fix issue that failed when setting `Context::$HOST_NAME` with a port

## v3.2.0 - 2022-09-21

- [#213](https://github.com/Shopify/shopify-api-php/pull/213) Add 10s leeway when decoding session token JWTs
Expand Down
4 changes: 3 additions & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ public static function initialize(
throw new InvalidArgumentException("Invalid host: $hostName");
}

$host = $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? ":{$parsedUrl["port"]}" : "");

self::$API_KEY = $apiKey;
self::$API_SECRET_KEY = $apiSecretKey;
self::$SCOPES = $authScopes;
self::$HOST_NAME = $parsedUrl["host"];
self::$HOST_NAME = $host;
self::$HOST_SCHEME = $parsedUrl["scheme"];
self::$SESSION_STORAGE = $sessionStorage;
self::$HTTP_CLIENT_FACTORY = new HttpClientFactory();
Expand Down
12 changes: 7 additions & 5 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ public function testCanAddOverrideLogger()
/**
* @dataProvider canSetHostSchemeProvider
*/
public function testCanSetHostScheme($host, $expectedScheme)
public function testCanSetHostScheme($host, $expectedScheme, $expectedHost)
{
Context::initialize('ash', 'steffi', ['sleepy', 'kitty'], $host, new MockSessionStorage());

$this->assertEquals('my-friends-cats.io', Context::$HOST_NAME);
$this->assertEquals($expectedHost, Context::$HOST_NAME);
$this->assertEquals($expectedScheme, Context::$HOST_SCHEME);
}

public function canSetHostSchemeProvider()
{
return [
['my-friends-cats.io', 'https'],
['https://my-friends-cats.io', 'https'],
['http://my-friends-cats.io', 'http'],
['my-friends-cats.io', 'https', 'my-friends-cats.io'],
['https://my-friends-cats.io', 'https', 'my-friends-cats.io'],
['http://my-friends-cats.io', 'http', 'my-friends-cats.io'],
['http://localhost', 'http', 'localhost'],
['http://localhost:1234', 'http', 'localhost:1234'],
];
}

Expand Down

0 comments on commit 4bc11d1

Please # to comment.