diff --git a/src/OAuth2/ResourceServer.php b/src/OAuth2/ResourceServer.php index 6bf3578c..f48a19f8 100644 --- a/src/OAuth2/ResourceServer.php +++ b/src/OAuth2/ResourceServer.php @@ -168,7 +168,7 @@ class ResourceServer } if (empty($access_token)) { - throw new Exception\MissingAccessTokenException('Access Token is Missing'); + throw new Exception\InvalidAccessTokenException('Access token is missing'); } return $access_token; diff --git a/src/OAuth2/Util/Request.php b/src/OAuth2/Util/Request.php index eefe37d0..ccb19dac 100644 --- a/src/OAuth2/Util/Request.php +++ b/src/OAuth2/Util/Request.php @@ -66,8 +66,10 @@ class Request implements RequestInterface protected function readHeaders() { if (function_exists('getallheaders')) { + // @codeCoverageIgnoreStart $headers = getallheaders(); } else { + // @codeCoverageIgnoreEnd $headers = array(); foreach ($this->server() as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { diff --git a/tests/resource/ResourceServerTest.php b/tests/resource/ResourceServerTest.php index 5f7361f7..3da9a991 100644 --- a/tests/resource/ResourceServerTest.php +++ b/tests/resource/ResourceServerTest.php @@ -4,15 +4,11 @@ use \Mockery as m; class Resource_Server_test extends PHPUnit_Framework_TestCase { - private $client; private $session; - private $scope; public function setUp() { - $this->client = M::mock('OAuth2\Storage\ClientInterface'); $this->session = M::mock('OAuth2\Storage\SessionInterface'); - //$this->scope = M::mock('OAuth2\Storage\ScopeInterface'); } private function returnDefault() @@ -64,7 +60,7 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase } /** - * @expectedException OAuth2\Exception\MissingAccessTokenException + * @expectedException OAuth2\Exception\InvalidAccessTokenException */ public function test_determineAccessToken_missingToken() { @@ -83,13 +79,19 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase public function test_determineAccessToken_fromHeader() { - $_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; - $request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER); + $request = new OAuth2\Util\Request(); - $s = $this->returnDefault(); - $s->setRequest($request); + $requestReflector = new ReflectionClass($request); + $param = $requestReflector->getProperty('headers'); + $param->setAccessible(true); + $param->setValue($request, array( + 'Authorization' => 'Bearer YWJjZGVm' + )); + $s = $this->returnDefault(); + $s->setRequest($request); $reflector = new ReflectionClass($s); + $method = $reflector->getMethod('determineAccessToken'); $method->setAccessible(true); @@ -121,11 +123,15 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase { $this->session->shouldReceive('validateAccessToken')->andReturn(false); - $_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; - $request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER); - - $s = $this->returnDefault(); - $s->setRequest($request); + $request = new OAuth2\Util\Request(); + $requestReflector = new ReflectionClass($request); + $param = $requestReflector->getProperty('headers'); + $param->setAccessible(true); + $param->setValue($request, array( + 'Authorization' => 'Bearer YWJjZGVm' + )); + $s = $this->returnDefault(); + $s->setRequest($request); $this->assertFalse($s->isValid()); } @@ -139,11 +145,15 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase )); $this->session->shouldReceive('getScopes')->andReturn(array('foo', 'bar')); - $_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; - $request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER); - - $s = $this->returnDefault(); - $s->setRequest($request); + $request = new OAuth2\Util\Request(); + $requestReflector = new ReflectionClass($request); + $param = $requestReflector->getProperty('headers'); + $param->setAccessible(true); + $param->setValue($request, array( + 'Authorization' => 'Bearer YWJjZGVm' + )); + $s = $this->returnDefault(); + $s->setRequest($request); $this->assertTrue($s->isValid()); $this->assertEquals(123, $s->getOwnerId());