From 47656cd9b5d1b01a22c8ca91ce3626ffe22760e7 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 9 Apr 2016 15:44:38 +0100 Subject: [PATCH] Fix broken tests --- tests/Grant/AbstractGrantTest.php | 16 ++-- tests/Grant/AuthCodeGrantTest.php | 7 +- tests/Grant/ClientCredentialsGrantTest.php | 3 +- tests/Grant/ImplicitGrantTest.php | 4 +- tests/Grant/PasswordGrantTest.php | 8 +- tests/Grant/RefreshTokenGrantTest.php | 12 +-- .../AuthenticationServerMiddlewareTest.php | 2 +- .../ResourceServerMiddlewareTest.php | 2 +- .../ResponseTypes/BearerResponseTypeTest.php | 4 +- tests/ServerTest.php | 4 +- tests/Stubs/AccessTokenEntity.php | 13 ++++ tests/Stubs/AuthCodeEntity.php | 13 ++++ tests/Stubs/ClientEntity.php | 77 +------------------ tests/Stubs/RefreshTokenEntity.php | 12 +++ tests/Stubs/UserEntity.php | 7 +- 15 files changed, 70 insertions(+), 114 deletions(-) create mode 100644 tests/Stubs/AccessTokenEntity.php create mode 100644 tests/Stubs/AuthCodeEntity.php create mode 100644 tests/Stubs/RefreshTokenEntity.php diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index 0fb3fab4..559a5269 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -4,12 +4,9 @@ namespace LeagueTests\Grant; use League\Event\Emitter; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; -use League\OAuth2\Server\Entities\AuthCodeEntity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Grant\AbstractGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; @@ -17,6 +14,9 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use LeagueTests\Stubs\ClientEntity; +use LeagueTests\Stubs\AuthCodeEntity; +use LeagueTests\Stubs\AccessTokenEntity; +use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\ScopeEntity; use Zend\Diactoros\ServerRequest; @@ -60,8 +60,6 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testValidateClientConfidential() { $client = new ClientEntity(); - $client->setSecret('bar'); - $client->setRedirectUri('http://foo/bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -178,8 +176,8 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withParsedBody([ - 'client_id' => 'foo', - 'redirect_uri' => 'http://bar/foo', + 'client_id' => 'foo', + 'redirect_uri' => 'http://bar/foo', ]); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); @@ -206,8 +204,8 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withParsedBody([ - 'client_id' => 'foo', - 'redirect_uri' => 'http://bar/foo', + 'client_id' => 'foo', + 'redirect_uri' => 'http://bar/foo', ]); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 7782f030..b49ecd18 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -3,11 +3,11 @@ namespace LeagueTests\Grant; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; -use League\OAuth2\Server\Entities\AuthCodeEntity; +use LeagueTests\Stubs\AccessTokenEntity; +use LeagueTests\Stubs\AuthCodeEntity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntity; +use LeagueTests\Stubs\RefreshTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -705,7 +705,6 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToAccessTokenRequestMissingCode() { $client = new ClientEntity(); - $client->setSecret('bar'); $client->setRedirectUri('http://foo/bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index 7ce66307..dc883a0e 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -2,7 +2,7 @@ namespace LeagueTests\Grant; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -23,7 +23,6 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToRequest() { $client = new ClientEntity(); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index 09362417..5636de0e 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -3,7 +3,7 @@ namespace LeagueTests\Grant; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ImplicitGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -221,7 +221,7 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase [ 'response_type' => 'token', 'client_id' => 'foo', - 'redirect_uri' => 'sdfsdf', + 'redirect_uri' => 'sdfsdf', ], [ 'username' => 'alex', diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 0368569e..f8827720 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -2,10 +2,10 @@ namespace LeagueTests\Grant; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntity; +use LeagueTests\Stubs\RefreshTokenEntity; use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -31,7 +31,6 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToRequest() { $client = new ClientEntity(); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -78,7 +77,6 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToRequestMissingUsername() { $client = new ClientEntity(); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -110,7 +108,6 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToRequestMissingPassword() { $client = new ClientEntity(); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -143,7 +140,6 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToRequestBadCredentials() { $client = new ClientEntity(); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 6832f8c7..b19dce9c 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -3,10 +3,10 @@ namespace LeagueTests\Grant; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntity; +use LeagueTests\Stubs\RefreshTokenEntity; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -42,7 +42,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -102,7 +101,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -164,7 +162,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -221,7 +218,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -254,7 +250,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -290,7 +285,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -341,7 +335,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); @@ -388,7 +381,6 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { $client = new ClientEntity(); $client->setIdentifier('foo'); - $client->setSecret('bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); diff --git a/tests/Middleware/AuthenticationServerMiddlewareTest.php b/tests/Middleware/AuthenticationServerMiddlewareTest.php index ee3b7007..cbc3cf62 100644 --- a/tests/Middleware/AuthenticationServerMiddlewareTest.php +++ b/tests/Middleware/AuthenticationServerMiddlewareTest.php @@ -2,7 +2,7 @@ namespace LeagueTests\Middleware; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index bb3f7ab7..a3517d1d 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -3,7 +3,7 @@ namespace LeagueTests\Middleware; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; +use LeagueTests\Stubs\AccessTokenEntity; use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index 962cd99b..d6e75fdf 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -4,8 +4,8 @@ namespace LeagueTests\ResponseTypes; use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Entities\AccessTokenEntity; -use League\OAuth2\Server\Entities\RefreshTokenEntity; +use\LeagueTests\Stubs\AccessTokenEntity; +use LeagueTests\Stubs\RefreshTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; diff --git a/tests/ServerTest.php b/tests/ServerTest.php index dd5477d1..ec261b6f 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -2,8 +2,8 @@ namespace LeagueTests; -use League\OAuth2\Server\Entities\AccessTokenEntity; -use League\OAuth2\Server\Entities\AuthCodeEntity; +use LeagueTests\Stubs\AccessTokenEntity; +use LeagueTests\Stubs\AuthCodeEntity; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\ClientCredentialsGrant; diff --git a/tests/Stubs/AccessTokenEntity.php b/tests/Stubs/AccessTokenEntity.php new file mode 100644 index 00000000..77a4d223 --- /dev/null +++ b/tests/Stubs/AccessTokenEntity.php @@ -0,0 +1,13 @@ +name; + $this->redirectUri = $uri; } - /** - * {@inheritdoc} - */ public function setName($name) { $this->name = $name; } - /** - * {@inheritdoc} - */ - public function canKeepASecret() - { - return $this->secret !== null; - } - - /** - * {@inheritdoc} - */ - public function setSecret($secret) - { - $this->secret = password_hash($secret, PASSWORD_DEFAULT); - } - - /** - * {@inheritdoc} - */ - public function validateSecret($submittedSecret) - { - return strcmp((string) $submittedSecret, $this->secret) === 0; - } - - /** - * {@inheritdoc} - */ - public function setRedirectUri($redirectUri) - { - $this->redirectUri = $redirectUri; - } - - /** - * {@inheritdoc} - */ - public function getRedirectUri() - { - return $this->redirectUri; - } - - /** - * Get the hashed client secret - * - * @return string - */ - public function getSecret() - { - return $this->secret; - } } diff --git a/tests/Stubs/RefreshTokenEntity.php b/tests/Stubs/RefreshTokenEntity.php new file mode 100644 index 00000000..f145b706 --- /dev/null +++ b/tests/Stubs/RefreshTokenEntity.php @@ -0,0 +1,12 @@ +setIdentifier(123); } }