Merge branch 'v4.0.0-relational-example' of github.com:thephpleague/oauth2-server into v4.0.0-relational-example

This commit is contained in:
Alex Bilbie
2014-07-28 13:54:46 +01:00
24 changed files with 2420 additions and 50 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace Codeception\Module;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class AuthHelper extends \Codeception\Module
{
function seeJsonKeyExists($key)
{
$json = $this->getModule('REST')->grabResponse();
$array = json_decode($json);
$this->assertTrue(array_key_exists($key, $array));
}
function seeJsonKeyDoesNotExists($key)
{
$json = $this->getModule('REST')->grabResponse();
$array = json_decode($json);
$this->assertFalse(array_key_exists($key, $array));
}
}

8
tests/auth.suite.yml Normal file
View File

@@ -0,0 +1,8 @@
class_name: AuthTester
modules:
enabled: [PhpBrowser, REST, AuthHelper]
config:
PhpBrowser:
url: http://localhost:8000/
REST:
url: http://localhost:8000/

View File

@@ -0,0 +1,24 @@
<?php
$I = new AuthTester($scenario);
$I->wantTo('get an access token with an authorization code');
$I->sendGET('authcode_grant.php/authorize?client_id=testclient&redirect_uri=http%3A%2F%2Fexample.com%2Fredirect&response_type=code&scope=basic');
$I->seeResponseCodeIs(200);
$I->seeHttpHeader('Location');
$location = $I->grabHttpHeader('Location');
$urlParts = parse_url($location);
parse_str($urlParts['query'], $queryString);
$I->sendPOST('authcode_grant.php/access_token', [
'client_id' => 'testclient',
'redirect_uri' => 'http://example.com/redirect',
'client_secret' => 'secret',
'code' => $queryString['code'],
'grant_type' => 'authorization_code'
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeJsonKeyExists('expires_in');
$I->seeJsonKeyExists('access_token');
$I->seeResponseContainsJson(['token_type' => 'Bearer']);
$I->seeJsonKeyDoesNotExists('foobar');

2162
tests/auth/AuthTester.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
<?php
$I = new AuthTester($scenario);
$I->wantTo('get an access token with client credentials');
$I->sendPOST('other_grants.php/access_token', [
'client_id' => 'testclient',
'client_secret' => 'secret',
'grant_type' => 'client_credentials'
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeJsonKeyExists('expires_in');
$I->seeJsonKeyExists('access_token');
$I->seeResponseContainsJson(['token_type' => 'Bearer']);
$I->seeJsonKeyDoesNotExists('foobar');

View File

@@ -0,0 +1,11 @@
<?php
$I = new AuthTester($scenario);
$I->wantTo('get an access token with resource owner credentials');
$I->sendPOST('other_grants.php/access_token', [
'client_id' => 'testclient',
'client_secret' => 'secret',
'grant_type' => 'password',
'username' => 'alexbilbie'
]);
$I->seeResponseCodeIs(400);
$I->seeResponseIsJson();

View File

@@ -0,0 +1,15 @@
<?php
$I = new AuthTester($scenario);
$I->wantTo('get an access token with resource owner credentials');
$I->sendPOST('other_grants.php/access_token', [
'client_id' => 'testclient',
'client_secret' => 'secret',
'grant_type' => 'password'
]);
$I->seeResponseCodeIs(400);
$I->seeResponseIsJson();
$I->seeResponseContainsJson([
'error' => 'invalid_request',
'message' => 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter
more than once, or is otherwise malformed. Check the "username" parameter.'
]);

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

@@ -402,7 +402,6 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(array_key_exists('access_token', $response));
$this->assertTrue(array_key_exists('token_type', $response));
$this->assertTrue(array_key_exists('expires_in', $response));
$this->assertTrue(array_key_exists('expires', $response));
}
public function testCompleteFlowRefreshToken()
@@ -470,6 +469,5 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
// $this->assertTrue(array_key_exists('refresh_token', $response));
$this->assertTrue(array_key_exists('token_type', $response));
$this->assertTrue(array_key_exists('expires_in', $response));
$this->assertTrue(array_key_exists('expires', $response));
}
}

View File

@@ -11,7 +11,7 @@ use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\AuthorizationServer;
use Mockery as M;
class RefreshTokenGreantTest extends \PHPUnit_Framework_TestCase
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
{
public function testSetRefreshTokenTTL()
{
@@ -212,7 +212,6 @@ class RefreshTokenGreantTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(array_key_exists('refresh_token', $response));
$this->assertTrue(array_key_exists('token_type', $response));
$this->assertTrue(array_key_exists('expires_in', $response));
$this->assertTrue(array_key_exists('expires', $response));
}
public function testCompleteFlowRequestScopes()
@@ -284,7 +283,6 @@ class RefreshTokenGreantTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(isset($response['refresh_token']));
$this->assertTrue(isset($response['token_type']));
$this->assertTrue(isset($response['expires_in']));
$this->assertTrue(isset($response['expires']));
}
public function testCompleteFlowRequestScopesInvalid()