Added tests for resource server middleware

This commit is contained in:
Alex Bilbie 2016-04-17 12:54:39 +01:00
parent f6f39698d9
commit 7c35778316
2 changed files with 35 additions and 28 deletions

View File

@ -5,12 +5,9 @@ namespace LeagueTests\Middleware;
use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Middleware\ResourceServerMiddleware;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\ResourceServer;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\Server;
use LeagueTests\Stubs\AccessTokenEntity; use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\StubResponseType;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
@ -18,15 +15,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase
{ {
public function testValidResponse() public function testValidResponse()
{ {
$clientRepository = $this->getMock(ClientRepositoryInterface::class); $server = new ResourceServer(
$server = new Server(
$clientRepository,
$this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(AccessTokenRepositoryInterface::class),
$this->getMock(ScopeRepositoryInterface::class), 'file://' . __DIR__ . '/../Stubs/public.key'
'file://' . __DIR__ . '/../Stubs/private.key',
'file://' . __DIR__ . '/../Stubs/public.key',
new StubResponseType()
); );
$client = new ClientEntity(); $client = new ClientEntity();
@ -59,15 +50,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase
public function testValidResponseExpiredToken() public function testValidResponseExpiredToken()
{ {
$clientRepository = $this->getMock(ClientRepositoryInterface::class); $server = new ResourceServer(
$server = new Server(
$clientRepository,
$this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(AccessTokenRepositoryInterface::class),
$this->getMock(ScopeRepositoryInterface::class), 'file://' . __DIR__ . '/../Stubs/public.key'
'file://' . __DIR__ . '/../Stubs/private.key',
'file://' . __DIR__ . '/../Stubs/public.key',
new StubResponseType()
); );
$client = new ClientEntity(); $client = new ClientEntity();
@ -100,15 +85,9 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase
public function testErrorResponse() public function testErrorResponse()
{ {
$clientRepository = $this->getMock(ClientRepositoryInterface::class); $server = new ResourceServer(
$server = new Server(
$clientRepository,
$this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(AccessTokenRepositoryInterface::class),
$this->getMock(ScopeRepositoryInterface::class), 'file://' . __DIR__ . '/../Stubs/public.key'
'file://' . __DIR__ . '/../Stubs/private.key',
'file://' . __DIR__ . '/../Stubs/public.key',
new StubResponseType()
); );
$request = new ServerRequest(); $request = new ServerRequest();

View File

@ -0,0 +1,28 @@
<?php
namespace LeagueTests;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\ResourceServer;
use Zend\Diactoros\ServerRequestFactory;
class ResourceServerTest extends \PHPUnit_Framework_TestCase
{
public function testValidateAuthenticatedRequest()
{
$server = new ResourceServer(
$this->getMock(AccessTokenRepositoryInterface::class),
'file://' . __DIR__ . '/Stubs/public.key'
);
try {
$server->validateAuthenticatedRequest(ServerRequestFactory::fromGlobals());
} catch (OAuthServerException $e) {
$this->assertEquals('Missing "Authorization" header', $e->getHint());
}
}
}