mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-05 11:41:53 +05:30
Various fixes and tweaks
This commit is contained in:
parent
89f3c35466
commit
60b2caf41d
@ -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;
|
||||||
|
@ -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_') {
|
||||||
|
@ -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);
|
|
||||||
|
|
||||||
$s = $this->returnDefault();
|
$requestReflector = new ReflectionClass($request);
|
||||||
$s->setRequest($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);
|
$reflector = new ReflectionClass($s);
|
||||||
|
|
||||||
$method = $reflector->getMethod('determineAccessToken');
|
$method = $reflector->getMethod('determineAccessToken');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
@ -121,11 +123,15 @@ 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');
|
||||||
$s = $this->returnDefault();
|
$param->setAccessible(true);
|
||||||
$s->setRequest($request);
|
$param->setValue($request, array(
|
||||||
|
'Authorization' => 'Bearer YWJjZGVm'
|
||||||
|
));
|
||||||
|
$s = $this->returnDefault();
|
||||||
|
$s->setRequest($request);
|
||||||
|
|
||||||
$this->assertFalse($s->isValid());
|
$this->assertFalse($s->isValid());
|
||||||
}
|
}
|
||||||
@ -139,11 +145,15 @@ 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');
|
||||||
$s = $this->returnDefault();
|
$param->setAccessible(true);
|
||||||
$s->setRequest($request);
|
$param->setValue($request, array(
|
||||||
|
'Authorization' => 'Bearer YWJjZGVm'
|
||||||
|
));
|
||||||
|
$s = $this->returnDefault();
|
||||||
|
$s->setRequest($request);
|
||||||
|
|
||||||
$this->assertTrue($s->isValid());
|
$this->assertTrue($s->isValid());
|
||||||
$this->assertEquals(123, $s->getOwnerId());
|
$this->assertEquals(123, $s->getOwnerId());
|
||||||
|
Loading…
Reference in New Issue
Block a user