Skip to content

Commit

Permalink
Merge pull request #29 from mcrumm/key_file_rewind
Browse files Browse the repository at this point in the history
Rewind the keyFileStream before each read
  • Loading branch information
dwsupplee committed Apr 3, 2016
2 parents fc0014d + d9b7ab3 commit bda29bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/RequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function getCredentialsFetcher()
}

if ($this->keyFileStream) {
$this->keyFileStream->rewind();
return CredentialsLoader::makeCredentials($this->scopes, $this->keyFileStream);
}

Expand Down
32 changes: 32 additions & 0 deletions tests/RequestWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ public function testCredentialsFetcher($wrapperConfig)
);
}

/**
* @dataProvider keyFileCredentialsProvider
*/
public function testCredentialsFromKeyFileStreamCanBeReadMultipleTimes($wrapperConfig)
{
$requestWrapper = new RequestWrapper($wrapperConfig);

$requestWrapper->getCredentialsFetcher();
$credentials = $requestWrapper->getCredentialsFetcher();

$this->assertInstanceOf('Google\Auth\FetchAuthTokenInterface', $credentials);
}

public function credentialsProvider()
{
$config = [
Expand All @@ -130,6 +143,25 @@ public function credentialsProvider()
];
}

public function keyFileCredentialsProvider()
{
$config = [
'authHttpHandler' => function ($request, $options = []) {
return new Response(200, [], json_encode(['access_token' => 'abc']));
},
'httpHandler' => function ($request, $options = []) {
return new Response(200, []);
}
];

$keyFilePath = __DIR__ . '/fixtures/json-key-fixture.json';

return [
[$config + ['keyFile' => file_get_contents($keyFilePath)]], // keyFile
[$config + ['keyFilePath' => $keyFilePath]], //keyFilePath
];
}

public function testAddsUserAgentToRequest()
{
$requestWrapper = new RequestWrapper([
Expand Down

0 comments on commit bda29bb

Please sign in to comment.