From b5217271b0cf378227e738f908da2192e3b41607 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 6 Apr 2014 19:13:45 +0100 Subject: [PATCH] Added exception message testing --- tests/Grant/ClientCredentialsTest.php | 8 ++++---- tests/Grant/PasswordTest.php | 20 +++++++++++--------- tests/Grant/RefreshTokenTest.php | 12 ++++++------ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/Grant/ClientCredentialsTest.php b/tests/Grant/ClientCredentialsTest.php index cdc74df9..0ba342c7 100644 --- a/tests/Grant/ClientCredentialsTest.php +++ b/tests/Grant/ClientCredentialsTest.php @@ -13,7 +13,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase { function testCompleteFlowMissingClientId() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.'); $_POST['grant_type'] = 'client_credentials'; @@ -27,7 +27,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase function testCompleteFlowMissingClientSecret() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.'); $_POST = [ 'grant_type' => 'client_credentials', @@ -43,7 +43,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidClient() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed'); $_POST = [ 'grant_type' => 'client_credentials', @@ -66,7 +66,7 @@ class ClientCredentialsTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidScope() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "foo" scope.'); $_POST = [ 'grant_type' => 'client_credentials', diff --git a/tests/Grant/PasswordTest.php b/tests/Grant/PasswordTest.php index 38b33b32..9941761c 100644 --- a/tests/Grant/PasswordTest.php +++ b/tests/Grant/PasswordTest.php @@ -14,7 +14,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase { function testCompleteFlowMissingClientId() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.'); $_POST['grant_type'] = 'password'; @@ -28,7 +28,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testCompleteFlowMissingClientSecret() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.'); $_POST = [ 'grant_type' => 'password', @@ -44,7 +44,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidClient() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed'); $_POST = [ 'grant_type' => 'password', @@ -67,7 +67,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testNoUsername() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "username" parameter.'); $_POST = [ 'grant_type' => 'password', @@ -109,7 +109,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testNoPassword() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "password" parameter.'); $_POST = [ 'grant_type' => 'password', @@ -152,7 +152,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testNoCallable() { - $this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantTypeException'); + $this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantTypeException', 'Null or non-callable callback set on Password grant'); $_POST = [ 'grant_type' => 'password', @@ -196,12 +196,14 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidScope() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "foo" scope.'); $_POST = [ 'grant_type' => 'password', 'client_id' => 'testapp', 'client_secret' => 'foobar', + 'username' => 'foo', + 'password' => 'foobar', 'scope' => 'foo' ]; @@ -242,7 +244,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testCompleteFlowNoScopes() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "scope" parameter.'); $_POST = [ 'grant_type' => 'password', @@ -291,7 +293,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidCredentials() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The user credentials were incorrect.'); $_POST = [ 'grant_type' => 'password', diff --git a/tests/Grant/RefreshTokenTest.php b/tests/Grant/RefreshTokenTest.php index d0c2785e..c6b0bc36 100644 --- a/tests/Grant/RefreshTokenTest.php +++ b/tests/Grant/RefreshTokenTest.php @@ -27,7 +27,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase function testCompleteFlowMissingClientId() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_id" parameter.'); $_POST['grant_type'] = 'refresh_token'; @@ -40,7 +40,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase function testCompleteFlowMissingClientSecret() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "client_secret" parameter.'); $_POST = [ 'grant_type' => 'refresh_token', @@ -56,7 +56,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidClient() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'Client authentication failed'); $_POST = [ 'grant_type' => 'refresh_token', @@ -79,7 +79,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase function testCompleteFlowMissingRefreshToken() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "refresh_token" parameter.'); $_POST = [ 'grant_type' => 'refresh_token', @@ -113,7 +113,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase function testCompleteFlowInvalidRefreshToken() { - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The refresh token is invalid.'); $_POST = [ 'grant_type' => 'refresh_token', @@ -352,7 +352,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase $server->addGrantType($grant); - $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException', 'The requested scope is invalid, unknown, or malformed. Check the "blah" scope.'); $server->issueAccessToken(); }