Skip to content

Commit

Permalink
fixes subscriber and middleware options (#184)
Browse files Browse the repository at this point in the history
* fixes subscriber and middleware options
  • Loading branch information
bshaffer authored Jan 24, 2018
1 parent 6308640 commit 383ab84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ApplicationDefaultCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function getSubscriber(
) {
$creds = self::getCredentials($scope, $httpHandler, $cacheConfig, $cache);

return new AuthTokenSubscriber($creds, $cacheConfig);
return new AuthTokenSubscriber($creds, $httpHandler);
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function getMiddleware(
) {
$creds = self::getCredentials($scope, $httpHandler, $cacheConfig, $cache);

return new AuthTokenMiddleware($creds, $cacheConfig);
return new AuthTokenMiddleware($creds, $httpHandler);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/ApplicationDefaultCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ public function testFailsIfNotOnGceAndNoDefaultFileFound()
ApplicationDefaultCredentials::getMiddleware('a scope', $httpHandler);
}

public function testWithCacheOptions()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$httpHandler = getHandler([
buildResponse(200),
]);

$cacheOptions = [];
$cachePool = $this->getMock('Psr\Cache\CacheItemPoolInterface');

$middleware = ApplicationDefaultCredentials::getMiddleware(
'a scope',
$httpHandler,
$cacheOptions,
$cachePool
);
}

public function testSuccedsIfNoDefaultFilesButIsOnGCE()
{
$wantedTokens = [
Expand Down Expand Up @@ -280,6 +300,26 @@ public function testFailsIfNotOnGceAndNoDefaultFileFound()
ApplicationDefaultCredentials::getSubscriber('a scope', $httpHandler);
}

public function testWithCacheOptions()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$httpHandler = getHandler([
buildResponse(200),
]);

$cacheOptions = [];
$cachePool = $this->getMock('Psr\Cache\CacheItemPoolInterface');

$subscriber = ApplicationDefaultCredentials::getSubscriber(
'a scope',
$httpHandler,
$cacheOptions,
$cachePool
);
}

public function testSuccedsIfNoDefaultFilesButIsOnGCE()
{
$wantedTokens = [
Expand Down

0 comments on commit 383ab84

Please sign in to comment.