2014-01-16 22:21:06 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LeagueTests;
|
|
|
|
|
2014-02-24 20:13:00 +05:30
|
|
|
use League\OAuth2\Server\AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
|
|
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
|
|
use \Mockery as M;
|
|
|
|
|
2014-05-03 15:25:25 +05:30
|
|
|
class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
2014-01-16 22:21:06 +05:30
|
|
|
{
|
|
|
|
public function testSetGet()
|
|
|
|
{
|
2014-02-24 20:13:00 +05:30
|
|
|
$server = new AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
$server->requireScopeParam(true);
|
|
|
|
$server->requireStateParam(true);
|
|
|
|
$server->setDefaultScope('foobar');
|
|
|
|
$server->setScopeDelimeter(',');
|
|
|
|
$server->setAccessTokenTTL(1);
|
|
|
|
|
|
|
|
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
|
|
|
|
$grant->shouldReceive('getIdentifier')->andReturn('foobar');
|
|
|
|
$grant->shouldReceive('getResponseType')->andReturn('foobar');
|
|
|
|
$grant->shouldReceive('setAuthorizationServer');
|
|
|
|
|
|
|
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
|
|
|
$scopeStorage->shouldReceive('setServer');
|
|
|
|
|
|
|
|
$server->addGrantType($grant);
|
|
|
|
$server->setScopeStorage($scopeStorage);
|
|
|
|
|
|
|
|
$this->assertTrue($server->hasGrantType('foobar'));
|
|
|
|
$this->assertTrue($server->getGrantType('foobar') instanceof GrantTypeInterface);
|
|
|
|
$this->assertSame($server->getResponseTypes(), ['foobar']);
|
|
|
|
$this->assertTrue($server->scopeParamRequired());
|
|
|
|
$this->assertTrue($server->stateParamRequired());
|
2014-11-07 07:50:06 +05:30
|
|
|
$this->assertTrue($server->getScopeStorage() instanceof ScopeInterface);
|
2014-01-16 22:21:06 +05:30
|
|
|
$this->assertEquals('foobar', $server->getDefaultScope());
|
|
|
|
$this->assertEquals(',', $server->getScopeDelimeter());
|
|
|
|
$this->assertEquals(1, $server->getAccessTokenTTL());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidGrantType()
|
|
|
|
{
|
2014-05-01 19:03:11 +05:30
|
|
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantException');
|
2014-02-24 20:13:00 +05:30
|
|
|
$server = new AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
$server->getGrantType('foobar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueAccessToken()
|
|
|
|
{
|
|
|
|
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
|
|
|
|
$grant->shouldReceive('getIdentifier')->andReturn('foobar');
|
|
|
|
$grant->shouldReceive('getResponseType')->andReturn('foobar');
|
|
|
|
$grant->shouldReceive('setAuthorizationServer');
|
|
|
|
$grant->shouldReceive('completeFlow')->andReturn(true);
|
|
|
|
|
|
|
|
$_POST['grant_type'] = 'foobar';
|
|
|
|
|
2014-02-24 20:13:00 +05:30
|
|
|
$server = new AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
$server->addGrantType($grant);
|
|
|
|
|
|
|
|
$this->assertTrue($server->issueAccessToken());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueAccessTokenEmptyGrantType()
|
|
|
|
{
|
2014-05-01 19:03:11 +05:30
|
|
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
2014-02-24 20:13:00 +05:30
|
|
|
$server = new AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
$this->assertTrue($server->issueAccessToken());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueAccessTokenInvalidGrantType()
|
|
|
|
{
|
2014-05-01 19:03:11 +05:30
|
|
|
$this->setExpectedException('League\OAuth2\Server\Exception\UnsupportedGrantTypeException');
|
2014-01-16 22:21:06 +05:30
|
|
|
|
|
|
|
$_POST['grant_type'] = 'foobar';
|
|
|
|
|
2014-02-24 20:13:00 +05:30
|
|
|
$server = new AuthorizationServer;
|
2014-01-16 22:21:06 +05:30
|
|
|
$this->assertTrue($server->issueAccessToken());
|
|
|
|
}
|
|
|
|
}
|