Merge pull request #236 from vimishor/issue-230

[Fix] Invalid JSON in response will trigger fatal error
oauth1test
Ben Ramsey 2015-03-11 08:40:57 -05:00
commit 395b345e3d
2 changed files with 24 additions and 0 deletions

View File

@ -205,6 +205,11 @@ abstract class AbstractProvider implements ProviderInterface
switch ($this->responseType) {
case 'json':
$result = json_decode($response, true);
if (JSON_ERROR_NONE !== json_last_error()) {
$result = [];
}
break;
case 'string':
parse_str($response, $result);

View File

@ -65,6 +65,25 @@ class GithubTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('1', $token->uid);
}
/**
* @ticket 230
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Required option not passed: access_token
*/
public function testGetAccessTokenWithInvalidJson()
{
$response = m::mock('Guzzle\Http\Message\Response');
$response->shouldReceive('getBody')->times(1)->andReturn('invalid');
$client = m::mock('Guzzle\Service\Client');
$client->shouldReceive('setBaseUrl')->times(1);
$client->shouldReceive('post->send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$this->provider->responseType = 'json';
$this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
}
public function testGetAccessTokenSetResultUid()
{
$this->provider->uidKey = 'otherKey';