Various fixes and tweaks

This commit is contained in:
Alex Bilbie 2013-02-08 11:40:33 +00:00
parent 89f3c35466
commit 60b2caf41d
3 changed files with 32 additions and 20 deletions

View File

@ -168,7 +168,7 @@ class ResourceServer
} }
if (empty($access_token)) { if (empty($access_token)) {
throw new Exception\MissingAccessTokenException('Access Token is Missing'); throw new Exception\InvalidAccessTokenException('Access token is missing');
} }
return $access_token; return $access_token;

View File

@ -66,8 +66,10 @@ class Request implements RequestInterface
protected function readHeaders() protected function readHeaders()
{ {
if (function_exists('getallheaders')) { if (function_exists('getallheaders')) {
// @codeCoverageIgnoreStart
$headers = getallheaders(); $headers = getallheaders();
} else { } else {
// @codeCoverageIgnoreEnd
$headers = array(); $headers = array();
foreach ($this->server() as $name => $value) { foreach ($this->server() as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') { if (substr($name, 0, 5) == 'HTTP_') {

View File

@ -4,15 +4,11 @@ use \Mockery as m;
class Resource_Server_test extends PHPUnit_Framework_TestCase class Resource_Server_test extends PHPUnit_Framework_TestCase
{ {
private $client;
private $session; private $session;
private $scope;
public function setUp() public function setUp()
{ {
$this->client = M::mock('OAuth2\Storage\ClientInterface');
$this->session = M::mock('OAuth2\Storage\SessionInterface'); $this->session = M::mock('OAuth2\Storage\SessionInterface');
//$this->scope = M::mock('OAuth2\Storage\ScopeInterface');
} }
private function returnDefault() 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() public function test_determineAccessToken_missingToken()
{ {
@ -83,13 +79,19 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase
public function test_determineAccessToken_fromHeader() public function test_determineAccessToken_fromHeader()
{ {
$_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; $request = new OAuth2\Util\Request();
$request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER);
$requestReflector = new ReflectionClass($request);
$param = $requestReflector->getProperty('headers');
$param->setAccessible(true);
$param->setValue($request, array(
'Authorization' => 'Bearer YWJjZGVm'
));
$s = $this->returnDefault(); $s = $this->returnDefault();
$s->setRequest($request); $s->setRequest($request);
$reflector = new ReflectionClass($s); $reflector = new ReflectionClass($s);
$method = $reflector->getMethod('determineAccessToken'); $method = $reflector->getMethod('determineAccessToken');
$method->setAccessible(true); $method->setAccessible(true);
@ -121,9 +123,13 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase
{ {
$this->session->shouldReceive('validateAccessToken')->andReturn(false); $this->session->shouldReceive('validateAccessToken')->andReturn(false);
$_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; $request = new OAuth2\Util\Request();
$request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER); $requestReflector = new ReflectionClass($request);
$param = $requestReflector->getProperty('headers');
$param->setAccessible(true);
$param->setValue($request, array(
'Authorization' => 'Bearer YWJjZGVm'
));
$s = $this->returnDefault(); $s = $this->returnDefault();
$s->setRequest($request); $s->setRequest($request);
@ -139,9 +145,13 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase
)); ));
$this->session->shouldReceive('getScopes')->andReturn(array('foo', 'bar')); $this->session->shouldReceive('getScopes')->andReturn(array('foo', 'bar'));
$_SERVER['HTTP_AUTHORIZATION'] = 'Bearer abcdef'; $request = new OAuth2\Util\Request();
$request = new OAuth2\Util\Request(array(), array(), array(), array(), $_SERVER); $requestReflector = new ReflectionClass($request);
$param = $requestReflector->getProperty('headers');
$param->setAccessible(true);
$param->setValue($request, array(
'Authorization' => 'Bearer YWJjZGVm'
));
$s = $this->returnDefault(); $s = $this->returnDefault();
$s->setRequest($request); $s->setRequest($request);