From 7c35778316e365c8447a5988730ca312ddfbdfb2 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 17 Apr 2016 12:54:39 +0100 Subject: [PATCH] Added tests for resource server middleware --- .../ResourceServerMiddlewareTest.php | 35 ++++--------------- tests/ResourceServerTest.php | 28 +++++++++++++++ 2 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 tests/ResourceServerTest.php diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index a71dc5ab..e91e9b9b 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -5,12 +5,9 @@ namespace LeagueTests\Middleware; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; -use League\OAuth2\Server\Repositories\ClientRepositoryInterface; -use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; -use League\OAuth2\Server\Server; +use League\OAuth2\Server\ResourceServer; use LeagueTests\Stubs\AccessTokenEntity; use LeagueTests\Stubs\ClientEntity; -use LeagueTests\Stubs\StubResponseType; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; @@ -18,15 +15,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase { public function testValidResponse() { - $clientRepository = $this->getMock(ClientRepositoryInterface::class); - - $server = new Server( - $clientRepository, + $server = new ResourceServer( $this->getMock(AccessTokenRepositoryInterface::class), - $this->getMock(ScopeRepositoryInterface::class), - 'file://' . __DIR__ . '/../Stubs/private.key', - 'file://' . __DIR__ . '/../Stubs/public.key', - new StubResponseType() + 'file://' . __DIR__ . '/../Stubs/public.key' ); $client = new ClientEntity(); @@ -59,15 +50,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase public function testValidResponseExpiredToken() { - $clientRepository = $this->getMock(ClientRepositoryInterface::class); - - $server = new Server( - $clientRepository, + $server = new ResourceServer( $this->getMock(AccessTokenRepositoryInterface::class), - $this->getMock(ScopeRepositoryInterface::class), - 'file://' . __DIR__ . '/../Stubs/private.key', - 'file://' . __DIR__ . '/../Stubs/public.key', - new StubResponseType() + 'file://' . __DIR__ . '/../Stubs/public.key' ); $client = new ClientEntity(); @@ -100,15 +85,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase public function testErrorResponse() { - $clientRepository = $this->getMock(ClientRepositoryInterface::class); - - $server = new Server( - $clientRepository, + $server = new ResourceServer( $this->getMock(AccessTokenRepositoryInterface::class), - $this->getMock(ScopeRepositoryInterface::class), - 'file://' . __DIR__ . '/../Stubs/private.key', - 'file://' . __DIR__ . '/../Stubs/public.key', - new StubResponseType() + 'file://' . __DIR__ . '/../Stubs/public.key' ); $request = new ServerRequest(); diff --git a/tests/ResourceServerTest.php b/tests/ResourceServerTest.php new file mode 100644 index 00000000..12365c47 --- /dev/null +++ b/tests/ResourceServerTest.php @@ -0,0 +1,28 @@ +getMock(AccessTokenRepositoryInterface::class), + 'file://' . __DIR__ . '/Stubs/public.key' + ); + + try { + $server->validateAuthenticatedRequest(ServerRequestFactory::fromGlobals()); + } catch (OAuthServerException $e) { + $this->assertEquals('Missing "Authorization" header', $e->getHint()); + } + } + +}