mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
Lots of fixes for tests following exceptions changes
This commit is contained in:
parent
9f1f0cc3bc
commit
1183fe80c6
@ -5,7 +5,7 @@ namespace LeagueTests;
|
|||||||
use LeagueTests\Stubs\StubAbstractServer;
|
use LeagueTests\Stubs\StubAbstractServer;
|
||||||
use \Mockery as M;
|
use \Mockery as M;
|
||||||
|
|
||||||
class AbstractTokenTests extends \PHPUnit_Framework_TestCase
|
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
function testSetGet()
|
function testSetGet()
|
||||||
{
|
{
|
||||||
@ -19,7 +19,7 @@ class AbstractTokenTests extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testGetStorageException()
|
function testGetStorageException()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ServerException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\ServerErrorException');
|
||||||
$server = new StubAbstractServer();
|
$server = new StubAbstractServer();
|
||||||
$server->getStorage('foobar');
|
$server->getStorage('foobar');
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,8 @@ use League\OAuth2\Server\Grant\GrantTypeInterface;
|
|||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
use \Mockery as M;
|
use \Mockery as M;
|
||||||
|
|
||||||
class AuthorizationTests extends \PHPUnit_Framework_TestCase
|
class AuthorizationTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetExceptionMessage()
|
|
||||||
{
|
|
||||||
$m = AuthorizationServer::getExceptionMessage('access_denied');
|
|
||||||
|
|
||||||
$reflector = new \ReflectionClass('League\OAuth2\Server\AuthorizationServer');
|
|
||||||
$exceptionMessages = $reflector->getProperty('exceptionMessages');
|
|
||||||
$exceptionMessages->setAccessible(true);
|
|
||||||
$v = $exceptionMessages->getValue();
|
|
||||||
|
|
||||||
$this->assertEquals($v['access_denied'], $m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetExceptionCode()
|
|
||||||
{
|
|
||||||
$this->assertEquals('access_denied', AuthorizationServer::getExceptionType(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetExceptionHttpHeaders()
|
|
||||||
{
|
|
||||||
$this->assertEquals(array('HTTP/1.1 401 Unauthorized'), AuthorizationServer::getExceptionHttpHeaders('access_denied'));
|
|
||||||
$this->assertEquals(array('HTTP/1.1 500 Internal Server Error'), AuthorizationServer::getExceptionHttpHeaders('server_error'));
|
|
||||||
$this->assertEquals(array('HTTP/1.1 501 Not Implemented'), AuthorizationServer::getExceptionHttpHeaders('unsupported_grant_type'));
|
|
||||||
$this->assertEquals(array('HTTP/1.1 400 Bad Request'), AuthorizationServer::getExceptionHttpHeaders('invalid_refresh'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer;
|
||||||
@ -67,7 +42,7 @@ class AuthorizationTests extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testInvalidGrantType()
|
public function testInvalidGrantType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantTypeException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantException');
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer;
|
||||||
$server->getGrantType('foobar');
|
$server->getGrantType('foobar');
|
||||||
}
|
}
|
||||||
@ -90,14 +65,14 @@ class AuthorizationTests extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testIssueAccessTokenEmptyGrantType()
|
public function testIssueAccessTokenEmptyGrantType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer;
|
||||||
$this->assertTrue($server->issueAccessToken());
|
$this->assertTrue($server->issueAccessToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIssueAccessTokenInvalidGrantType()
|
public function testIssueAccessTokenInvalidGrantType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\UnsupportedGrantTypeException');
|
||||||
|
|
||||||
$_POST['grant_type'] = 'foobar';
|
$_POST['grant_type'] = 'foobar';
|
||||||
|
|
@ -5,7 +5,7 @@ namespace LeagueTests\Grant;
|
|||||||
use League\OAuth2\Server\Grant;
|
use League\OAuth2\Server\Grant;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\Scope;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Grant\ClientException;
|
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||||
use LeagueTests\Stubs\StubAbstractGrant;
|
use LeagueTests\Stubs\StubAbstractGrant;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidateScopesMissingScope()
|
public function testValidateScopesMissingScope()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
@ -91,7 +91,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidateScopesInvalidScope()
|
public function testValidateScopesInvalidScope()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
|
@ -9,7 +9,7 @@ use League\OAuth2\Server\Entity\Client;
|
|||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\Session;
|
||||||
use League\OAuth2\Server\Entity\AuthCode as AC;
|
use League\OAuth2\Server\Entity\AuthCode as AC;
|
||||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
||||||
use League\OAuth2\Server\Grant\ClientException;
|
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -27,7 +27,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsMissingClientId()
|
public function testCheckAuthoriseParamsMissingClientId()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [];
|
$_POST = [];
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsMissingRedirectUri()
|
public function testCheckAuthoriseParamsMissingRedirectUri()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "redirect_uri" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp'
|
||||||
@ -56,7 +56,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsMissingStateParam()
|
public function testCheckAuthoriseParamsMissingStateParam()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "state" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
@ -73,7 +73,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsMissingResponseType()
|
public function testCheckAuthoriseParamsMissingResponseType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "response_type" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
@ -89,7 +89,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsInvalidResponseType()
|
public function testCheckAuthoriseParamsInvalidResponseType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The authorization server does not support obtaining an access token using this method.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\UnsupportedResponseTypeException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
@ -106,7 +106,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsInvalidClient()
|
public function testCheckAuthoriseParamsInvalidClient()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
@ -129,7 +129,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCheckAuthoriseParamsInvalidScope()
|
public function testCheckAuthoriseParamsInvalidScope()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "foo" scope.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'response_type' => 'code',
|
'response_type' => 'code',
|
||||||
@ -260,7 +260,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowMissingClientId()
|
public function testCompleteFlowMissingClientId()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST['grant_type'] = 'authorization_code';
|
$_POST['grant_type'] = 'authorization_code';
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowMissingClientSecret()
|
public function testCompleteFlowMissingClientSecret()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
@ -290,7 +290,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowMissingRedirectUri()
|
public function testCompleteFlowMissingRedirectUri()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "redirect_uri" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
@ -307,7 +307,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowInvalidClient()
|
public function testCompleteFlowInvalidClient()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
@ -331,7 +331,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowMissingCode()
|
public function testCompleteFlowMissingCode()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "code" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
@ -379,7 +379,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowInvalidCode()
|
public function testCompleteFlowInvalidCode()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "code" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
@ -428,7 +428,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testCompleteFlowRedirectUriMismatch()
|
public function testCompleteFlowRedirectUriMismatch()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "redirect_uri" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
|
@ -13,7 +13,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
function testCompleteFlowMissingClientId()
|
function testCompleteFlowMissingClientId()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST['grant_type'] = 'client_credentials';
|
$_POST['grant_type'] = 'client_credentials';
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowMissingClientSecret()
|
function testCompleteFlowMissingClientSecret()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
@ -43,7 +43,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidClient()
|
function testCompleteFlowInvalidClient()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
@ -66,7 +66,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidScope()
|
function testCompleteFlowInvalidScope()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "foo" scope.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
|
@ -7,14 +7,13 @@ use League\OAuth2\Server\Grant\RefreshToken;
|
|||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\Scope;
|
||||||
use League\OAuth2\Server\Entity\Client;
|
use League\OAuth2\Server\Entity\Client;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Grant\ClientException;
|
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class PasswordTest extends \PHPUnit_Framework_TestCase
|
class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
function testCompleteFlowMissingClientId()
|
function testCompleteFlowMissingClientId()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST['grant_type'] = 'password';
|
$_POST['grant_type'] = 'password';
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowMissingClientSecret()
|
function testCompleteFlowMissingClientSecret()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -44,7 +43,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidClient()
|
function testCompleteFlowInvalidClient()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -67,7 +66,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testNoUsername()
|
function testNoUsername()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "username" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -109,7 +108,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testNoPassword()
|
function testNoPassword()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "password" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -152,7 +151,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testNoCallable()
|
function testNoCallable()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantTypeException', 'Null or non-callable callback set on Password grant');
|
$this->setExpectedException('League\OAuth2\Server\Exception\ServerErrorException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -196,7 +195,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidScope()
|
function testCompleteFlowInvalidScope()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "foo" scope.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -244,7 +243,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowNoScopes()
|
function testCompleteFlowNoScopes()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "scope" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
@ -293,7 +292,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidCredentials()
|
function testCompleteFlowInvalidCredentials()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The user credentials were incorrect.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidCredentialsException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
|
@ -9,7 +9,6 @@ use League\OAuth2\Server\Entity\AccessToken;
|
|||||||
use League\OAuth2\Server\Entity\Session;
|
use League\OAuth2\Server\Entity\Session;
|
||||||
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
use League\OAuth2\Server\Entity\RefreshToken as RT;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Grant\ClientException;
|
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -27,7 +26,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowMissingClientId()
|
function testCompleteFlowMissingClientId()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST['grant_type'] = 'refresh_token';
|
$_POST['grant_type'] = 'refresh_token';
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowMissingClientSecret()
|
function testCompleteFlowMissingClientSecret()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
@ -56,7 +55,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidClient()
|
function testCompleteFlowInvalidClient()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
@ -79,7 +78,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowMissingRefreshToken()
|
function testCompleteFlowMissingRefreshToken()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "refresh_token" parameter.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
@ -113,7 +112,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function testCompleteFlowInvalidRefreshToken()
|
function testCompleteFlowInvalidRefreshToken()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The refresh token is invalid.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRefreshException');
|
||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
@ -352,7 +351,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
|
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "blah" scope.');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
|
||||||
|
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use League\OAuth2\Server\Entity\Client;
|
|||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\Scope;
|
||||||
use \Mockery as M;
|
use \Mockery as M;
|
||||||
|
|
||||||
class ResourceServerTests extends \PHPUnit_Framework_TestCase
|
class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private function returnDefault()
|
private function returnDefault()
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ class ResourceServerTests extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDetermineAccessTokenMissingToken()
|
public function testDetermineAccessTokenMissingToken()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidAccessTokenException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
@ -89,43 +89,6 @@ class ResourceServerTests extends \PHPUnit_Framework_TestCase
|
|||||||
$method->invoke($server);
|
$method->invoke($server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDetermineAccessTokenBrokenCurlRequest()
|
|
||||||
{
|
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidAccessTokenException');
|
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
|
||||||
$sessionStorage->shouldReceive('setServer');
|
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
|
||||||
$accessTokenStorage->shouldReceive('get')->andReturn(false);
|
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
|
||||||
$clientStorage->shouldReceive('setServer');
|
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
|
||||||
$scopeStorage->shouldReceive('setServer');
|
|
||||||
|
|
||||||
$server = new ResourceServer(
|
|
||||||
$sessionStorage,
|
|
||||||
$accessTokenStorage,
|
|
||||||
$clientStorage,
|
|
||||||
$scopeStorage
|
|
||||||
);
|
|
||||||
|
|
||||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
|
||||||
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
|
||||||
'Authorization' => 'Bearer, Bearer abcdef'
|
|
||||||
]);
|
|
||||||
$server->setRequest($request);
|
|
||||||
|
|
||||||
$reflector = new \ReflectionClass($server);
|
|
||||||
$method = $reflector->getMethod('determineAccessToken');
|
|
||||||
$method->setAccessible(true);
|
|
||||||
|
|
||||||
$method->invoke($server);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsValidNotValid()
|
public function testIsValidNotValid()
|
||||||
{
|
{
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@ -148,7 +111,7 @@ class ResourceServerTests extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage
|
$scopeStorage
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertFalse($server->isValid());
|
$this->assertFalse($server->isValidRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsValid()
|
public function testIsValid()
|
||||||
@ -197,7 +160,7 @@ class ResourceServerTests extends \PHPUnit_Framework_TestCase
|
|||||||
]);
|
]);
|
||||||
$server->setRequest($request);
|
$server->setRequest($request);
|
||||||
|
|
||||||
$this->assertTrue($server->isValid());
|
$this->assertTrue($server->isValidRequest());
|
||||||
$this->assertEquals('at', $server->getTokenKey());
|
$this->assertEquals('at', $server->getTokenKey());
|
||||||
$this->assertEquals(123, $server->getOwnerId());
|
$this->assertEquals(123, $server->getOwnerId());
|
||||||
$this->assertEquals('user', $server->getOwnerType());
|
$this->assertEquals('user', $server->getOwnerType());
|
Loading…
Reference in New Issue
Block a user