From 4c1cd04a2442b93cbf10771fb8665fad11c9e93c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 8 Nov 2014 18:26:12 +0000 Subject: [PATCH] CS fixes --- .../relational/Storage/AccessTokenStorage.php | 16 +- .../relational/Storage/AuthCodeStorage.php | 14 +- examples/relational/Storage/ClientStorage.php | 11 +- .../Storage/RefreshTokenStorage.php | 10 +- examples/relational/Storage/ScopeStorage.php | 9 +- .../relational/Storage/SessionStorage.php | 15 +- examples/relational/api.php | 44 ++---- examples/relational/authcode_grant.php | 62 +++----- examples/relational/config/db.php | 4 +- examples/relational/config/init.php | 36 ++--- examples/relational/other_grants.php | 57 +++---- src/AbstractServer.php | 19 ++- src/AuthorizationServer.php | 8 +- src/Entity/AbstractTokenEntity.php | 5 +- src/Entity/AuthCodeEntity.php | 2 +- src/Entity/EntityTrait.php | 2 +- src/Grant/AbstractGrant.php | 12 +- src/Grant/AuthCodeGrant.php | 12 +- src/Grant/ClientCredentialsGrant.php | 8 +- src/Grant/PasswordGrant.php | 8 +- src/Grant/RefreshTokenGrant.php | 8 +- src/ResourceServer.php | 15 +- src/Storage/AccessTokenInterface.php | 3 +- src/Storage/SessionInterface.php | 2 +- src/TokenType/AbstractTokenType.php | 4 +- src/TokenType/Bearer.php | 2 +- src/Util/KeyAlgorithm/DefaultAlgorithm.php | 2 +- src/Util/RedirectUri.php | 2 +- tests/fuzz/grant-authcode.yml | 2 +- tests/fuzz/grant-client-credentials.yml | 2 +- tests/fuzz/grant-password.yml | 2 +- tests/fuzz/tokeninfo-no-access-token.yml | 2 +- ...okeninfo-no-invalid-token-query-string.yml | 2 +- tests/fuzz/tokeninfo-no-invalid-token.yml | 2 +- tests/fuzz/tokeninfo-valid-token-header.yml | 2 +- tests/fuzz/tokeninfo-valid-token.yml | 2 +- tests/fuzz/users-token-iamalex.yml | 2 +- tests/fuzz/users-token-iamphil.yml | 2 +- tests/unit/AbstractServerTest.php | 6 +- tests/unit/AuthorizationServerTest.php | 12 +- tests/unit/Bootstrap.php | 2 +- tests/unit/Entity/AbstractTokenEntityTest.php | 10 +- tests/unit/Entity/AccessTokenEntityTest.php | 8 +- tests/unit/Entity/AuthCodeEntityTest.php | 10 +- tests/unit/Entity/ClientEntityTest.php | 6 +- tests/unit/Entity/RefreshTokenEntityTest.php | 8 +- tests/unit/Entity/ScopeEntityTest.php | 6 +- tests/unit/Entity/SessionEntityTest.php | 12 +- tests/unit/Exception/OAuthExceptionTest.php | 6 +- tests/unit/Grant/AbstractGrantTest.php | 40 ++--- tests/unit/Grant/AuthCodeGrantTest.php | 142 +++++++++--------- .../unit/Grant/ClientCredentialsGrantTest.php | 53 ++++--- tests/unit/Grant/PasswordGrantTest.php | 87 ++++++----- tests/unit/Grant/RefreshTokenGrantTest.php | 64 ++++---- tests/unit/ResourceServerTest.php | 20 +-- tests/unit/Storage/AbstractStorageTest.php | 8 +- tests/unit/Stubs/StubAbstractServer.php | 2 +- tests/unit/Stubs/StubAbstractStorage.php | 2 +- tests/unit/Stubs/StubAbstractTokenEntity.php | 6 +- tests/unit/util/RedirectUriTest.php | 6 +- tests/unit/util/SecureKeyTest.php | 5 +- 61 files changed, 430 insertions(+), 503 deletions(-) diff --git a/examples/relational/Storage/AccessTokenStorage.php b/examples/relational/Storage/AccessTokenStorage.php index 55949314..7d0c37e7 100644 --- a/examples/relational/Storage/AccessTokenStorage.php +++ b/examples/relational/Storage/AccessTokenStorage.php @@ -2,14 +2,12 @@ namespace RelationalExample\Storage; +use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Entity\AbstractTokenEntity; +use League\OAuth2\Server\Entity\AccessTokenEntity; +use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Storage\AccessTokenInterface; use League\OAuth2\Server\Storage\Adapter; -use League\OAuth2\Server\Entity\AccessTokenEntity; -use League\OAuth2\Server\Entity\AbstractTokenEntity; -use League\OAuth2\Server\Entity\RefreshTokenEntity; -use League\OAuth2\Server\Entity\ScopeEntity; - -use Illuminate\Database\Capsule\Manager as Capsule; class AccessTokenStorage extends Adapter implements AccessTokenInterface { @@ -50,7 +48,7 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface foreach ($result as $row) { $scope = (new ScopeEntity($this->server))->hydrate([ 'id' => $row['id'], - 'description' => $row['description'] + 'description' => $row['description'], ]); $response[] = $scope; } @@ -68,7 +66,7 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface ->insert([ 'access_token' => $token, 'session_id' => $sessionId, - 'expire_time' => $expireTime + 'expire_time' => $expireTime, ]); } @@ -80,7 +78,7 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface Capsule::table('oauth_access_token_scopes') ->insert([ 'access_token' => $token->getId(), - 'scope' => $scope->getId() + 'scope' => $scope->getId(), ]); } diff --git a/examples/relational/Storage/AuthCodeStorage.php b/examples/relational/Storage/AuthCodeStorage.php index 5a840237..106f9010 100644 --- a/examples/relational/Storage/AuthCodeStorage.php +++ b/examples/relational/Storage/AuthCodeStorage.php @@ -2,12 +2,11 @@ namespace RelationalExample\Storage; -use League\OAuth2\Server\Storage\AuthCodeInterface; -use League\OAuth2\Server\Storage\Adapter; +use Illuminate\Database\Capsule\Manager as Capsule; use League\OAuth2\Server\Entity\AuthCodeEntity; use League\OAuth2\Server\Entity\ScopeEntity; - -use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Storage\Adapter; +use League\OAuth2\Server\Storage\AuthCodeInterface; class AuthCodeStorage extends Adapter implements AuthCodeInterface { @@ -25,6 +24,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface $token = new AuthCodeEntity($this->server); $token->setId($result[0]['auth_code']); $token->setRedirectUri($result[0]['client_redirect_uri']); + return $token; } @@ -38,7 +38,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface 'auth_code' => $token, 'client_redirect_uri' => $redirectUri, 'session_id' => $sessionId, - 'expire_time' => $expireTime + 'expire_time' => $expireTime, ]); } @@ -59,7 +59,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface foreach ($result as $row) { $scope = (new ScopeEntity($this->server))->hydrate([ 'id' => $row['id'], - 'description' => $row['description'] + 'description' => $row['description'], ]); $response[] = $scope; } @@ -76,7 +76,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface Capsule::table('oauth_auth_code_scopes') ->insert([ 'auth_code' => $token->getId(), - 'scope' => $scope->getId() + 'scope' => $scope->getId(), ]); } diff --git a/examples/relational/Storage/ClientStorage.php b/examples/relational/Storage/ClientStorage.php index 8db0e0c0..99e851aa 100644 --- a/examples/relational/Storage/ClientStorage.php +++ b/examples/relational/Storage/ClientStorage.php @@ -2,12 +2,11 @@ namespace RelationalExample\Storage; -use League\OAuth2\Server\Storage\ClientInterface; -use League\OAuth2\Server\Storage\Adapter; +use Illuminate\Database\Capsule\Manager as Capsule; use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\SessionEntity; - -use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Storage\Adapter; +use League\OAuth2\Server\Storage\ClientInterface; class ClientStorage extends Adapter implements ClientInterface { @@ -36,7 +35,7 @@ class ClientStorage extends Adapter implements ClientInterface $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], - 'name' => $result[0]['name'] + 'name' => $result[0]['name'], ]); return $client; @@ -60,7 +59,7 @@ class ClientStorage extends Adapter implements ClientInterface $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], - 'name' => $result[0]['name'] + 'name' => $result[0]['name'], ]); return $client; diff --git a/examples/relational/Storage/RefreshTokenStorage.php b/examples/relational/Storage/RefreshTokenStorage.php index 92c52647..11afa391 100644 --- a/examples/relational/Storage/RefreshTokenStorage.php +++ b/examples/relational/Storage/RefreshTokenStorage.php @@ -2,11 +2,10 @@ namespace RelationalExample\Storage; -use League\OAuth2\Server\Storage\RefreshTokenInterface; -use League\OAuth2\Server\Storage\Adapter; -use League\OAuth2\Server\Entity\RefreshTokenEntity; - use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Entity\RefreshTokenEntity; +use League\OAuth2\Server\Storage\Adapter; +use League\OAuth2\Server\Storage\RefreshTokenInterface; class RefreshTokenStorage extends Adapter implements RefreshTokenInterface { @@ -40,7 +39,7 @@ class RefreshTokenStorage extends Adapter implements RefreshTokenInterface ->insert([ 'refresh_token' => $token, 'access_token' => $accessToken, - 'expire_time' => $expireTime + 'expire_time' => $expireTime, ]); } @@ -53,5 +52,4 @@ class RefreshTokenStorage extends Adapter implements RefreshTokenInterface ->where('refresh_token', $token->getId()) ->delete(); } - } diff --git a/examples/relational/Storage/ScopeStorage.php b/examples/relational/Storage/ScopeStorage.php index 9b50ae28..fc2988b3 100644 --- a/examples/relational/Storage/ScopeStorage.php +++ b/examples/relational/Storage/ScopeStorage.php @@ -2,11 +2,10 @@ namespace RelationalExample\Storage; -use League\OAuth2\Server\Storage\ScopeInterface; -use League\OAuth2\Server\Storage\Adapter; -use League\OAuth2\Server\Entity\ScopeEntity; - use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Storage\Adapter; +use League\OAuth2\Server\Storage\ScopeInterface; class ScopeStorage extends Adapter implements ScopeInterface { @@ -25,7 +24,7 @@ class ScopeStorage extends Adapter implements ScopeInterface return (new ScopeEntity($this->server))->hydrate([ 'id' => $result[0]['id'], - 'description' => $result[0]['description'] + 'description' => $result[0]['description'], ]); } } diff --git a/examples/relational/Storage/SessionStorage.php b/examples/relational/Storage/SessionStorage.php index 37e1759a..35935ec1 100644 --- a/examples/relational/Storage/SessionStorage.php +++ b/examples/relational/Storage/SessionStorage.php @@ -2,14 +2,13 @@ namespace RelationalExample\Storage; -use League\OAuth2\Server\Storage\SessionInterface; -use League\OAuth2\Server\Storage\Adapter; +use Illuminate\Database\Capsule\Manager as Capsule; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\AuthCodeEntity; -use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\ScopeEntity; - -use Illuminate\Database\Capsule\Manager as Capsule; +use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Storage\Adapter; +use League\OAuth2\Server\Storage\SessionInterface; class SessionStorage extends Adapter implements SessionInterface { @@ -74,7 +73,7 @@ class SessionStorage extends Adapter implements SessionInterface foreach ($result as $scope) { $scopes[] = (new ScopeEntity($this->server))->hydrate([ 'id' => $scope['id'], - 'description' => $scope['description'] + 'description' => $scope['description'], ]); } @@ -90,7 +89,7 @@ class SessionStorage extends Adapter implements SessionInterface ->insertGetId([ 'owner_type' => $ownerType, 'owner_id' => $ownerId, - 'client_id' => $clientId + 'client_id' => $clientId, ]); return $id; @@ -104,7 +103,7 @@ class SessionStorage extends Adapter implements SessionInterface Capsule::table('oauth_session_scopes') ->insert([ 'session_id' => $session->getId(), - 'scope' => $scope->getId() + 'scope' => $scope->getId(), ]); } } diff --git a/examples/relational/api.php b/examples/relational/api.php index 5b62898a..fededdf8 100644 --- a/examples/relational/api.php +++ b/examples/relational/api.php @@ -1,19 +1,17 @@ createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); $router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY); // Set up the OAuth 2.0 resource server @@ -30,8 +28,8 @@ $server = new ResourceServer( ); // Routing setup -$request = (new Request)->createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); // GET /tokeninfo $router->get('/tokeninfo', function (Request $request) use ($server) { @@ -41,7 +39,7 @@ $router->get('/tokeninfo', function (Request $request) use ($server) { 'owner_type' => $server->getOwnerType(), 'access_token' => $server->getAccessToken(), 'client_id' => $server->getClientId(), - 'scopes' => $server->getScopes() + 'scopes' => $server->getScopes(), ]; return new Response(json_encode($token)); @@ -58,7 +56,7 @@ $router->get('/users', function (Request $request) use ($server) { foreach ($results as $result) { $user = [ 'username' => $result['username'], - 'name' => $result['name'] + 'name' => $result['name'], ]; if ($server->hasScope('email')) { @@ -86,7 +84,7 @@ $router->get('/users/{username}', function (Request $request, $args) use ($serve $user = [ 'username' => $result[0]['username'], - 'name' => $result[0]['name'] + 'name' => $result[0]['name'], ]; if ($server->hasScope('email')) { @@ -103,7 +101,6 @@ $router->get('/users/{username}', function (Request $request, $args) use ($serve $dispatcher = $router->getDispatcher(); try { - // Check that access token is present $server->isValidRequest(false); @@ -112,34 +109,25 @@ try { $request->getMethod(), $request->getPathInfo() ); - } catch (\Orno\Http\Exception $e) { - // A failed response $response = $e->getJsonResponse(); $response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()])); - } catch (\League\OAuth2\Server\Exception\OAuthException $e) { - $response = new Response(json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode); foreach ($e->getHttpHeaders() as $header) { $response->headers($header); } - } catch (\Exception $e) { - - $response = new Orno\Http\Response; + $response = new Orno\Http\Response(); $response->setStatusCode(500); $response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()])); - } finally { - // Return the response $response->headers->set('Content-type', 'application/json'); $response->send(); - } diff --git a/examples/relational/authcode_grant.php b/examples/relational/authcode_grant.php index 51774676..380025e6 100644 --- a/examples/relational/authcode_grant.php +++ b/examples/relational/authcode_grant.php @@ -1,29 +1,24 @@ createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); $router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY); // Set up the OAuth 2.0 authorization server -$server = new \League\OAuth2\Server\AuthorizationServer; -$server->setSessionStorage(new Storage\SessionStorage); -$server->setAccessTokenStorage(new Storage\AccessTokenStorage); -$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage); -$server->setClientStorage(new Storage\ClientStorage); -$server->setScopeStorage(new Storage\ScopeStorage); -$server->setAuthCodeStorage(new Storage\AuthCodeStorage); +$server = new \League\OAuth2\Server\AuthorizationServer(); +$server->setSessionStorage(new Storage\SessionStorage()); +$server->setAccessTokenStorage(new Storage\AccessTokenStorage()); +$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage()); +$server->setClientStorage(new Storage\ClientStorage()); +$server->setScopeStorage(new Storage\ScopeStorage()); +$server->setAuthCodeStorage(new Storage\AuthCodeStorage()); $authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant(); $server->addGrantType($authCodeGrant); @@ -32,28 +27,24 @@ $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); $server->addGrantType($refrehTokenGrant); // Routing setup -$request = (new Request)->createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); $router->get('/authorize', function (Request $request) use ($server) { // First ensure the parameters in the query string are correct try { - $authParams = $server->getGrantType('authorization_code')->checkAuthorizeParams(); - } catch (\Exception $e) { - return new Response( json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode, $e->getHttpHeaders() ); - } // Normally at this point you would show the user a sign-in screen and ask them to authorize the requested scopes @@ -78,21 +69,18 @@ $router->get('/authorize', function (Request $request) use ($server) { $router->post('/access_token', function (Request $request) use ($server) { try { - $response = $server->issueAccessToken(); + return new Response(json_encode($response), 200); - } catch (\Exception $e) { - return new Response( json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode, $e->getHttpHeaders() ); - } }); @@ -100,40 +88,30 @@ $router->post('/access_token', function (Request $request) use ($server) { $dispatcher = $router->getDispatcher(); try { - // A successful response $response = $dispatcher->dispatch( $request->getMethod(), $request->getPathInfo() ); - } catch (\Orno\Http\Exception $e) { - // A failed response $response = $e->getJsonResponse(); $response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()])); - } catch (\League\OAuth2\Server\Exception\OAuthException $e) { - $response = new Response(json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode); foreach ($e->getHttpHeaders() as $header) { $response->headers($header); } - } catch (\Exception $e) { - - $response = new Orno\Http\Response; + $response = new Orno\Http\Response(); $response->setStatusCode(500); $response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()])); - } finally { - // Return the response $response->headers->set('Content-type', 'application/json'); $response->send(); - } diff --git a/examples/relational/config/db.php b/examples/relational/config/db.php index 80eaf687..de883979 100644 --- a/examples/relational/config/db.php +++ b/examples/relational/config/db.php @@ -6,13 +6,13 @@ use Illuminate\Database\Capsule\Manager as Capsule; include __DIR__.'/../vendor/autoload.php'; -$capsule = new Capsule; +$capsule = new Capsule(); $capsule->addConnection([ 'driver' => 'sqlite', 'database' => __DIR__.'/oauth2.sqlite3', 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci' + 'collation' => 'utf8_unicode_ci', ]); $capsule->setAsGlobal(); diff --git a/examples/relational/config/init.php b/examples/relational/config/init.php index 1f6a5b8f..1c07630f 100644 --- a/examples/relational/config/init.php +++ b/examples/relational/config/init.php @@ -29,7 +29,7 @@ Capsule::table('users')->insert([ 'password' => password_hash('whisky', PASSWORD_DEFAULT), 'name' => 'Alex Bilbie', 'email' => 'hello@alexbilbie.com', - 'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3' + 'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3', ]); Capsule::table('users')->insert([ @@ -37,7 +37,7 @@ Capsule::table('users')->insert([ 'password' => password_hash('cider', PASSWORD_DEFAULT), 'name' => 'Phil Sturgeon', 'email' => 'email@philsturgeon.co.uk', - 'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951' + 'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951', ]); /******************************************************************************/ @@ -54,7 +54,7 @@ Capsule::schema()->create('oauth_clients', function ($table) { Capsule::table('oauth_clients')->insert([ 'id' => 'testclient', 'secret' => 'secret', - 'name' => 'Test Client' + 'name' => 'Test Client', ]); /******************************************************************************/ @@ -69,7 +69,7 @@ Capsule::schema()->create('oauth_client_redirect_uris', function ($table) { Capsule::table('oauth_client_redirect_uris')->insert([ 'client_id' => 'testclient', - 'redirect_uri' => 'http://example.com/redirect' + 'redirect_uri' => 'http://example.com/redirect', ]); /******************************************************************************/ @@ -84,17 +84,17 @@ Capsule::schema()->create('oauth_scopes', function ($table) { Capsule::table('oauth_scopes')->insert([ 'id' => 'basic', - 'description' => 'Basic details about your account' + 'description' => 'Basic details about your account', ]); Capsule::table('oauth_scopes')->insert([ 'id' => 'email', - 'description' => 'Your email address' + 'description' => 'Your email address', ]); Capsule::table('oauth_scopes')->insert([ 'id' => 'photo', - 'description' => 'Your photo' + 'description' => 'Your photo', ]); /******************************************************************************/ @@ -114,19 +114,19 @@ Capsule::schema()->create('oauth_sessions', function ($table) { Capsule::table('oauth_sessions')->insert([ 'owner_type' => 'client', 'owner_id' => 'testclient', - 'client_id' => 'testclient' + 'client_id' => 'testclient', ]); Capsule::table('oauth_sessions')->insert([ 'owner_type' => 'user', 'owner_id' => '1', - 'client_id' => 'testclient' + 'client_id' => 'testclient', ]); Capsule::table('oauth_sessions')->insert([ 'owner_type' => 'user', 'owner_id' => '2', - 'client_id' => 'testclient' + 'client_id' => 'testclient', ]); /******************************************************************************/ @@ -144,19 +144,19 @@ Capsule::schema()->create('oauth_access_tokens', function ($table) { Capsule::table('oauth_access_tokens')->insert([ 'access_token' => 'iamgod', 'session_id' => '1', - 'expire_time' => time() + 86400 + 'expire_time' => time() + 86400, ]); Capsule::table('oauth_access_tokens')->insert([ 'access_token' => 'iamalex', 'session_id' => '2', - 'expire_time' => time() + 86400 + 'expire_time' => time() + 86400, ]); Capsule::table('oauth_access_tokens')->insert([ 'access_token' => 'iamphil', 'session_id' => '3', - 'expire_time' => time() + 86400 + 'expire_time' => time() + 86400, ]); /******************************************************************************/ @@ -199,27 +199,27 @@ Capsule::schema()->create('oauth_access_token_scopes', function ($table) { Capsule::table('oauth_access_token_scopes')->insert([ 'access_token' => 'iamgod', - 'scope' => 'basic' + 'scope' => 'basic', ]); Capsule::table('oauth_access_token_scopes')->insert([ 'access_token' => 'iamgod', - 'scope' => 'email' + 'scope' => 'email', ]); Capsule::table('oauth_access_token_scopes')->insert([ 'access_token' => 'iamgod', - 'scope' => 'photo' + 'scope' => 'photo', ]); Capsule::table('oauth_access_token_scopes')->insert([ 'access_token' => 'iamphil', - 'scope' => 'email' + 'scope' => 'email', ]); Capsule::table('oauth_access_token_scopes')->insert([ 'access_token' => 'iamalex', - 'scope' => 'photo' + 'scope' => 'photo', ]); /******************************************************************************/ diff --git a/examples/relational/other_grants.php b/examples/relational/other_grants.php index a1c8c442..a59d201e 100644 --- a/examples/relational/other_grants.php +++ b/examples/relational/other_grants.php @@ -1,29 +1,25 @@ createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); $router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY); // Set up the OAuth 2.0 authorization server -$server = new \League\OAuth2\Server\AuthorizationServer; -$server->setSessionStorage(new Storage\SessionStorage); -$server->setAccessTokenStorage(new Storage\AccessTokenStorage); -$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage); -$server->setClientStorage(new Storage\ClientStorage); -$server->setScopeStorage(new Storage\ScopeStorage); -$server->setAuthCodeStorage(new Storage\AuthCodeStorage); +$server = new \League\OAuth2\Server\AuthorizationServer(); +$server->setSessionStorage(new Storage\SessionStorage()); +$server->setAccessTokenStorage(new Storage\AccessTokenStorage()); +$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage()); +$server->setClientStorage(new Storage\ClientStorage()); +$server->setScopeStorage(new Storage\ScopeStorage()); +$server->setAuthCodeStorage(new Storage\AuthCodeStorage()); $clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant(); $server->addGrantType($clientCredentials); @@ -47,27 +43,24 @@ $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); $server->addGrantType($refrehTokenGrant); // Routing setup -$request = (new Request)->createFromGlobals(); -$router = new \Orno\Route\RouteCollection; +$request = (new Request())->createFromGlobals(); +$router = new \Orno\Route\RouteCollection(); $router->post('/access_token', function (Request $request) use ($server) { try { - $response = $server->issueAccessToken(); + return new Response(json_encode($response), 200); - } catch (\Exception $e) { - return new Response( json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode, $e->getHttpHeaders() ); - } }); @@ -75,40 +68,30 @@ $router->post('/access_token', function (Request $request) use ($server) { $dispatcher = $router->getDispatcher(); try { - // A successful response $response = $dispatcher->dispatch( $request->getMethod(), $request->getPathInfo() ); - } catch (\Orno\Http\Exception $e) { - // A failed response $response = $e->getJsonResponse(); $response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()])); - } catch (\League\OAuth2\Server\Exception\OAuthException $e) { - $response = new Response(json_encode([ 'error' => $e->errorType, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]), $e->httpStatusCode); foreach ($e->getHttpHeaders() as $header) { $response->headers($header); } - } catch (\Exception $e) { - - $response = new Orno\Http\Response; + $response = new Orno\Http\Response(); $response->setStatusCode(500); $response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()])); - } finally { - // Return the response $response->headers->set('Content-type', 'application/json'); $response->send(); - } diff --git a/src/AbstractServer.php b/src/AbstractServer.php index 5167584a..220fffc4 100644 --- a/src/AbstractServer.php +++ b/src/AbstractServer.php @@ -11,16 +11,15 @@ namespace League\OAuth2\Server; -use League\OAuth2\Server\Exception; -use League\OAuth2\Server\TokenType\TokenTypeInterface; -use League\OAuth2\Server\Storage\SessionInterface; -use League\OAuth2\Server\Storage\AccessTokenInterface; -use League\OAuth2\Server\Storage\RefreshTokenInterface; -use League\OAuth2\Server\Storage\AuthCodeInterface; -use League\OAuth2\Server\Storage\ScopeInterface; -use League\OAuth2\Server\Storage\ClientInterface; -use Symfony\Component\HttpFoundation\Request; use League\Event\Emitter; +use League\OAuth2\Server\Storage\AccessTokenInterface; +use League\OAuth2\Server\Storage\AuthCodeInterface; +use League\OAuth2\Server\Storage\ClientInterface; +use League\OAuth2\Server\Storage\RefreshTokenInterface; +use League\OAuth2\Server\Storage\ScopeInterface; +use League\OAuth2\Server\Storage\SessionInterface; +use League\OAuth2\Server\TokenType\TokenTypeInterface; +use Symfony\Component\HttpFoundation\Request; /** * OAuth 2.0 Resource Server @@ -98,7 +97,7 @@ abstract class AbstractServer public function setEventEmitter($emitter = null) { if ($emitter === null) { - $this->eventEmitter = new Emitter; + $this->eventEmitter = new Emitter(); } else { $this->eventEmitter = $emitter; } diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index bd1445ff..645df543 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -12,12 +12,6 @@ namespace League\OAuth2\Server; use League\OAuth2\Server\Grant\GrantTypeInterface; -use League\OAuth2\Server\Storage\ClientInterface; -use League\OAuth2\Server\Storage\AccessTokenInterface; -use League\OAuth2\Server\Storage\AuthCodeInterface; -use League\OAuth2\Server\Storage\RefreshTokenInterface; -use League\OAuth2\Server\Storage\SessionInterface; -use League\OAuth2\Server\Storage\ScopeInterface; use League\OAuth2\Server\TokenType\Bearer; use Symfony\Component\HttpFoundation\Request; @@ -76,7 +70,7 @@ class AuthorizationServer extends AbstractServer public function __construct() { // Set Bearer as the default token type - $this->setTokenType(new Bearer); + $this->setTokenType(new Bearer()); parent::__construct(); diff --git a/src/Entity/AbstractTokenEntity.php b/src/Entity/AbstractTokenEntity.php index 5eeb775f..37ed0951 100644 --- a/src/Entity/AbstractTokenEntity.php +++ b/src/Entity/AbstractTokenEntity.php @@ -11,10 +11,8 @@ namespace League\OAuth2\Server\Entity; -use League\OAuth2\Server\Util\SecureKey; use League\OAuth2\Server\AbstractServer; -use Symfony\Component\HttpFoundation\ParameterBag; -use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Util\SecureKey; /** * Abstract token class @@ -170,6 +168,7 @@ abstract class AbstractTokenEntity if ($this->id === null) { return ''; } + return $this->id; } diff --git a/src/Entity/AuthCodeEntity.php b/src/Entity/AuthCodeEntity.php index 75b4dea7..52f87316 100644 --- a/src/Entity/AuthCodeEntity.php +++ b/src/Entity/AuthCodeEntity.php @@ -56,7 +56,7 @@ class AuthCodeEntity extends AbstractTokenEntity return $uri.http_build_query([ 'code' => $this->getId(), - 'state' => $state + 'state' => $state, ]); } diff --git a/src/Entity/EntityTrait.php b/src/Entity/EntityTrait.php index 80d6138f..a71f3bc5 100644 --- a/src/Entity/EntityTrait.php +++ b/src/Entity/EntityTrait.php @@ -15,7 +15,7 @@ trait EntityTrait { /** * Hydrate an entity with properites - * @param array $properties + * @param array $properties */ public function hydrate(array $properties) { diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 2609fda6..4ec2b6ed 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -12,8 +12,8 @@ namespace League\OAuth2\Server\Grant; use League\OAuth2\Server\AuthorizationServer; -use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Exception; /** @@ -108,7 +108,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * Inject the authorization server into the grant - * @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance + * @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance * @return self */ public function setAuthorizationServer(AuthorizationServer $server) @@ -120,11 +120,11 @@ abstract class AbstractGrant implements GrantTypeInterface /** * Given a list of scopes, validate them and return an array of Scope entities - * @param string $scopeParam A string of scopes (e.g. "profile email birthday") - * @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity - * @param string|null $redirectUri The redirect URI to return the user to + * @param string $scopeParam A string of scopes (e.g. "profile email birthday") + * @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity + * @param string|null $redirectUri The redirect URI to return the user to * @return \League\OAuth2\Server\Entity\ScopeEntity[] - * @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required + * @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required */ public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null) { diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 283d7af5..48ea6a41 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -11,15 +11,15 @@ namespace League\OAuth2\Server\Grant; -use League\OAuth2\Server\Request; -use League\OAuth2\Server\Exception; +use League\OAuth2\Server\Entity\AccessTokenEntity; +use League\OAuth2\Server\Entity\AuthCodeEntity; use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\RefreshTokenEntity; use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\AccessTokenEntity; -use League\OAuth2\Server\Entity\AuthCodeEntity; -use League\OAuth2\Server\Util\SecureKey; use League\OAuth2\Server\Event; +use League\OAuth2\Server\Exception; +use League\OAuth2\Server\Request; +use League\OAuth2\Server\Util\SecureKey; /** * Auth code grant class @@ -234,7 +234,7 @@ class AuthCodeGrant extends AbstractGrant } foreach ($session->getScopes() as $scope) { - $accessToken->associateScope($scope); + $accessToken->associateScope($scope); } $this->server->getTokenType()->setSession($session); diff --git a/src/Grant/ClientCredentialsGrant.php b/src/Grant/ClientCredentialsGrant.php index 8c87b249..40f6f051 100644 --- a/src/Grant/ClientCredentialsGrant.php +++ b/src/Grant/ClientCredentialsGrant.php @@ -14,9 +14,9 @@ namespace League\OAuth2\Server\Grant; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Event; use League\OAuth2\Server\Exception; use League\OAuth2\Server\Util\SecureKey; -use League\OAuth2\Server\Event; /** * Client credentials grant class @@ -53,7 +53,7 @@ class ClientCredentialsGrant extends AbstractGrant */ public function completeFlow() { - // Get the required params + // Get the required params $clientId = $this->server->getRequest()->request->get('client_id', null); if (is_null($clientId)) { $clientId = $this->server->getRequest()->getUser(); @@ -99,11 +99,11 @@ class ClientCredentialsGrant extends AbstractGrant // Associate scopes with the session and access token foreach ($scopes as $scope) { - $session->associateScope($scope); + $session->associateScope($scope); } foreach ($session->getScopes() as $scope) { - $accessToken->associateScope($scope); + $accessToken->associateScope($scope); } // Save everything diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index 5f7cc4c2..db222dfb 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -11,13 +11,13 @@ namespace League\OAuth2\Server\Grant; -use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\AccessTokenEntity; +use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\RefreshTokenEntity; use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Event; use League\OAuth2\Server\Exception; use League\OAuth2\Server\Util\SecureKey; -use League\OAuth2\Server\Event; /** * Password grant class @@ -141,11 +141,11 @@ class PasswordGrant extends AbstractGrant // Associate scopes with the session and access token foreach ($scopes as $scope) { - $session->associateScope($scope); + $session->associateScope($scope); } foreach ($session->getScopes() as $scope) { - $accessToken->associateScope($scope); + $accessToken->associateScope($scope); } $this->server->getTokenType()->setSession($session); diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index 67333991..1c5a0e5f 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -11,13 +11,13 @@ namespace League\OAuth2\Server\Grant; -use League\OAuth2\Server\Request; -use League\OAuth2\Server\Exception; -use League\OAuth2\Server\Util\SecureKey; -use League\OAuth2\Server\Entity\RefreshTokenEntity; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\RefreshTokenEntity; use League\OAuth2\Server\Event; +use League\OAuth2\Server\Exception; +use League\OAuth2\Server\Request; +use League\OAuth2\Server\Util\SecureKey; /** * Referesh token grant diff --git a/src/ResourceServer.php b/src/ResourceServer.php index 6596a559..73199a49 100644 --- a/src/ResourceServer.php +++ b/src/ResourceServer.php @@ -11,13 +11,12 @@ namespace League\OAuth2\Server; -use League\OAuth2\Server\Storage\ClientInterface; -use League\OAuth2\Server\Storage\AccessTokenInterface; -use League\OAuth2\Server\Storage\SessionInterface; -use League\OAuth2\Server\Storage\ScopeInterface; use League\OAuth2\Server\Entity\AccessTokenEntity; +use League\OAuth2\Server\Storage\AccessTokenInterface; +use League\OAuth2\Server\Storage\ClientInterface; +use League\OAuth2\Server\Storage\ScopeInterface; +use League\OAuth2\Server\Storage\SessionInterface; use League\OAuth2\Server\TokenType\Bearer; -use League\OAuth2\Server\Exception; use Symfony\Component\HttpFoundation\Request; /** @@ -57,7 +56,7 @@ class ResourceServer extends AbstractServer $this->setScopeStorage($scopeStorage); // Set Bearer as the default token type - $this->setTokenType(new Bearer); + $this->setTokenType(new Bearer()); parent::__construct(); @@ -101,13 +100,13 @@ class ResourceServer extends AbstractServer // Ensure the access token exists if (!$this->accessToken instanceof AccessTokenEntity) { - throw new Exception\AccessDeniedException; + throw new Exception\AccessDeniedException(); } // Check the access token hasn't expired // Ensure the auth code hasn't expired if ($this->accessToken->isExpired() === true) { - throw new Exception\AccessDeniedException; + throw new Exception\AccessDeniedException(); } return true; diff --git a/src/Storage/AccessTokenInterface.php b/src/Storage/AccessTokenInterface.php index 126efb0b..ca172abe 100644 --- a/src/Storage/AccessTokenInterface.php +++ b/src/Storage/AccessTokenInterface.php @@ -11,9 +11,8 @@ namespace League\OAuth2\Server\Storage; -use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\AbstractTokenEntity; -use League\OAuth2\Server\Entity\RefreshTokenEntity; +use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\ScopeEntity; /** diff --git a/src/Storage/SessionInterface.php b/src/Storage/SessionInterface.php index 545df304..a4ae0437 100644 --- a/src/Storage/SessionInterface.php +++ b/src/Storage/SessionInterface.php @@ -13,8 +13,8 @@ namespace League\OAuth2\Server\Storage; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\AuthCodeEntity; -use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; /** * Session storage interface diff --git a/src/TokenType/AbstractTokenType.php b/src/TokenType/AbstractTokenType.php index 7691ec9e..e530b445 100644 --- a/src/TokenType/AbstractTokenType.php +++ b/src/TokenType/AbstractTokenType.php @@ -11,9 +11,9 @@ namespace League\OAuth2\Server\TokenType; -use Symfony\Component\HttpFoundation\Request; use League\OAuth2\Server\AbstractServer; use League\OAuth2\Server\Entity\SessionEntity; +use Symfony\Component\HttpFoundation\Request; abstract class AbstractTokenType { @@ -42,6 +42,7 @@ abstract class AbstractTokenType public function setServer(AbstractServer $server) { $this->server = $server; + return $this; } @@ -52,6 +53,7 @@ abstract class AbstractTokenType public function setSession(SessionEntity $session) { $this->session = $session; + return $this; } diff --git a/src/TokenType/Bearer.php b/src/TokenType/Bearer.php index bedb0279..797de3ac 100644 --- a/src/TokenType/Bearer.php +++ b/src/TokenType/Bearer.php @@ -23,7 +23,7 @@ class Bearer extends AbstractTokenType implements TokenTypeInterface $return = [ 'access_token' => $this->getParam('access_token'), 'token_type' => 'Bearer', - 'expires_in' => $this->getParam('expires_in') + 'expires_in' => $this->getParam('expires_in'), ]; if (!is_null($this->getParam('refresh_token'))) { diff --git a/src/Util/KeyAlgorithm/DefaultAlgorithm.php b/src/Util/KeyAlgorithm/DefaultAlgorithm.php index fc07b0cb..08c4009a 100644 --- a/src/Util/KeyAlgorithm/DefaultAlgorithm.php +++ b/src/Util/KeyAlgorithm/DefaultAlgorithm.php @@ -30,6 +30,6 @@ class DefaultAlgorithm implements KeyAlgorithmInterface // @codeCoverageIgnoreEnd } - return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $len); + return substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $len); } } diff --git a/src/Util/RedirectUri.php b/src/Util/RedirectUri.php index b05b92bc..15caddb3 100644 --- a/src/Util/RedirectUri.php +++ b/src/Util/RedirectUri.php @@ -23,7 +23,7 @@ class RedirectUri * @param string $queryDelimeter The query string delimeter (default: "?") * @return string The updated URI */ - public static function make($uri, $params = array(), $queryDelimeter = '?') + public static function make($uri, $params = [], $queryDelimeter = '?') { $uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&'; diff --git a/tests/fuzz/grant-authcode.yml b/tests/fuzz/grant-authcode.yml index 7c740a9d..e4df2d68 100644 --- a/tests/fuzz/grant-authcode.yml +++ b/tests/fuzz/grant-authcode.yml @@ -6,4 +6,4 @@ response: headers: - key: Location - valueRegex: /http:\/\/example.com\/redirect\?code=([a-zA-Z0-9]*)/ \ No newline at end of file + valueRegex: /http:\/\/example.com\/redirect\?code=([a-zA-Z0-9]*)/ diff --git a/tests/fuzz/grant-client-credentials.yml b/tests/fuzz/grant-client-credentials.yml index e56d903f..47b9f566 100644 --- a/tests/fuzz/grant-client-credentials.yml +++ b/tests/fuzz/grant-client-credentials.yml @@ -64,4 +64,4 @@ response: valueRegex: /([a-zA-Z0-9]*)/ - key: token_type - value: Bearer \ No newline at end of file + value: Bearer diff --git a/tests/fuzz/grant-password.yml b/tests/fuzz/grant-password.yml index 0348c5f2..e0f95827 100644 --- a/tests/fuzz/grant-password.yml +++ b/tests/fuzz/grant-password.yml @@ -85,4 +85,4 @@ response: valueRegex: /([a-zA-Z0-9]*)/ - key: token_type - value: Bearer \ No newline at end of file + value: Bearer diff --git a/tests/fuzz/tokeninfo-no-access-token.yml b/tests/fuzz/tokeninfo-no-access-token.yml index 3d084cf7..253d29e9 100644 --- a/tests/fuzz/tokeninfo-no-access-token.yml +++ b/tests/fuzz/tokeninfo-no-access-token.yml @@ -13,4 +13,4 @@ response: value: "invalid_request" - key: message - value: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter." \ No newline at end of file + value: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter." diff --git a/tests/fuzz/tokeninfo-no-invalid-token-query-string.yml b/tests/fuzz/tokeninfo-no-invalid-token-query-string.yml index bfe07737..2606eb05 100644 --- a/tests/fuzz/tokeninfo-no-invalid-token-query-string.yml +++ b/tests/fuzz/tokeninfo-no-invalid-token-query-string.yml @@ -13,4 +13,4 @@ response: value: "access_denied" - key: message - value: "The resource owner or authorization server denied the request." \ No newline at end of file + value: "The resource owner or authorization server denied the request." diff --git a/tests/fuzz/tokeninfo-no-invalid-token.yml b/tests/fuzz/tokeninfo-no-invalid-token.yml index 8c4535e3..eab58240 100644 --- a/tests/fuzz/tokeninfo-no-invalid-token.yml +++ b/tests/fuzz/tokeninfo-no-invalid-token.yml @@ -17,4 +17,4 @@ response: value: "access_denied" - key: message - value: "The resource owner or authorization server denied the request." \ No newline at end of file + value: "The resource owner or authorization server denied the request." diff --git a/tests/fuzz/tokeninfo-valid-token-header.yml b/tests/fuzz/tokeninfo-valid-token-header.yml index c30d819e..67f74d69 100644 --- a/tests/fuzz/tokeninfo-valid-token-header.yml +++ b/tests/fuzz/tokeninfo-valid-token-header.yml @@ -23,4 +23,4 @@ response: value: iamgod - key: client_id - value: testclient \ No newline at end of file + value: testclient diff --git a/tests/fuzz/tokeninfo-valid-token.yml b/tests/fuzz/tokeninfo-valid-token.yml index fb160249..d76def84 100644 --- a/tests/fuzz/tokeninfo-valid-token.yml +++ b/tests/fuzz/tokeninfo-valid-token.yml @@ -19,4 +19,4 @@ response: value: iamgod - key: client_id - value: testclient \ No newline at end of file + value: testclient diff --git a/tests/fuzz/users-token-iamalex.yml b/tests/fuzz/users-token-iamalex.yml index 629de493..43086f3e 100644 --- a/tests/fuzz/users-token-iamalex.yml +++ b/tests/fuzz/users-token-iamalex.yml @@ -29,4 +29,4 @@ response: value: Phil Sturgeon - key: 1.photo - valueType: string \ No newline at end of file + valueType: string diff --git a/tests/fuzz/users-token-iamphil.yml b/tests/fuzz/users-token-iamphil.yml index 6f1b7b57..98d8e982 100644 --- a/tests/fuzz/users-token-iamphil.yml +++ b/tests/fuzz/users-token-iamphil.yml @@ -29,4 +29,4 @@ response: value: Phil Sturgeon - key: 1.email - valueType: string \ No newline at end of file + valueType: string diff --git a/tests/unit/AbstractServerTest.php b/tests/unit/AbstractServerTest.php index 8bf34dd5..074f363c 100644 --- a/tests/unit/AbstractServerTest.php +++ b/tests/unit/AbstractServerTest.php @@ -10,7 +10,7 @@ class AbstractServerTest extends \PHPUnit_Framework_TestCase { $server = new StubAbstractServer(); $var = 0; - $server->addEventListener('event.name', function() use ($var) { + $server->addEventListener('event.name', function () use ($var) { $var++; $this->assertSame(1, $var); }); @@ -18,11 +18,9 @@ class AbstractServerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($server->getRequest() instanceof \Symfony\Component\HttpFoundation\Request); $this->assertTrue($server->getEventEmitter() instanceof \League\Event\Emitter); - $server2 = new StubAbstractServer(); - $server2->setRequest((new \Symfony\Component\HttpFoundation\Request)); + $server2->setRequest((new \Symfony\Component\HttpFoundation\Request())); $server2->setEventEmitter(1); $this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request); - } } diff --git a/tests/unit/AuthorizationServerTest.php b/tests/unit/AuthorizationServerTest.php index a17a004e..f0873a71 100644 --- a/tests/unit/AuthorizationServerTest.php +++ b/tests/unit/AuthorizationServerTest.php @@ -5,13 +5,13 @@ namespace LeagueTests; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Grant\GrantTypeInterface; use League\OAuth2\Server\Storage\ScopeInterface; -use \Mockery as M; +use Mockery as M; class AuthorizationServerTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $server->requireScopeParam(true); $server->requireStateParam(true); $server->setDefaultScope('foobar'); @@ -43,7 +43,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase public function testInvalidGrantType() { $this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantException'); - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $server->getGrantType('foobar'); } @@ -57,7 +57,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'foobar'; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $server->addGrantType($grant); $this->assertTrue($server->issueAccessToken()); @@ -66,7 +66,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase public function testIssueAccessTokenEmptyGrantType() { $this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException'); - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $this->assertTrue($server->issueAccessToken()); } @@ -76,7 +76,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'foobar'; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $this->assertTrue($server->issueAccessToken()); } } diff --git a/tests/unit/Bootstrap.php b/tests/unit/Bootstrap.php index e6d3d782..4c9c8086 100644 --- a/tests/unit/Bootstrap.php +++ b/tests/unit/Bootstrap.php @@ -1,5 +1,5 @@ wget http://getcomposer.org/composer.phar\n> php composer.phar install\n"); } diff --git a/tests/unit/Entity/AbstractTokenEntityTest.php b/tests/unit/Entity/AbstractTokenEntityTest.php index f3bb290a..4c3b1020 100644 --- a/tests/unit/Entity/AbstractTokenEntityTest.php +++ b/tests/unit/Entity/AbstractTokenEntityTest.php @@ -3,12 +3,12 @@ namespace LeagueTests\Entity; use LeagueTests\Stubs\StubAbstractTokenEntity; -use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\AuthorizationServer; -use \Mockery as M; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; +use Mockery as M; -class AbstractTokenTest extends \PHPUnit_Framework_TestCase +class AbstractTokenEntityTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { @@ -93,7 +93,7 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase $scopes = [ (new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']), - (new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']) + (new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']), ]; $result = $method->invokeArgs($entity, [$scopes]); diff --git a/tests/unit/Entity/AccessTokenEntityTest.php b/tests/unit/Entity/AccessTokenEntityTest.php index ae1399cf..6f2a617e 100644 --- a/tests/unit/Entity/AccessTokenEntityTest.php +++ b/tests/unit/Entity/AccessTokenEntityTest.php @@ -2,12 +2,12 @@ namespace LeagueTests\Entity; +use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\AccessTokenEntity; -use \Mockery as M; +use Mockery as M; -class AccessTokenTest extends \PHPUnit_Framework_TestCase +class AccessTokenEntityTest extends \PHPUnit_Framework_TestCase { public function testSave() { @@ -20,7 +20,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('associateScope'); $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); diff --git a/tests/unit/Entity/AuthCodeEntityTest.php b/tests/unit/Entity/AuthCodeEntityTest.php index 87b761bb..5b7fc089 100644 --- a/tests/unit/Entity/AuthCodeEntityTest.php +++ b/tests/unit/Entity/AuthCodeEntityTest.php @@ -2,13 +2,13 @@ namespace LeagueTests\Entity; +use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\AuthCodeEntity; use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\AuthCodeEntity; -use League\OAuth2\Server\AuthorizationServer; -use \Mockery as M; +use Mockery as M; -class AuthCodeTest extends \PHPUnit_Framework_TestCase +class AuthCodeEntityTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { @@ -37,7 +37,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase $authCodeStorage->shouldReceive('associateScope'); $authCodeStorage->shouldReceive('setServer'); $authCodeStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $server->shouldReceive('getAuthCodeStorage')->andReturn($authCodeStorage); diff --git a/tests/unit/Entity/ClientEntityTest.php b/tests/unit/Entity/ClientEntityTest.php index 7521ad7a..9bb13c7d 100644 --- a/tests/unit/Entity/ClientEntityTest.php +++ b/tests/unit/Entity/ClientEntityTest.php @@ -3,9 +3,9 @@ namespace LeagueTests\Entity; use League\OAuth2\Server\Entity\ClientEntity; -use \Mockery as M; +use Mockery as M; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientEntityTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { @@ -14,7 +14,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase 'id' => 'foobar', 'secret' => 'barfoo', 'name' => 'Test Client', - 'redirectUri' => 'http://foo/bar' + 'redirectUri' => 'http://foo/bar', ]); $this->assertEquals('foobar', $client->getId()); diff --git a/tests/unit/Entity/RefreshTokenEntityTest.php b/tests/unit/Entity/RefreshTokenEntityTest.php index d1f5bde5..f2b05cf7 100644 --- a/tests/unit/Entity/RefreshTokenEntityTest.php +++ b/tests/unit/Entity/RefreshTokenEntityTest.php @@ -2,11 +2,11 @@ namespace LeagueTests\Entity; -use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\RefreshTokenEntity; -use \Mockery as M; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; +use Mockery as M; class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase { @@ -55,7 +55,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase (new AccessTokenEntity($server))->setId('foobar') ); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage); diff --git a/tests/unit/Entity/ScopeEntityTest.php b/tests/unit/Entity/ScopeEntityTest.php index a9730089..3fec4fe1 100644 --- a/tests/unit/Entity/ScopeEntityTest.php +++ b/tests/unit/Entity/ScopeEntityTest.php @@ -3,16 +3,16 @@ namespace LeagueTests\Entity; use League\OAuth2\Server\Entity\ScopeEntity; -use \Mockery as M; +use Mockery as M; -class ScopeTest extends \PHPUnit_Framework_TestCase +class ScopeEntityTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { $server = M::mock('League\OAuth2\Server\AbstractServer'); $scope = (new ScopeEntity($server))->hydrate([ 'id' => 'foobar', - 'description' => 'barfoo' + 'description' => 'barfoo', ]); $this->assertEquals('foobar', $scope->getId()); diff --git a/tests/unit/Entity/SessionEntityTest.php b/tests/unit/Entity/SessionEntityTest.php index 4aea41ea..5ca26a75 100644 --- a/tests/unit/Entity/SessionEntityTest.php +++ b/tests/unit/Entity/SessionEntityTest.php @@ -2,15 +2,15 @@ namespace LeagueTests\Entity; +use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Entity\AccessTokenEntity; use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\RefreshTokenEntity; -use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\AuthorizationServer; -use \Mockery as M; +use League\OAuth2\Server\Entity\SessionEntity; +use Mockery as M; -class SessionTest extends \PHPUnit_Framework_TestCase +class SessionEntityTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { @@ -60,7 +60,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase $scopes = [ (new ScopeEntity($server))->hydrate(['id' => 'scope1']), - (new ScopeEntity($server))->hydrate(['id' => 'scope2']) + (new ScopeEntity($server))->hydrate(['id' => 'scope2']), ]; $result = $method->invokeArgs($entity, [$scopes]); @@ -132,7 +132,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('associateScope'); $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $server->shouldReceive('getSessionStorage')->andReturn($sessionStorage); diff --git a/tests/unit/Exception/OAuthExceptionTest.php b/tests/unit/Exception/OAuthExceptionTest.php index 7ab5bed1..273ed374 100644 --- a/tests/unit/Exception/OAuthExceptionTest.php +++ b/tests/unit/Exception/OAuthExceptionTest.php @@ -2,13 +2,13 @@ namespace LeagueTests; -use \Mockery as M; +use League\OAuth2\Server\Exception\OAuthException; class OAuthExceptionTest extends \PHPUnit_Framework_TestCase { public function testGetHttpHeaders() { - $exception = new \League\OAuth2\Server\Exception\OAuthException(); + $exception = new OAuthException(); $exception->httpStatusCode = 400; $this->assertSame($exception->getHttpHeaders(), ['HTTP/1.1 400 Bad Request']); @@ -25,7 +25,7 @@ class OAuthExceptionTest extends \PHPUnit_Framework_TestCase public function testShouldRedirect() { - $exception = new \League\OAuth2\Server\Exception\OAuthException(); + $exception = new OAuthException(); $exception->redirectUri = 'http://example.com/'; $exception->errorType = 'Error'; $this->assertTrue($exception->shouldRedirect()); diff --git a/tests/unit/Grant/AbstractGrantTest.php b/tests/unit/Grant/AbstractGrantTest.php index 784a5dc6..e7c5043e 100644 --- a/tests/unit/Grant/AbstractGrantTest.php +++ b/tests/unit/Grant/AbstractGrantTest.php @@ -2,21 +2,21 @@ namespace LeagueTests\Grant; -use League\OAuth2\Server\Grant; -use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\Entity\ClientEntity; -use League\OAuth2\Server\AuthorizationServer; -use League\OAuth2\Server\Exception\InvalidRequestException; use LeagueTests\Stubs\StubAbstractGrant; +use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Exception\InvalidRequestException; +use League\OAuth2\Server\Grant; use Mockery as M; class AbstractGrantTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setIdentifier('foobar'); $grant->setAccessTokenTTL(300); $grant->setAuthorizationServer($server); @@ -31,14 +31,14 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase { $server = M::mock('League\OAuth2\Server\AbstractServer'); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $reflectedGrant = new \ReflectionClass('LeagueTests\Stubs\StubAbstractGrant'); $method = $reflectedGrant->getMethod('formatScopes'); $method->setAccessible(true); $scopes = [ (new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']), - (new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']) + (new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']), ]; $result = $method->invokeArgs($grant, [$scopes]); @@ -51,7 +51,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testValidateScopes() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); $scopeStorage->shouldReceive('setServer'); @@ -61,14 +61,14 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $server->setScopeStorage($scopeStorage); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setAuthorizationServer($server); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); $this->assertEquals( [ - 'foo' => (new ScopeEntity($server))->hydrate(['id' => 'foo']) + 'foo' => (new ScopeEntity($server))->hydrate(['id' => 'foo']), ], $grant->validateScopes('foo', $client) ); @@ -81,11 +81,11 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); $scopeStorage->shouldReceive('setServer'); - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $server->requireScopeParam(true); $server->setScopeStorage($scopeStorage); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setAuthorizationServer($server); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); @@ -101,10 +101,10 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $scopeStorage->shouldReceive('setServer'); $scopeStorage->shouldReceive('get')->andReturn(null); - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $server->setScopeStorage($scopeStorage); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setAuthorizationServer($server); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); @@ -114,7 +114,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testValidateScopesDefaultScope() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); $scopeStorage->shouldReceive('setServer'); @@ -127,7 +127,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $server->setScopeStorage($scopeStorage); $server->setDefaultScope('foo'); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setAuthorizationServer($server); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); @@ -137,7 +137,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase public function testValidateScopesDefaultScopeArray() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); $scopeStorage->shouldReceive('setServer'); @@ -150,7 +150,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $server->setScopeStorage($scopeStorage); $server->setDefaultScope(['foo', 'bar']); - $grant = new StubAbstractGrant; + $grant = new StubAbstractGrant(); $grant->setAuthorizationServer($server); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); diff --git a/tests/unit/Grant/AuthCodeGrantTest.php b/tests/unit/Grant/AuthCodeGrantTest.php index 3b418f02..72a564d4 100644 --- a/tests/unit/Grant/AuthCodeGrantTest.php +++ b/tests/unit/Grant/AuthCodeGrantTest.php @@ -2,21 +2,21 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\AuthCodeEntity; +use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Exception\InvalidRequestException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; -use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\Entity\ClientEntity; -use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\AuthCodeEntity; -use League\OAuth2\Server\AuthorizationServer; -use League\OAuth2\Server\Exception\InvalidRequestException; use Mockery as M; class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase { public function testSetAuthTokenTTL() { - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $grant->setAuthTokenTTL(100); $class = new \ReflectionClass($grant); @@ -30,25 +30,24 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException'); $_GET = []; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $grant->checkAuthorizeParams(); - } public function testCheckAuthoriseParamsMissingRedirectUri() { $this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException'); - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $_GET = [ - 'client_id' => 'testapp' + 'client_id' => 'testapp', ]; - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $grant->checkAuthorizeParams(); @@ -61,11 +60,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_GET = [ 'client_id' => 'testapp', 'redirect_uri' => 'http://foo/bar', - 'response_type' => 'code' + 'response_type' => 'code', ]; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -83,9 +82,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_GET = [ 'client_id' => 'testapp', - 'redirect_uri' => 'http://foo/bar' + 'redirect_uri' => 'http://foo/bar', ]; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -94,7 +93,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $server->setClientStorage($clientStorage); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->requireStateParam(true); $server->addGrantType($grant); @@ -107,9 +106,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_GET = [ 'client_id' => 'testapp', - 'redirect_uri' => 'http://foo/bar' + 'redirect_uri' => 'http://foo/bar', ]; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -118,7 +117,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $server->setClientStorage($clientStorage); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $grant->checkAuthorizeParams(); @@ -131,9 +130,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_GET = [ 'client_id' => 'testapp', 'redirect_uri' => 'http://foo/bar', - 'response_type' => 'foobar' + 'response_type' => 'foobar', ]; - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -142,7 +141,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $server->setClientStorage($clientStorage); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $grant->checkAuthorizeParams(); @@ -156,11 +155,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'response_type' => 'code', 'client_id' => 'testapp', 'redirect_uri' => 'http://foo/bar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -197,11 +196,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'response_type' => 'code', 'client_id' => 'testapp', 'redirect_uri' => 'http://foo/bar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -213,7 +212,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('create')->andreturn(123); $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage->shouldReceive('associateScope'); @@ -221,7 +220,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -249,11 +248,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase public function testNewAuthoriseRequest() { - $server = new AuthorizationServer; + $server = new AuthorizationServer(); $client = (new ClientEntity($server))->hydrate(['id' => 'testapp']); $scope = (new ScopeEntity($server))->hydrate(['id' => 'foo']); - $grant = new AuthCodeGrant; + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); @@ -284,12 +283,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'authorization_code'; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $server->issueAccessToken(); - } public function testCompleteFlowMissingClientSecret() @@ -298,11 +296,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'authorization_code', - 'client_id' => 'testapp' + 'client_id' => 'testapp', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -315,11 +313,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'authorization_code', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -333,11 +331,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'authorization_code', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'redirect_uri' => 'http://foo/bar' + 'redirect_uri' => 'http://foo/bar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -357,11 +355,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'authorization_code', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'redirect_uri' => 'http://foo/bar' + 'redirect_uri' => 'http://foo/bar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -406,11 +404,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'redirect_uri' => 'http://foo/bar', - 'code' => 'foobar' + 'code' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -455,11 +453,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'redirect_uri' => 'http://foo/bar', - 'code' => 'foobar' + 'code' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -506,11 +504,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'redirect_uri' => 'http://foo/bar', - 'code' => 'foobar' + 'code' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -555,11 +553,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'redirect_uri' => 'http://foo/bar', - 'code' => 'foo' + 'code' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -581,7 +579,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase (new SessionEntity($server))->setId('foobar') ); $sessionStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); @@ -589,7 +587,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('associateScope'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); @@ -605,7 +603,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase (new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300) ); $authCodeStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $server->setClientStorage($clientStorage); @@ -625,12 +623,12 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'redirect_uri' => 'http://foo/bar', - 'code' => 'foo' + 'code' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new AuthCodeGrant; - $rtgrant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new AuthCodeGrant(); + $rtgrant = new RefreshTokenGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -652,7 +650,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase (new SessionEntity($server))->setId('foobar') ); $sessionStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); @@ -660,7 +658,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('associateScope'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); @@ -676,7 +674,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase (new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300) ); $authCodeStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface'); diff --git a/tests/unit/Grant/ClientCredentialsGrantTest.php b/tests/unit/Grant/ClientCredentialsGrantTest.php index 733c225b..8e5643f5 100644 --- a/tests/unit/Grant/ClientCredentialsGrantTest.php +++ b/tests/unit/Grant/ClientCredentialsGrantTest.php @@ -2,11 +2,11 @@ namespace LeagueTests\Grant; -use League\OAuth2\Server\Grant\ClientCredentialsGrant; +use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\ScopeEntity; use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\ClientEntity; -use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Grant\ClientCredentialsGrant; use Mockery as M; class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase @@ -17,12 +17,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'client_credentials'; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $server->addGrantType($grant); $server->issueAccessToken(); - } public function testCompleteFlowMissingClientSecret() @@ -31,11 +30,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'client_credentials', - 'client_id' => 'testapp' + 'client_id' => 'testapp', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -48,11 +47,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'client_credentials', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -72,11 +71,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'client_credentials', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -112,11 +111,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'client_credentials', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -160,11 +159,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'client_credentials', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -176,7 +175,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('create')->andreturn(123); $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage->shouldReceive('getByAccessToken')->andReturn( (new SessionEntity($server))->setId('foobar') @@ -187,7 +186,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -214,16 +213,16 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'client_credentials', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new ClientCredentialsGrant; + $server = new AuthorizationServer(); + $grant = new ClientCredentialsGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); $clientStorage->shouldReceive('get')->andThrow( - new \League\OAuth2\Server\Exception\UnauthorizedClientException + new \League\OAuth2\Server\Exception\UnauthorizedClientException() ); $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); diff --git a/tests/unit/Grant/PasswordGrantTest.php b/tests/unit/Grant/PasswordGrantTest.php index 959ee004..e54ca479 100644 --- a/tests/unit/Grant/PasswordGrantTest.php +++ b/tests/unit/Grant/PasswordGrantTest.php @@ -2,12 +2,12 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; -use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\Entity\ClientEntity; -use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\AuthorizationServer; use Mockery as M; class PasswordGrantTest extends \PHPUnit_Framework_TestCase @@ -18,12 +18,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'password'; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $server->addGrantType($grant); $server->issueAccessToken(); - } public function testCompleteFlowMissingClientSecret() @@ -32,11 +31,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'password', - 'client_id' => 'testapp' + 'client_id' => 'testapp', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -49,11 +48,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'password', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -72,11 +71,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'password', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -115,11 +114,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'password', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'username' => 'foo' + 'username' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -159,11 +158,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'username' => 'foo', - 'password' => 'foobar' + 'password' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -204,11 +203,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_secret' => 'foobar', 'username' => 'foo', 'password' => 'foobar', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -251,11 +250,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'username' => 'username', - 'password' => 'password' + 'password' => 'password', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -301,11 +300,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_secret' => 'foobar', 'scope' => 'foo', 'username' => 'username', - 'password' => 'password' + 'password' => 'password', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -317,7 +316,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('create')->andreturn(123); $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage->shouldReceive('associateScope'); @@ -325,7 +324,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -355,11 +354,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_secret' => 'foobar', 'scope' => 'foo', 'username' => 'username', - 'password' => 'password' + 'password' => 'password', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -371,7 +370,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('create')->andreturn(123); $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage->shouldReceive('getByAccessToken')->andReturn( (new SessionEntity($server))->setId('foobar') @@ -382,7 +381,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -416,11 +415,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase 'client_secret' => 'foobar', 'scope' => 'foo', 'username' => 'username', - 'password' => 'password' + 'password' => 'password', ]; - $server = new AuthorizationServer; - $grant = new PasswordGrant; + $server = new AuthorizationServer(); + $grant = new PasswordGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -432,7 +431,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $sessionStorage->shouldReceive('setServer'); $sessionStorage->shouldReceive('create')->andreturn(123); $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $sessionStorage->shouldReceive('getByAccessToken')->andReturn( (new SessionEntity($server))->setId('foobar') @@ -443,7 +442,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('setServer'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -469,7 +468,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase }); $server->addGrantType($grant); - $server->addGrantType(new RefreshTokenGrant); + $server->addGrantType(new RefreshTokenGrant()); $response = $server->issueAccessToken(); $this->assertTrue(array_key_exists('access_token', $response)); diff --git a/tests/unit/Grant/RefreshTokenGrantTest.php b/tests/unit/Grant/RefreshTokenGrantTest.php index d11555b9..40ae6b0b 100644 --- a/tests/unit/Grant/RefreshTokenGrantTest.php +++ b/tests/unit/Grant/RefreshTokenGrantTest.php @@ -2,20 +2,20 @@ namespace LeagueTests\Grant; -use League\OAuth2\Server\Grant\RefreshTokenGrant; -use League\OAuth2\Server\Entity\ScopeEntity; -use League\OAuth2\Server\Entity\ClientEntity; -use League\OAuth2\Server\Entity\AccessTokenEntity; -use League\OAuth2\Server\Entity\SessionEntity; -use League\OAuth2\Server\Entity\RefreshTokenEntity; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Entity\AccessTokenEntity; +use League\OAuth2\Server\Entity\ClientEntity; +use League\OAuth2\Server\Entity\RefreshTokenEntity; +use League\OAuth2\Server\Entity\ScopeEntity; +use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\Grant\RefreshTokenGrant; use Mockery as M; class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase { public function testSetRefreshTokenTTL() { - $grant = new RefreshTokenGrant; + $grant = new RefreshTokenGrant(); $grant->setRefreshTokenTTL(86400); $property = new \ReflectionProperty($grant, 'refreshTokenTTL'); @@ -30,8 +30,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $_POST['grant_type'] = 'refresh_token'; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -43,11 +43,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'refresh_token', - 'client_id' => 'testapp' + 'client_id' => 'testapp', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $server->addGrantType($grant); $server->issueAccessToken(); @@ -60,11 +60,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $_POST = [ 'grant_type' => 'refresh_token', 'client_id' => 'testapp', - 'client_secret' => 'foobar' + 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -86,8 +86,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase 'client_secret' => 'foobar', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -118,11 +118,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'refresh_token', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'refresh_token' => 'meh' + 'refresh_token' => 'meh', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -152,11 +152,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase 'grant_type' => 'refresh_token', 'client_id' => 'testapp', 'client_secret' => 'foobar', - 'refresh_token' => 'refresh_token' + 'refresh_token' => 'refresh_token', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); $clientStorage->shouldReceive('setServer'); @@ -180,7 +180,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('delete'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -221,11 +221,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'refresh_token' => 'refresh_token', - 'scope' => 'foo' + 'scope' => 'foo', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo'])); @@ -251,7 +251,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('delete'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); @@ -292,11 +292,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase 'client_id' => 'testapp', 'client_secret' => 'foobar', 'refresh_token' => 'refresh_token', - 'scope' => 'blah' + 'scope' => 'blah', ]; - $server = new AuthorizationServer; - $grant = new RefreshTokenGrant; + $server = new AuthorizationServer(); + $grant = new RefreshTokenGrant(); $oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo'])); @@ -322,7 +322,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('delete'); $accessTokenStorage->shouldReceive('create'); $accessTokenStorage->shouldReceive('getScopes')->andReturn([ - (new ScopeEntity($server))->hydrate(['id' => 'foo']) + (new ScopeEntity($server))->hydrate(['id' => 'foo']), ]); $accessTokenStorage->shouldReceive('associateScope'); diff --git a/tests/unit/ResourceServerTest.php b/tests/unit/ResourceServerTest.php index 34d61547..8855abad 100644 --- a/tests/unit/ResourceServerTest.php +++ b/tests/unit/ResourceServerTest.php @@ -2,12 +2,12 @@ namespace LeagueTests; -use League\OAuth2\Server\ResourceServer; use League\OAuth2\Server\Entity\AccessTokenEntity; -use League\OAuth2\Server\Entity\SessionEntity; use League\OAuth2\Server\Entity\ClientEntity; use League\OAuth2\Server\Entity\ScopeEntity; -use \Mockery as M; +use League\OAuth2\Server\Entity\SessionEntity; +use League\OAuth2\Server\ResourceServer; +use Mockery as M; class ResourceServerTest extends \PHPUnit_Framework_TestCase { @@ -77,7 +77,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $request = new \Symfony\Component\HttpFoundation\Request(); $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ - 'HTTP_AUTHORIZATION' => 'Bearer' + 'HTTP_AUTHORIZATION' => 'Bearer', ]); $server->setRequest($request); @@ -137,7 +137,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $server->setIdKey('at'); - $server->addEventListener('session.owner', function($event) { + $server->addEventListener('session.owner', function ($event) { $this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity); }); @@ -147,7 +147,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('getScopes')->andReturn([ (new ScopeEntity($server))->hydrate(['id' => 'foo']), - (new ScopeEntity($server))->hydrate(['id' => 'bar']) + (new ScopeEntity($server))->hydrate(['id' => 'bar']), ]); $sessionStorage->shouldReceive('getByAccessToken')->andReturn( @@ -160,7 +160,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $request = new \Symfony\Component\HttpFoundation\Request(); $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ - 'Authorization' => 'Bearer abcdef' + 'Authorization' => 'Bearer abcdef', ]); $server->setRequest($request); @@ -194,7 +194,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $server->setIdKey('at'); - $server->addEventListener('session.owner', function($event) { + $server->addEventListener('session.owner', function ($event) { $this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity); }); @@ -204,7 +204,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $accessTokenStorage->shouldReceive('getScopes')->andReturn([ (new ScopeEntity($server))->hydrate(['id' => 'foo']), - (new ScopeEntity($server))->hydrate(['id' => 'bar']) + (new ScopeEntity($server))->hydrate(['id' => 'bar']), ]); $sessionStorage->shouldReceive('getByAccessToken')->andReturn( @@ -217,7 +217,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase $request = new \Symfony\Component\HttpFoundation\Request(); $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ - 'Authorization' => 'Bearer abcdef' + 'Authorization' => 'Bearer abcdef', ]); $server->setRequest($request); diff --git a/tests/unit/Storage/AbstractStorageTest.php b/tests/unit/Storage/AbstractStorageTest.php index 6b943f71..30312cb7 100644 --- a/tests/unit/Storage/AbstractStorageTest.php +++ b/tests/unit/Storage/AbstractStorageTest.php @@ -2,19 +2,19 @@ namespace LeagueTests\Storage; -use LeagueTests\Stubs\StubAbstractStorage; use LeagueTests\Stubs\StubAbstractServer; +use LeagueTests\Stubs\StubAbstractStorage; -class AdapterStorageTest extends \PHPUnit_Framework_TestCase +class AbstractStorageTest extends \PHPUnit_Framework_TestCase { public function testSetGet() { - $storage = new StubAbstractStorage; + $storage = new StubAbstractStorage(); $reflector = new \ReflectionClass($storage); $setMethod = $reflector->getMethod('setServer'); $setMethod->setAccessible(true); - $setMethod->invokeArgs($storage, [new StubAbstractServer]); + $setMethod->invokeArgs($storage, [new StubAbstractServer()]); $getMethod = $reflector->getMethod('getServer'); $getMethod->setAccessible(true); diff --git a/tests/unit/Stubs/StubAbstractServer.php b/tests/unit/Stubs/StubAbstractServer.php index 70d78d9e..9254d80d 100644 --- a/tests/unit/Stubs/StubAbstractServer.php +++ b/tests/unit/Stubs/StubAbstractServer.php @@ -4,5 +4,5 @@ namespace LeagueTests\Stubs; class StubAbstractServer extends \League\OAuth2\Server\AbstractServer { - + // } diff --git a/tests/unit/Stubs/StubAbstractStorage.php b/tests/unit/Stubs/StubAbstractStorage.php index cb920f94..2f1b610c 100644 --- a/tests/unit/Stubs/StubAbstractStorage.php +++ b/tests/unit/Stubs/StubAbstractStorage.php @@ -4,5 +4,5 @@ namespace LeagueTests\Stubs; class StubAbstractStorage extends \League\OAuth2\Server\Storage\AbstractStorage { - + // } diff --git a/tests/unit/Stubs/StubAbstractTokenEntity.php b/tests/unit/Stubs/StubAbstractTokenEntity.php index e04c76fd..3333c9ab 100644 --- a/tests/unit/Stubs/StubAbstractTokenEntity.php +++ b/tests/unit/Stubs/StubAbstractTokenEntity.php @@ -2,17 +2,17 @@ namespace LeagueTests\Stubs; -use \League\OAuth2\Server\Entity\AbstractTokenEntity; +use League\OAuth2\Server\Entity\AbstractTokenEntity; class StubAbstractTokenEntity extends AbstractTokenEntity { public function expire() { - + // } public function save() { - + // } } diff --git a/tests/unit/util/RedirectUriTest.php b/tests/unit/util/RedirectUriTest.php index 415ca3d7..6b677404 100644 --- a/tests/unit/util/RedirectUriTest.php +++ b/tests/unit/util/RedirectUriTest.php @@ -8,9 +8,9 @@ class RedirectUriTest extends \PHPUnit_Framework_TestCase { public function testMake() { - $v1 = RedirectUri::make('https://foobar/', array('foo'=>'bar')); - $v2 = RedirectUri::make('https://foobar/', array('foo'=>'bar'), '#'); - $v3 = RedirectUri::make('https://foobar/', array('foo'=>'bar', 'bar' => 'foo')); + $v1 = RedirectUri::make('https://foobar/', ['foo' => 'bar']); + $v2 = RedirectUri::make('https://foobar/', ['foo' => 'bar'], '#'); + $v3 = RedirectUri::make('https://foobar/', ['foo' => 'bar', 'bar' => 'foo']); $this->assertEquals('https://foobar/?foo=bar', $v1); $this->assertEquals('https://foobar/#foo=bar', $v2); diff --git a/tests/unit/util/SecureKeyTest.php b/tests/unit/util/SecureKeyTest.php index edfbb538..394226f5 100644 --- a/tests/unit/util/SecureKeyTest.php +++ b/tests/unit/util/SecureKeyTest.php @@ -2,7 +2,7 @@ namespace LeagueTests\util; -use \League\OAuth2\Server\Util\SecureKey; +use League\OAuth2\Server\Util\SecureKey; class SecureKeyTest extends \PHPUnit_Framework_TestCase { @@ -26,8 +26,7 @@ class SecureKeyTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('generate') ->with(11) - ->will($this->returnValue($result)) - ; + ->will($this->returnValue($result)); SecureKey::setAlgorithm($algorithm); $this->assertSame($algorithm, SecureKey::getAlgorithm());