mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-25 06:30:13 +05:30
Added tests for resource server middleware
This commit is contained in:
parent
f6f39698d9
commit
7c35778316
@ -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();
|
||||||
|
28
tests/ResourceServerTest.php
Normal file
28
tests/ResourceServerTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user