mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
Update dependencies and fix PHPUnit tests
This commit is contained in:
parent
bac79a26a8
commit
e3b23fa826
@ -6,18 +6,18 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1.0",
|
"php": ">=7.1.0",
|
||||||
"ext-openssl": "*",
|
"ext-openssl": "*",
|
||||||
"league/event": "^2.1",
|
"league/event": "^2.2",
|
||||||
"lcobucci/jwt": "^3.2.2",
|
"lcobucci/jwt": "^3.3.1",
|
||||||
"psr/http-message": "^1.0.1",
|
"psr/http-message": "^1.0.1",
|
||||||
"defuse/php-encryption": "^2.1",
|
"defuse/php-encryption": "^2.2.1",
|
||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^6.3 || ^7.0",
|
"phpunit/phpunit": "^7.5.13 || ^8.2.3",
|
||||||
"zendframework/zend-diactoros": "^1.3.2",
|
"zendframework/zend-diactoros": "^2.1.2",
|
||||||
"phpstan/phpstan": "^0.9.2",
|
"phpstan/phpstan": "^0.11.8",
|
||||||
"phpstan/phpstan-phpunit": "^0.9.4",
|
"phpstan/phpstan-phpunit": "^0.11.2",
|
||||||
"phpstan/phpstan-strict-rules": "^0.9.0",
|
"phpstan/phpstan-strict-rules": "^0.11.1",
|
||||||
"roave/security-advisories": "dev-master"
|
"roave/security-advisories": "dev-master"
|
||||||
},
|
},
|
||||||
"repositories": [
|
"repositories": [
|
||||||
|
@ -31,7 +31,7 @@ class AuthorizationServerTest extends TestCase
|
|||||||
{
|
{
|
||||||
const DEFAULT_SCOPE = 'basic';
|
const DEFAULT_SCOPE = 'basic';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
// Make sure the keys have the correct permissions.
|
// Make sure the keys have the correct permissions.
|
||||||
chmod(__DIR__ . '/Stubs/private.key', 0600);
|
chmod(__DIR__ . '/Stubs/private.key', 0600);
|
||||||
@ -326,10 +326,6 @@ class AuthorizationServerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 2
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestUnregistered()
|
public function testValidateAuthorizationRequestUnregistered()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer(
|
$server = new AuthorizationServer(
|
||||||
@ -340,19 +336,13 @@ class AuthorizationServerTest extends TestCase
|
|||||||
'file://' . __DIR__ . '/Stubs/public.key'
|
'file://' . __DIR__ . '/Stubs/public.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
]);
|
||||||
null,
|
|
||||||
'php://input',
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
$headers = [],
|
$this->expectExceptionCode(2);
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$server->validateAuthorizationRequest($request);
|
$server->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,6 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class BearerTokenValidatorTest extends TestCase
|
class BearerTokenValidatorTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @expectedException League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 9
|
|
||||||
*/
|
|
||||||
public function testThrowExceptionWhenAccessTokenIsNotSigned()
|
public function testThrowExceptionWhenAccessTokenIsNotSigned()
|
||||||
{
|
{
|
||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
@ -35,6 +31,9 @@ class BearerTokenValidatorTest extends TestCase
|
|||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$request = $request->withHeader('authorization', sprintf('Bearer %s', $unsignedJwt));
|
$request = $request->withHeader('authorization', sprintf('Bearer %s', $unsignedJwt));
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(9);
|
||||||
|
|
||||||
$bearerTokenValidator->validateAuthorization($request);
|
$bearerTokenValidator->validateAuthorization($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,9 +148,7 @@ class AbstractGrantTest extends TestCase
|
|||||||
$this->assertEquals($client, $result);
|
$this->assertEquals($client, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientMissingClientId()
|
public function testValidateClientMissingClientId()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -167,12 +165,11 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientMissingClientSecret()
|
public function testValidateClientMissingClientSecret()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -192,12 +189,11 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientInvalidClientSecret()
|
public function testValidateClientInvalidClientSecret()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -218,12 +214,11 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientInvalidRedirectUri()
|
public function testValidateClientInvalidRedirectUri()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -246,12 +241,11 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientInvalidRedirectUriArray()
|
public function testValidateClientInvalidRedirectUriArray()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -274,12 +268,11 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateClientBadClient()
|
public function testValidateClientBadClient()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -300,6 +293,8 @@ class AbstractGrantTest extends TestCase
|
|||||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||||
$validateClientMethod->setAccessible(true);
|
$validateClientMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$validateClientMethod->invoke($grantMock, $serverRequest, true);
|
$validateClientMethod->invoke($grantMock, $serverRequest, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,8 +434,7 @@ class AbstractGrantTest extends TestCase
|
|||||||
$method = $abstractGrantReflection->getMethod('getQueryStringParameter');
|
$method = $abstractGrantReflection->getMethod('getQueryStringParameter');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withQueryParams([
|
||||||
$serverRequest = $serverRequest->withQueryParams([
|
|
||||||
'foo' => 'bar',
|
'foo' => 'bar',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -461,9 +455,6 @@ class AbstractGrantTest extends TestCase
|
|||||||
$this->assertEquals([$scope], $grantMock->validateScopes('basic '));
|
$this->assertEquals([$scope], $grantMock->validateScopes('basic '));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateScopesBadScope()
|
public function testValidateScopesBadScope()
|
||||||
{
|
{
|
||||||
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
$scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock();
|
||||||
@ -473,6 +464,8 @@ class AbstractGrantTest extends TestCase
|
|||||||
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
||||||
$grantMock->setScopeRepository($scopeRepositoryMock);
|
$grantMock->setScopeRepository($scopeRepositoryMock);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$grantMock->validateScopes('basic ');
|
$grantMock->validateScopes('basic ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +477,7 @@ class AbstractGrantTest extends TestCase
|
|||||||
$method = $abstractGrantReflection->getMethod('generateUniqueIdentifier');
|
$method = $abstractGrantReflection->getMethod('generateUniqueIdentifier');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$this->assertInternalType('string', $method->invoke($grantMock));
|
$this->assertIsString($method->invoke($grantMock));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanRespondToAuthorizationRequest()
|
public function testCanRespondToAuthorizationRequest()
|
||||||
@ -493,21 +486,21 @@ class AbstractGrantTest extends TestCase
|
|||||||
$this->assertFalse($grantMock->canRespondToAuthorizationRequest(new ServerRequest()));
|
$this->assertFalse($grantMock->canRespondToAuthorizationRequest(new ServerRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequest()
|
public function testValidateAuthorizationRequest()
|
||||||
{
|
{
|
||||||
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grantMock->validateAuthorizationRequest(new ServerRequest());
|
$grantMock->validateAuthorizationRequest(new ServerRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testCompleteAuthorizationRequest()
|
public function testCompleteAuthorizationRequest()
|
||||||
{
|
{
|
||||||
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grantMock->completeAuthorizationRequest(new AuthorizationRequest());
|
$grantMock->completeAuthorizationRequest(new AuthorizationRequest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ use LeagueTests\Stubs\StubResponseType;
|
|||||||
use LeagueTests\Stubs\UserEntity;
|
use LeagueTests\Stubs\UserEntity;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Zend\Diactoros\ServerRequest;
|
use Zend\Diactoros\ServerRequest;
|
||||||
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
class AuthCodeGrantTest extends TestCase
|
class AuthCodeGrantTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -40,7 +41,7 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
|
|
||||||
const CODE_CHALLENGE = 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM';
|
const CODE_CHALLENGE = 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->cryptStub = new CryptTraitStub();
|
$this->cryptStub = new CryptTraitStub();
|
||||||
}
|
}
|
||||||
@ -200,9 +201,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooShort()
|
public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooShort()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -218,28 +216,18 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
'code_challenge' => str_repeat('A', 42),
|
||||||
'php://input',
|
]);
|
||||||
[],
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
'code_challenge' => str_repeat('A', 42),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooLong()
|
public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooLong()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -255,28 +243,18 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
'code_challenge' => str_repeat('A', 129),
|
||||||
'php://input',
|
]);
|
||||||
[],
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
'code_challenge' => str_repeat('A', 129),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestCodeChallengeInvalidCharacters()
|
public function testValidateAuthorizationRequestCodeChallengeInvalidCharacters()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -292,29 +270,18 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
|
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
'code_challenge' => str_repeat('A', 42) . '!',
|
||||||
'php://input',
|
]);
|
||||||
[],
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
'code_challenge' => str_repeat('A', 42) . '!',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestMissingClientId()
|
public function testValidateAuthorizationRequestMissingClientId()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -326,26 +293,16 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
]);
|
||||||
null,
|
|
||||||
null,
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
'php://input',
|
$this->expectExceptionCode(3);
|
||||||
$headers = [],
|
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestInvalidClientId()
|
public function testValidateAuthorizationRequestInvalidClientId()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -358,27 +315,17 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
]);
|
||||||
null,
|
|
||||||
'php://input',
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
$headers = [],
|
$this->expectExceptionCode(4);
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestBadRedirectUriString()
|
public function testValidateAuthorizationRequestBadRedirectUriString()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -393,28 +340,18 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
[],
|
$this->expectExceptionCode(4);
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestBadRedirectUriArray()
|
public function testValidateAuthorizationRequestBadRedirectUriArray()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -429,28 +366,18 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
[],
|
$this->expectExceptionCode(4);
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestInvalidCodeChallengeMethod()
|
public function testValidateAuthorizationRequestInvalidCodeChallengeMethod()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -472,22 +399,16 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
'code_challenge' => 'foobar',
|
||||||
'php://input',
|
'code_challenge_method' => 'foo',
|
||||||
[],
|
]);
|
||||||
[],
|
|
||||||
[
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
'response_type' => 'code',
|
$this->expectExceptionCode(3);
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
'code_challenge' => 'foobar',
|
|
||||||
'code_challenge_method' => 'foo',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
@ -513,10 +434,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 9
|
|
||||||
*/
|
|
||||||
public function testCompleteAuthorizationRequestDenied()
|
public function testCompleteAuthorizationRequestDenied()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -535,6 +452,9 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setEncryptionKey($this->cryptStub->getKey());
|
$grant->setEncryptionKey($this->cryptStub->getKey());
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(9);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest($authRequest);
|
$grant->completeAuthorizationRequest($authRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,10 +874,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testRespondToAccessTokenRequestMissingRedirectUri()
|
public function testRespondToAccessTokenRequestMissingRedirectUri()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -999,13 +915,12 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(3);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testRespondToAccessTokenRequestRedirectUriMismatch()
|
public function testRespondToAccessTokenRequestRedirectUriMismatch()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -1048,13 +963,12 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(3);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testRespondToAccessTokenRequestMissingCode()
|
public function testRespondToAccessTokenRequestMissingCode()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -1093,6 +1007,9 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(3);
|
||||||
|
|
||||||
/* @var StubResponseType $response */
|
/* @var StubResponseType $response */
|
||||||
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
$grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
||||||
}
|
}
|
||||||
@ -1711,10 +1628,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 7
|
|
||||||
*/
|
|
||||||
public function testAuthCodeRepositoryFailToPersist()
|
public function testAuthCodeRepositoryFailToPersist()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -1734,13 +1647,12 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
$grant->setEncryptionKey($this->cryptStub->getKey());
|
$grant->setEncryptionKey($this->cryptStub->getKey());
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(7);
|
||||||
|
|
||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
|
|
||||||
* @expectedExceptionCode 100
|
|
||||||
*/
|
|
||||||
public function testAuthCodeRepositoryFailToPersistUniqueNoInfiniteLoop()
|
public function testAuthCodeRepositoryFailToPersistUniqueNoInfiniteLoop()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -1759,6 +1671,9 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
new DateInterval('PT10M')
|
new DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException::class);
|
||||||
|
$this->expectExceptionCode(100);
|
||||||
|
|
||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1831,10 +1746,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 7
|
|
||||||
*/
|
|
||||||
public function testRefreshTokenRepositoryFailToPersist()
|
public function testRefreshTokenRepositoryFailToPersist()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -1896,6 +1807,9 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(7);
|
||||||
|
|
||||||
/** @var StubResponseType $response */
|
/** @var StubResponseType $response */
|
||||||
$response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
$response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
||||||
|
|
||||||
@ -1903,10 +1817,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
|
|
||||||
* @expectedExceptionCode 100
|
|
||||||
*/
|
|
||||||
public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop()
|
public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -1968,6 +1878,9 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException::class);
|
||||||
|
$this->expectExceptionCode(100);
|
||||||
|
|
||||||
/** @var StubResponseType $response */
|
/** @var StubResponseType $response */
|
||||||
$response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
$response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M'));
|
||||||
|
|
||||||
@ -1975,9 +1888,6 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testCompleteAuthorizationRequestNoUser()
|
public function testCompleteAuthorizationRequestNoUser()
|
||||||
{
|
{
|
||||||
$grant = new AuthCodeGrant(
|
$grant = new AuthCodeGrant(
|
||||||
@ -1986,6 +1896,8 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
new DateInterval('PT10M')
|
new DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest(new AuthorizationRequest());
|
$grant->completeAuthorizationRequest(new AuthorizationRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2011,20 +1923,11 @@ class AuthCodeGrantTest extends TestCase
|
|||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
[],
|
|
||||||
[],
|
|
||||||
[
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->expectException(OAuthServerException::class);
|
$this->expectException(OAuthServerException::class);
|
||||||
$this->expectExceptionCode(3);
|
$this->expectExceptionCode(3);
|
||||||
|
@ -31,7 +31,7 @@ class ImplicitGrantTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected $cryptStub;
|
protected $cryptStub;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->cryptStub = new CryptTraitStub();
|
$this->cryptStub = new CryptTraitStub();
|
||||||
}
|
}
|
||||||
@ -51,12 +51,12 @@ class ImplicitGrantTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testRespondToAccessTokenRequest()
|
public function testRespondToAccessTokenRequest()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest(
|
$grant->respondToAccessTokenRequest(
|
||||||
new ServerRequest(),
|
new ServerRequest(),
|
||||||
new StubResponseType(),
|
new StubResponseType(),
|
||||||
@ -68,19 +68,10 @@ class ImplicitGrantTest extends TestCase
|
|||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'token',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
]);
|
||||||
null,
|
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'token',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertTrue($grant->canRespondToAuthorizationRequest($request));
|
$this->assertTrue($grant->canRespondToAuthorizationRequest($request));
|
||||||
}
|
}
|
||||||
@ -101,20 +92,11 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
||||||
}
|
}
|
||||||
@ -135,28 +117,15 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
$grant->setDefaultScope(self::DEFAULT_SCOPE);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://foo/bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://foo/bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
$this->assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestMissingClientId()
|
public function testValidateAuthorizationRequestMissingClientId()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -164,26 +133,14 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams(['response_type' => 'code']);
|
||||||
[],
|
|
||||||
[],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
null,
|
$this->expectExceptionCode(3);
|
||||||
null,
|
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestInvalidClientId()
|
public function testValidateAuthorizationRequestInvalidClientId()
|
||||||
{
|
{
|
||||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||||
@ -192,27 +149,17 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
]);
|
||||||
null,
|
|
||||||
'php://input',
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
$headers = [],
|
$this->expectExceptionCode(4);
|
||||||
$cookies = [],
|
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestBadRedirectUriString()
|
public function testValidateAuthorizationRequestBadRedirectUriString()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -223,28 +170,18 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
$cookies = [],
|
$this->expectExceptionCode(4);
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 4
|
|
||||||
*/
|
|
||||||
public function testValidateAuthorizationRequestBadRedirectUriArray()
|
public function testValidateAuthorizationRequestBadRedirectUriArray()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -255,20 +192,14 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = (new ServerRequest())->withQueryParams([
|
||||||
[],
|
'response_type' => 'code',
|
||||||
[],
|
'client_id' => 'foo',
|
||||||
null,
|
'redirect_uri' => 'http://bar',
|
||||||
null,
|
]);
|
||||||
'php://input',
|
|
||||||
$headers = [],
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
$cookies = [],
|
$this->expectExceptionCode(4);
|
||||||
$queryParams = [
|
|
||||||
'response_type' => 'code',
|
|
||||||
'client_id' => 'foo',
|
|
||||||
'redirect_uri' => 'http://bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$grant->validateAuthorizationRequest($request);
|
$grant->validateAuthorizationRequest($request);
|
||||||
}
|
}
|
||||||
@ -302,10 +233,6 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 9
|
|
||||||
*/
|
|
||||||
public function testCompleteAuthorizationRequestDenied()
|
public function testCompleteAuthorizationRequestDenied()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -326,6 +253,9 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(9);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest($authRequest);
|
$grant->completeAuthorizationRequest($authRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,10 +290,6 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
$this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 7
|
|
||||||
*/
|
|
||||||
public function testAccessTokenRepositoryFailToPersist()
|
public function testAccessTokenRepositoryFailToPersist()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -385,13 +311,12 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(7);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest($authRequest);
|
$grant->completeAuthorizationRequest($authRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
|
|
||||||
* @expectedExceptionCode 100
|
|
||||||
*/
|
|
||||||
public function testAccessTokenRepositoryFailToPersistUniqueNoInfiniteLoop()
|
public function testAccessTokenRepositoryFailToPersistUniqueNoInfiniteLoop()
|
||||||
{
|
{
|
||||||
$authRequest = new AuthorizationRequest();
|
$authRequest = new AuthorizationRequest();
|
||||||
@ -413,34 +338,38 @@ class ImplicitGrantTest extends TestCase
|
|||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException::class);
|
||||||
|
$this->expectExceptionCode(100);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest($authRequest);
|
$grant->completeAuthorizationRequest($authRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testSetRefreshTokenTTL()
|
public function testSetRefreshTokenTTL()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grant->setRefreshTokenTTL(new DateInterval('PT10M'));
|
$grant->setRefreshTokenTTL(new DateInterval('PT10M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testSetRefreshTokenRepository()
|
public function testSetRefreshTokenRepository()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
|
|
||||||
$refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
|
$refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testCompleteAuthorizationRequestNoUser()
|
public function testCompleteAuthorizationRequestNoUser()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
$grant = new ImplicitGrant(new DateInterval('PT10M'));
|
||||||
|
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
$grant->completeAuthorizationRequest(new AuthorizationRequest());
|
$grant->completeAuthorizationRequest(new AuthorizationRequest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,9 +127,6 @@ class PasswordGrantTest extends TestCase
|
|||||||
$this->assertNull($responseType->getRefreshToken());
|
$this->assertNull($responseType->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestMissingUsername()
|
public function testRespondToRequestMissingUsername()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -146,21 +143,18 @@ class PasswordGrantTest extends TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withQueryParams([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
]);
|
||||||
'client_secret' => 'bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestMissingPassword()
|
public function testRespondToRequestMissingPassword()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -177,23 +171,19 @@ class PasswordGrantTest extends TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'username' => 'alex',
|
||||||
'client_secret' => 'bar',
|
]);
|
||||||
'username' => 'alex',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 10
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestBadCredentials()
|
public function testRespondToRequestBadCredentials()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -211,17 +201,18 @@ class PasswordGrantTest extends TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'username' => 'alex',
|
||||||
'client_secret' => 'bar',
|
'password' => 'whisky',
|
||||||
'username' => 'alex',
|
]);
|
||||||
'password' => 'whisky',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(10);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected $cryptStub;
|
protected $cryptStub;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->cryptStub = new CryptTraitStub();
|
$this->cryptStub = new CryptTraitStub();
|
||||||
}
|
}
|
||||||
@ -209,10 +209,6 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $responseType->getRefreshToken());
|
$this->assertInstanceOf(RefreshTokenEntityInterface::class, $responseType->getRefreshToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 5
|
|
||||||
*/
|
|
||||||
public function testRespondToUnexpectedScope()
|
public function testRespondToUnexpectedScope()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -251,24 +247,21 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'refresh_token' => $oldRefreshToken,
|
||||||
'client_secret' => 'bar',
|
'scope' => 'foobar',
|
||||||
'refresh_token' => $oldRefreshToken,
|
]);
|
||||||
'scope' => 'foobar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(5);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 3
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestMissingOldToken()
|
public function testRespondToRequestMissingOldToken()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -285,22 +278,19 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
$grant->setEncryptionKey($this->cryptStub->getKey());
|
$grant->setEncryptionKey($this->cryptStub->getKey());
|
||||||
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
|
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
]);
|
||||||
'client_secret' => 'bar',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(3);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 8
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestInvalidOldToken()
|
public function testRespondToRequestInvalidOldToken()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -319,23 +309,20 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
|
|
||||||
$oldRefreshToken = 'foobar';
|
$oldRefreshToken = 'foobar';
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'refresh_token' => $oldRefreshToken,
|
||||||
'client_secret' => 'bar',
|
]);
|
||||||
'refresh_token' => $oldRefreshToken,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(8);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 8
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestClientMismatch()
|
public function testRespondToRequestClientMismatch()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -368,23 +355,20 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'refresh_token' => $oldRefreshToken,
|
||||||
'client_secret' => 'bar',
|
]);
|
||||||
'refresh_token' => $oldRefreshToken,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(8);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 8
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestExpiredToken()
|
public function testRespondToRequestExpiredToken()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -414,23 +398,20 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'refresh_token' => $oldRefreshToken,
|
||||||
'client_secret' => 'bar',
|
]);
|
||||||
'refresh_token' => $oldRefreshToken,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(8);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
* @expectedExceptionCode 8
|
|
||||||
*/
|
|
||||||
public function testRespondToRequestRevokedToken()
|
public function testRespondToRequestRevokedToken()
|
||||||
{
|
{
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
@ -461,16 +442,17 @@ class RefreshTokenGrantTest extends TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = (new ServerRequest())->withParsedBody([
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
'client_id' => 'foo',
|
||||||
[
|
'client_secret' => 'bar',
|
||||||
'client_id' => 'foo',
|
'refresh_token' => $oldRefreshToken,
|
||||||
'client_secret' => 'bar',
|
]);
|
||||||
'refresh_token' => $oldRefreshToken,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$responseType = new StubResponseType();
|
$responseType = new StubResponseType();
|
||||||
|
|
||||||
|
$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
|
||||||
|
$this->expectExceptionCode(8);
|
||||||
|
|
||||||
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class BearerResponseTypeTest extends TestCase
|
|||||||
|
|
||||||
$response->getBody()->rewind();
|
$response->getBody()->rewind();
|
||||||
$json = json_decode($response->getBody()->getContents());
|
$json = json_decode($response->getBody()->getContents());
|
||||||
$this->assertAttributeEquals('Bearer', 'token_type', $json);
|
$this->assertEquals('Bearer', $json->token_type);
|
||||||
$this->assertObjectHasAttribute('expires_in', $json);
|
$this->assertObjectHasAttribute('expires_in', $json);
|
||||||
$this->assertObjectHasAttribute('access_token', $json);
|
$this->assertObjectHasAttribute('access_token', $json);
|
||||||
$this->assertObjectHasAttribute('refresh_token', $json);
|
$this->assertObjectHasAttribute('refresh_token', $json);
|
||||||
@ -100,13 +100,13 @@ class BearerResponseTypeTest extends TestCase
|
|||||||
|
|
||||||
$response->getBody()->rewind();
|
$response->getBody()->rewind();
|
||||||
$json = json_decode($response->getBody()->getContents());
|
$json = json_decode($response->getBody()->getContents());
|
||||||
$this->assertAttributeEquals('Bearer', 'token_type', $json);
|
$this->assertEquals('Bearer', $json->token_type);
|
||||||
$this->assertObjectHasAttribute('expires_in', $json);
|
$this->assertObjectHasAttribute('expires_in', $json);
|
||||||
$this->assertObjectHasAttribute('access_token', $json);
|
$this->assertObjectHasAttribute('access_token', $json);
|
||||||
$this->assertObjectHasAttribute('refresh_token', $json);
|
$this->assertObjectHasAttribute('refresh_token', $json);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('foo', $json);
|
$this->assertObjectHasAttribute('foo', $json);
|
||||||
$this->assertAttributeEquals('bar', 'foo', $json);
|
$this->assertEquals('bar', $json->foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDetermineAccessTokenInHeaderValidToken()
|
public function testDetermineAccessTokenInHeaderValidToken()
|
||||||
|
@ -7,11 +7,10 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class CryptKeyTest extends TestCase
|
class CryptKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testNoFile()
|
public function testNoFile()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\LogicException::class);
|
||||||
|
|
||||||
new CryptKey('undefined file');
|
new CryptKey('undefined file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ class CryptTraitTest extends TestCase
|
|||||||
{
|
{
|
||||||
protected $cryptStub;
|
protected $cryptStub;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->cryptStub = new CryptTraitStub();
|
$this->cryptStub = new CryptTraitStub();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user