summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBrent Shaffer <bshafs@gmail.com>2013-01-21 21:07:00 +0400
committerBrent Shaffer <bshafs@gmail.com>2013-01-21 21:07:00 +0400
commit30be7a24c45b0268a7ed7b4038ae2e5e4eade47d (patch)
tree7f066dbcf11b70479d8a728a06c141b544002c25 /test
parentcbed0cb6330f1e1bad6d6acd291b01c6a869add9 (diff)
parent6ea0ad23dde79426fd54206916b967c4b9af69d1 (diff)
downloadoauth2-server-php-0.3.tar.xz
Merge branch 'develop'v0.3
Diffstat (limited to 'test')
-rw-r--r--test/OAuth2/AutoloadTest.php2
-rw-r--r--test/OAuth2/GrantType/AuthorizationCodeTest.php38
-rw-r--r--test/OAuth2/GrantType/ClientCredentialsTest.php39
-rw-r--r--test/OAuth2/GrantType/JWTBearerTest.php39
-rw-r--r--test/OAuth2/GrantType/RefreshTokenTest.php35
-rw-r--r--test/OAuth2/GrantType/UserCredentialsTest.php38
-rw-r--r--test/OAuth2/RequestTest.php4
-rw-r--r--test/OAuth2/ResponseTest.php2
-rw-r--r--test/OAuth2/Server/Access/BasicValidationTest.php2
-rw-r--r--test/OAuth2/Server/Authorize/BasicValidationTest.php17
-rw-r--r--test/OAuth2/Server/Authorize/CodeTest.php2
-rw-r--r--test/OAuth2/Server/Authorize/ImplicitTest.php2
-rw-r--r--test/OAuth2/Server/Grant/BasicValidationTest.php26
-rw-r--r--test/OAuth2/Storage/PdoTest.php2
-rw-r--r--test/bootstrap.php2
-rw-r--r--test/config/storage.json9
-rw-r--r--test/lib/OAuth2/Request/TestRequest.php8
-rw-r--r--test/lib/OAuth2/Storage/Bootstrap.php2
18 files changed, 171 insertions, 98 deletions
diff --git a/test/OAuth2/AutoloadTest.php b/test/OAuth2/AutoloadTest.php
index b7c2e10..eee1a00 100644
--- a/test/OAuth2/AutoloadTest.php
+++ b/test/OAuth2/AutoloadTest.php
@@ -11,4 +11,4 @@ class OAuth2_AutoloadTest extends PHPUnit_Framework_TestCase
$this->assertTrue(class_exists('OAuth2_GrantType_UserCredentials'));
$this->assertTrue(interface_exists('OAuth2_Storage_AccessTokenInterface'));
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/GrantType/AuthorizationCodeTest.php b/test/OAuth2/GrantType/AuthorizationCodeTest.php
index b4af1d5..783a3ee 100644
--- a/test/OAuth2/GrantType/AuthorizationCodeTest.php
+++ b/test/OAuth2/GrantType/AuthorizationCodeTest.php
@@ -6,9 +6,9 @@ class OAuth2_GrantType_AuthorizationCodeTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -20,10 +20,32 @@ class OAuth2_GrantType_AuthorizationCodeTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['code'] = 'InvalidCode'; // invalid authorization code
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['code'] = 'InvalidCode'; // invalid authorization code
+ $response = $server->handleGrantRequest($request);
+
+ $this->assertEquals($response->getStatusCode(), 400);
+ $this->assertEquals($response->getParameter('error'), 'invalid_grant');
+ $this->assertEquals($response->getParameter('error_description'), 'Authorization code doesn\'t exist or is invalid for the client');
+ }
+
+ public function testCodeCannotBeUsedTwice()
+ {
+ $server = $this->getTestServer();
+ $request = OAuth2_Request::createFromGlobals();
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['code'] = 'testcode'; // valid code
+
+ $response = $server->handleGrantRequest($request);
+
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertNotNull($response->getParameter('access_token'));
+
+ // try to use the same code again
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -39,4 +61,4 @@ class OAuth2_GrantType_AuthorizationCodeTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/GrantType/ClientCredentialsTest.php b/test/OAuth2/GrantType/ClientCredentialsTest.php
index f6934f8..93d6051 100644
--- a/test/OAuth2/GrantType/ClientCredentialsTest.php
+++ b/test/OAuth2/GrantType/ClientCredentialsTest.php
@@ -6,9 +6,9 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'client_credentials'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'FakeSecret'; // valid client secret
+ $request->request['grant_type'] = 'client_credentials'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'FakeSecret'; // valid client secret
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -20,10 +20,11 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'client_credentials'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['scope'] = 'scope';
+ $request->server['REQUEST_METHOD'] = 'POST';
+ $request->request['grant_type'] = 'client_credentials'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['scope'] = 'scope';
$token = $server->grantAccessToken($request);
$this->assertNotNull($token);
@@ -36,9 +37,9 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'client_credentials'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['grant_type'] = 'client_credentials'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
$token = $server->grantAccessToken($request);
$this->assertNotNull($token);
@@ -51,8 +52,8 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
// create with HTTP_AUTHORIZATION in header
$server = $this->getTestServer();
$headers = array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('Test Client ID:TestSecret'));
- $query = array('grant_type' => 'client_credentials');
- $request = new OAuth2_Request($query, array(), array(), array(), array(), $headers);
+ $params = array('grant_type' => 'client_credentials');
+ $request = new OAuth2_Request(array(), $params, array(), array(), array(), $headers);
$token = $server->grantAccessToken($request);
$this->assertNotNull($token);
@@ -61,8 +62,8 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
// create using PHP Authorization Globals
$headers = array('PHP_AUTH_USER' => 'Test Client ID', 'PHP_AUTH_PW' => 'TestSecret');
- $query = array('grant_type' => 'client_credentials');
- $request = new OAuth2_Request($query, array(), array(), array(), array(), $headers);
+ $params = array('grant_type' => 'client_credentials');
+ $request = new OAuth2_Request(array(), $params, array(), array(), array(), $headers);
$token = $server->grantAccessToken($request);
$this->assertNotNull($token);
@@ -75,7 +76,7 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
$request->server['REQUEST_METHOD'] = 'POST';
- $request->query['grant_type'] = 'client_credentials'; // valid grant type
+ $request->request['grant_type'] = 'client_credentials'; // valid grant type
$request->request['client_id'] = 'Test Client ID'; // valid client id
$request->request['client_secret'] = 'TestSecret'; // valid client secret
$token = $server->grantAccessToken($request);
@@ -89,9 +90,9 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'client_credentials'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['grant_type'] = 'client_credentials'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
$token = $server->grantAccessToken($request);
$this->assertNotNull($token);
@@ -107,4 +108,4 @@ class OAuth2_GrantType_ClientCredentialsTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/GrantType/JWTBearerTest.php b/test/OAuth2/GrantType/JWTBearerTest.php
index 1d2064c..7bae26e 100644
--- a/test/OAuth2/GrantType/JWTBearerTest.php
+++ b/test/OAuth2/GrantType/JWTBearerTest.php
@@ -99,7 +99,7 @@ class OAuth2_GrantType_JWTBearerTest extends PHPUnit_Framework_TestCase
$request->query['grant_type'] = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; // valid grant type
//Get a future NBF
- $jwt = $this->getJWT(NULL, time() + 10000);
+ $jwt = $this->getJWT(null, time() + 10000);
$request->query['assertion'] = $jwt;
$server->grantAccessToken($request);
@@ -117,7 +117,7 @@ class OAuth2_GrantType_JWTBearerTest extends PHPUnit_Framework_TestCase
$request->query['grant_type'] = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; // valid grant type
//Get a non timestamp nbf
- $jwt = $this->getJWT(NULL, 'notatimestamp');
+ $jwt = $this->getJWT(null, 'notatimestamp');
$request->query['assertion'] = $jwt;
$server->grantAccessToken($request);
@@ -148,24 +148,40 @@ class OAuth2_GrantType_JWTBearerTest extends PHPUnit_Framework_TestCase
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
$request->query['grant_type'] = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; // valid grant type
- $request->query['assertion'] = $this->getJWT(NULL, NULL, 'bad_client_id');
+ $request->query['assertion'] = $this->getJWT(null, null, null, 'bad_client_id');
$server->grantAccessToken($request);
$response = $server->getResponse();
$this->assertEquals($response->getStatusCode(), 400);
$this->assertEquals($response->getParameter('error'), 'invalid_grant');
- $this->assertEquals($response->getParameter('error_description'), 'Invalid issuer (iss) provided');
+ $this->assertEquals($response->getParameter('error_description'), 'Invalid issuer (iss) or subject (sub) provided');
+ }
+
+ public function testBadSbuject()
+ {
+ $server = $this->getTestServer();
+ $request = OAuth2_Request::createFromGlobals();
+ $request->query['grant_type'] = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; // valid grant type
+ $request->query['assertion'] = $this->getJWT(null, null, 'anotheruser@ourdomain.com');
+
+ $server->grantAccessToken($request);
+ $response = $server->getResponse();
+
+ $this->assertEquals($response->getStatusCode(), 400);
+ $this->assertEquals($response->getParameter('error'), 'invalid_grant');
+ $this->assertEquals($response->getParameter('error_description'), 'Invalid issuer (iss) or subject (sub) provided');
}
/**
* Generates a JWT
- * @param The expiration date. If the current time is greater than the exp, the JWT is invalid. $exp
- * @param The "not before" time. If the current time is less than the nbf, the JWT is invalid. $nbf
- * @param The issuer, usually the client_id. $iss
+ * @param $exp The expiration date. If the current time is greater than the exp, the JWT is invalid.
+ * @param $nbf The "not before" time. If the current time is less than the nbf, the JWT is invalid.
+ * @param $sub The subject we are acting on behalf of. This could be the email address of the user in the system.
+ * @param $iss The issuer, usually the client_id.
* @return string
*/
- private function getJWT($exp = NULL, $nbf = NULL, $iss = 'Test Client ID')
+ private function getJWT($exp = null, $nbf = null, $sub = null, $iss = 'Test Client ID')
{
$privateKey = "-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCy2DNurVPKjODp af+6DLCeDgnbA85pInA9aUUV9/3YrrStCusIMNRJV66ELT5OOfsurfmAxmuxZrOX eiPgoAcEEVmoE96MRHRn+3XCBmRr3u6ihbYFyXFQyMvqwVb3YEubZ/Y+j9IOMp0Z HC3T6R2PYyCZ2ogO7spM0s9VL/fOTQuf4S233als4OFSWJgeRUXL9lm2hfrqWCAu NlcZ0E/akvH9wBHT0HSbVAMG+TMZ7CYXoeXSBeopIFB6XW+dHw+nZzwWOnewMHrm GJK1eZ9ro2kxkEBvi8Gnf1LJGtteI0fsZtigiIEG2CeFWDjMcAbpu2wTIC2ZUzRo yGfTVModAgMBAAECggEAdqL4q0iLNufxIqVQIEjeuFozq3eA6zkPH42/aG1TlPN/ ovKFKq/JgsWJXODuXdIUj8iUpBn7wniQVcGOHynIvagMw3Q6wu1+EqQ6X3UCFJST 1HfCYWBZrO8mZhnO6NaWEQcL0EBzZTup/sg0lkgjdcSaEbVnYBCDXibRpn7lcZGK MrsHzm6leR9tVbCB7IfT4nPmoWorkJOPcXRmE6kiRYKOKsdvX7p9leMz7ChTL7aF oCSjanO37sx3Vl1Qs8a0hdPO3slXso8/jEyDQEAgOo9SPPF1Eb6ymNIXu83ic/MC LmhFBlb7sjNXP+KCT9dMTSsw6+cYybCh+8Yq6hTgQQKBgQDesyPsWN/pzxT5qHni CngVnoRihK7JDJ2wMAdg853rLFrCn6I4u5jk9U3hDgxdq1N7vOfBtaUnGpeBHM1Q U0oUhukp81I3QyBFgUs1Bjsenu+rQi3zYELKKH/nuTRThKfUQhb5UDwkSKq69Ooc ln2grkOV+UR5nJ3e9aSZvbbXVQKBgQDNlkyso/qm06vzaRu7H6aakhgQb+nMA01z mj5SWimMjd/hv5Mrz3ts1UHqJwT7ElL12pQObDVocLfb5DgX7ttfy36q2OL1+7Pg AxY42lcmXt77olDq+PT4WMzkFbJ2XIeg7aavYIb0EoTxf1rLZNJ+g5gqAb0OCtsp 91NkdygXqQKBgG04kq/Bzt+O7oybMlvIIqkHu4nN5SM5isT0aUoFcTf74u9890S3 zP7NyEpOZ4YxFpqjRU7d1YfeJNvv0kpI7xYuLICkk3gC9frgtI/m5GvaK1Vk+cBZ P6iCQGjXjnA/qUgSuc3Aqh5pfUKAB6nJrQd3MDKHtCuowkytUPMN9nSZAoGAAIu7 nGG7EqJRPI404qRM3vAwXCrP5hjEJeBs9e8DWTovM/w8OcuNOla+nA6KdtgvnDN+ XSNwaNyTwGO0umuJ7ZEuvulggOKwMZIQhwodXR63XNere1Q54kbqFFjyZloMiiLX ZHPPJ+q8q5948D1OScOzrbjfdaAVwODFOekPFDECgYEAnGiC1mwF52JiG6RSwR7M iR1Q2bMJsUW3ofPgOX4diUvg4sihdCj4gmCoKy8Y/rhK9T4Ntti6GPFKqRtjWC7f ja52w2QQbsMYoxeGQoEG4AO92WkJW1Tmj/LufL8C3+Pun+TrSJGreIsMu955v/PF 00cvfSeAGKSc2bXBowyEQQ8= -----END PRIVATE KEY-----";
@@ -173,10 +189,15 @@ class OAuth2_GrantType_JWTBearerTest extends PHPUnit_Framework_TestCase
$exp = time() + 1000;
}
+ if(!$sub){
+ $sub = "testuser@ourdomain.com";
+ }
+
$params = array(
'iss' => $iss,
'exp' => $exp,
'iat' => time(),
+ 'sub' => $sub,
'aud' => 'http://myapp.com/oauth/auth',
'scope' => 'view_friends_list'
);
@@ -184,7 +205,7 @@ class OAuth2_GrantType_JWTBearerTest extends PHPUnit_Framework_TestCase
if ($nbf) {
$params['nbf'] = $nbf;
}
-
+
$jwtUtil = new OAuth2_Util_JWT();
return $jwtUtil->encode($params, $privateKey);
diff --git a/test/OAuth2/GrantType/RefreshTokenTest.php b/test/OAuth2/GrantType/RefreshTokenTest.php
index 7c23ca7..181c463 100644
--- a/test/OAuth2/GrantType/RefreshTokenTest.php
+++ b/test/OAuth2/GrantType/RefreshTokenTest.php
@@ -10,9 +10,9 @@ class OAuth2_GrantType_RefreshTokenTest extends PHPUnit_Framework_TestCase
$server->addGrantType(new OAuth2_GrantType_RefreshToken($this->storage));
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'refresh_token'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['grant_type'] = 'refresh_token'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
$server->grantAccessToken($request);
$response = $server->getResponse();
@@ -27,10 +27,10 @@ class OAuth2_GrantType_RefreshTokenTest extends PHPUnit_Framework_TestCase
$server->addGrantType(new OAuth2_GrantType_RefreshToken($this->storage));
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'refresh_token'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['refresh_token'] = 'fake-token'; // valid client secret
+ $request->request['grant_type'] = 'refresh_token'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['refresh_token'] = 'fake-token'; // valid client secret
$server->grantAccessToken($request);
$response = $server->getResponse();
@@ -45,17 +45,18 @@ class OAuth2_GrantType_RefreshTokenTest extends PHPUnit_Framework_TestCase
$server->addGrantType(new OAuth2_GrantType_RefreshToken($this->storage, array('always_issue_new_refresh_token' => true)));
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'refresh_token'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['refresh_token'] = 'test-refreshtoken'; // valid client secret
+ $request->server['HTTP_METHOD'] = 'POST';
+ $request->request['grant_type'] = 'refresh_token'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['refresh_token'] = 'test-refreshtoken'; // valid client secret
$token = $server->grantAccessToken($request);
$this->assertTrue(isset($token['refresh_token']), 'refresh token should always refresh');
$refresh_token = $this->storage->getRefreshToken($token['refresh_token']);
$this->assertNotNull($refresh_token);
$this->assertEquals($refresh_token['refresh_token'], $token['refresh_token']);
- $this->assertEquals($refresh_token['client_id'], $request->query('client_id'));
+ $this->assertEquals($refresh_token['client_id'], $request->request('client_id'));
$this->assertTrue($token['refresh_token'] != 'test-refreshtoken', 'the refresh token returned is not the one used');
$used_token = $this->storage->getRefreshToken('test-refreshtoken');
$this->assertNull($used_token, 'the refresh token used is no longer valid');
@@ -67,10 +68,10 @@ class OAuth2_GrantType_RefreshTokenTest extends PHPUnit_Framework_TestCase
$server->addGrantType(new OAuth2_GrantType_RefreshToken($this->storage, array('always_issue_new_refresh_token' => false)));
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'refresh_token'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['refresh_token'] = 'test-refreshtoken'; // valid client secret
+ $request->request['grant_type'] = 'refresh_token'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['refresh_token'] = 'test-refreshtoken'; // valid client secret
$token = $server->grantAccessToken($request);
$this->assertFalse(isset($token['refresh_token']), 'refresh token should not be returned');
@@ -85,4 +86,4 @@ class OAuth2_GrantType_RefreshTokenTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/GrantType/UserCredentialsTest.php b/test/OAuth2/GrantType/UserCredentialsTest.php
index 81dfe15..463baec 100644
--- a/test/OAuth2/GrantType/UserCredentialsTest.php
+++ b/test/OAuth2/GrantType/UserCredentialsTest.php
@@ -6,10 +6,10 @@ class OAuth2_GrantType_UserCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'password'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['password'] = 'testpass'; // valid password
+ $request->request['grant_type'] = 'password'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['password'] = 'testpass'; // valid password
$server->grantAccessToken($request);
$response = $server->getResponse();
@@ -22,10 +22,10 @@ class OAuth2_GrantType_UserCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'password'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['username'] = 'test-username'; // valid username
+ $request->request['grant_type'] = 'password'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['username'] = 'test-username'; // valid username
$server->grantAccessToken($request);
$response = $server->getResponse();
@@ -38,11 +38,11 @@ class OAuth2_GrantType_UserCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'password'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['username'] = 'fake-username'; // valid username
- $request->query['password'] = 'testpass'; // valid password
+ $request->request['grant_type'] = 'password'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['username'] = 'fake-username'; // valid username
+ $request->request['password'] = 'testpass'; // valid password
$ret = $server->grantAccessToken($request);
$response = $server->getResponse();
@@ -55,11 +55,11 @@ class OAuth2_GrantType_UserCredentialsTest extends PHPUnit_Framework_TestCase
{
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'password'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['username'] = 'test-username'; // valid username
- $request->query['password'] = 'fakepass'; // valid password
+ $request->request['grant_type'] = 'password'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['username'] = 'test-username'; // valid username
+ $request->request['password'] = 'fakepass'; // valid password
$ret = $server->grantAccessToken($request);
$response = $server->getResponse();
@@ -76,4 +76,4 @@ class OAuth2_GrantType_UserCredentialsTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/RequestTest.php b/test/OAuth2/RequestTest.php
index a362c2f..cd21f57 100644
--- a/test/OAuth2/RequestTest.php
+++ b/test/OAuth2/RequestTest.php
@@ -18,7 +18,7 @@ class OAuth2_RequestTest extends PHPUnit_Framework_TestCase
/*** make some valid requests ***/
// Valid Grant Request
- $request->setQuery(array(
+ $request->setPost(array(
'grant_type' => 'authorization_code',
'client_id' => 'Test Client ID',
'client_secret' => 'TestSecret',
@@ -40,4 +40,4 @@ class OAuth2_RequestTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/ResponseTest.php b/test/OAuth2/ResponseTest.php
index a6d733b..7a65434 100644
--- a/test/OAuth2/ResponseTest.php
+++ b/test/OAuth2/ResponseTest.php
@@ -12,4 +12,4 @@ class OAuth2_ResponseTest extends PHPUnit_Framework_TestCase
$string = $response->getResponseBody('xml');
$this->assertContains('<response><bar>foo</bar><oates>halland</oates></response>', $string);
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Server/Access/BasicValidationTest.php b/test/OAuth2/Server/Access/BasicValidationTest.php
index c599509..f7f75d5 100644
--- a/test/OAuth2/Server/Access/BasicValidationTest.php
+++ b/test/OAuth2/Server/Access/BasicValidationTest.php
@@ -161,4 +161,4 @@ class OAuth2_Server_Access_BasicValidationTest extends PHPUnit_Framework_TestCas
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Server/Authorize/BasicValidationTest.php b/test/OAuth2/Server/Authorize/BasicValidationTest.php
index acaeb92..127b9fe 100644
--- a/test/OAuth2/Server/Authorize/BasicValidationTest.php
+++ b/test/OAuth2/Server/Authorize/BasicValidationTest.php
@@ -104,6 +104,21 @@ class OAuth2_Server_Authorize_BasicValidationTest extends PHPUnit_Framework_Test
$this->assertEquals($query['error_description'], 'The state parameter is required');
}
+ public function testValidateRedirectUri()
+ {
+ $server = $this->getTestServer();
+ $request = OAuth2_Request::createFromGlobals();
+ $request->query['client_id'] = 'Test Client ID with Redirect Uri'; // valid client id
+ $request->query['redirect_uri'] = 'http://adobe.com'; // invalid redirect URI
+ $request->query['response_type'] = 'code';
+ $response = $server->handleAuthorizeRequest($request, true);
+
+ $this->assertEquals($response->getStatusCode(), 400);
+
+ $this->assertEquals($response->getParameter('error'), 'redirect_uri_mismatch');
+ $this->assertEquals($response->getParameter('error_description'), 'The redirect URI provided is missing or does not match');
+ }
+
private function getTestServer($config = array())
{
$storage = OAuth2_Storage_Bootstrap::getInstance()->getMemoryStorage();
@@ -114,4 +129,4 @@ class OAuth2_Server_Authorize_BasicValidationTest extends PHPUnit_Framework_Test
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Server/Authorize/CodeTest.php b/test/OAuth2/Server/Authorize/CodeTest.php
index 62ed80f..c099298 100644
--- a/test/OAuth2/Server/Authorize/CodeTest.php
+++ b/test/OAuth2/Server/Authorize/CodeTest.php
@@ -112,4 +112,4 @@ class OAuth2_Server_Authorize_CodeTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Server/Authorize/ImplicitTest.php b/test/OAuth2/Server/Authorize/ImplicitTest.php
index 27ba933..30dcb39 100644
--- a/test/OAuth2/Server/Authorize/ImplicitTest.php
+++ b/test/OAuth2/Server/Authorize/ImplicitTest.php
@@ -126,4 +126,4 @@ class OAuth2_Server_Authorize_ImplicitTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Server/Grant/BasicValidationTest.php b/test/OAuth2/Server/Grant/BasicValidationTest.php
index c834f04..b30c665 100644
--- a/test/OAuth2/Server/Grant/BasicValidationTest.php
+++ b/test/OAuth2/Server/Grant/BasicValidationTest.php
@@ -18,7 +18,7 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
// add the test parameters in memory
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'invalid_grant_type'; // invalid grant type
+ $request->request['grant_type'] = 'invalid_grant_type'; // invalid grant type
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -31,7 +31,7 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
// add the test parameters in memory
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -44,8 +44,8 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
// add the test parameters in memory
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -58,9 +58,9 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
// add the test parameters in memory
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
- $request->query['client_id'] = 'Fake Client ID'; // invalid client id
- $request->query['client_secret'] = 'Fake Client Secret'; // invalid client secret
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Fake Client ID'; // invalid client id
+ $request->request['client_secret'] = 'Fake Client Secret'; // invalid client secret
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -68,7 +68,7 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
$this->assertEquals($response->getParameter('error_description'), 'The client credentials are invalid');
// try again with a real client ID, but an invalid secret
- $request->query['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
$response = $server->handleGrantRequest($request);
$this->assertEquals($response->getStatusCode(), 400);
@@ -81,10 +81,10 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
// add the test parameters in memory
$server = $this->getTestServer();
$request = OAuth2_Request::createFromGlobals();
- $request->query['grant_type'] = 'authorization_code'; // valid grant type
- $request->query['client_id'] = 'Test Client ID'; // valid client id
- $request->query['client_secret'] = 'TestSecret'; // valid client secret
- $request->query['code'] = 'testcode'; // valid authorization code
+ $request->request['grant_type'] = 'authorization_code'; // valid grant type
+ $request->request['client_id'] = 'Test Client ID'; // valid client id
+ $request->request['client_secret'] = 'TestSecret'; // valid client secret
+ $request->request['code'] = 'testcode'; // valid authorization code
$response = $server->handleGrantRequest($request);
$this->assertTrue($response instanceof OAuth2_Response);
@@ -104,4 +104,4 @@ class OAuth2_Server_Grant_BasicValidationTest extends PHPUnit_Framework_TestCase
return $server;
}
-} \ No newline at end of file
+}
diff --git a/test/OAuth2/Storage/PdoTest.php b/test/OAuth2/Storage/PdoTest.php
index a61748b..31c389d 100644
--- a/test/OAuth2/Storage/PdoTest.php
+++ b/test/OAuth2/Storage/PdoTest.php
@@ -155,4 +155,4 @@ class OAuth2_Storage_PdoTest extends PHPUnit_Framework_TestCase
array($mysql),
);
}
-} \ No newline at end of file
+}
diff --git a/test/bootstrap.php b/test/bootstrap.php
index 02bcc90..ff91fc0 100644
--- a/test/bootstrap.php
+++ b/test/bootstrap.php
@@ -4,4 +4,4 @@ require_once(dirname(__FILE__).'/../src/OAuth2/Autoloader.php');
OAuth2_Autoloader::register();
// register test classes
-OAuth2_Autoloader::register(dirname(__FILE__).'/lib'); \ No newline at end of file
+OAuth2_Autoloader::register(dirname(__FILE__).'/lib');
diff --git a/test/config/storage.json b/test/config/storage.json
index 48541a1..8bd35e6 100644
--- a/test/config/storage.json
+++ b/test/config/storage.json
@@ -11,6 +11,10 @@
"client_credentials" : {
"Test Client ID": {
"secret": "TestSecret"
+ },
+ "Test Client ID with Redirect Uri": {
+ "secret": "TestSecret2",
+ "redirect_uri": "http://brentertainment.com"
}
},
"user_credentials" : {
@@ -46,6 +50,9 @@
},
"jwt": {
- "Test Client ID": "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstgzbq1Tyozg6Wn/ugyw ng4J2wPOaSJwPWlFFff92K60rQrrCDDUSVeuhC0+Tjn7Lq35gMZrsWazl3oj4KAH BBFZqBPejER0Z/t1wgZka97uooW2BclxUMjL6sFW92BLm2f2Po/SDjKdGRwt0+kd j2MgmdqIDu7KTNLPVS/3zk0Ln+Ett92pbODhUliYHkVFy/ZZtoX66lggLjZXGdBP 2pLx/cAR09B0m1QDBvkzGewmF6Hl0gXqKSBQel1vnR8Pp2c8Fjp3sDB65hiStXmf a6NpMZBAb4vBp39SyRrbXiNH7GbYoIiBBtgnhVg4zHAG6btsEyAtmVM0aMhn01TK HQIDAQAB -----END PUBLIC KEY----- "
+ "Test Client ID": {
+ "key": "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstgzbq1Tyozg6Wn/ugyw ng4J2wPOaSJwPWlFFff92K60rQrrCDDUSVeuhC0+Tjn7Lq35gMZrsWazl3oj4KAH BBFZqBPejER0Z/t1wgZka97uooW2BclxUMjL6sFW92BLm2f2Po/SDjKdGRwt0+kd j2MgmdqIDu7KTNLPVS/3zk0Ln+Ett92pbODhUliYHkVFy/ZZtoX66lggLjZXGdBP 2pLx/cAR09B0m1QDBvkzGewmF6Hl0gXqKSBQel1vnR8Pp2c8Fjp3sDB65hiStXmf a6NpMZBAb4vBp39SyRrbXiNH7GbYoIiBBtgnhVg4zHAG6btsEyAtmVM0aMhn01TK HQIDAQAB -----END PUBLIC KEY----- ",
+ "subject": "testuser@ourdomain.com"
+ }
}
} \ No newline at end of file
diff --git a/test/lib/OAuth2/Request/TestRequest.php b/test/lib/OAuth2/Request/TestRequest.php
index 623d139..4772e28 100644
--- a/test/lib/OAuth2/Request/TestRequest.php
+++ b/test/lib/OAuth2/Request/TestRequest.php
@@ -43,4 +43,10 @@ class OAuth2_Request_TestRequest implements OAuth2_RequestInterface
{
$this->query = $query;
}
-} \ No newline at end of file
+
+ public function setPost(array $post)
+ {
+ $this->server['HTTP_METHOD'] = 'POST';
+ $this->post = $post;
+ }
+}
diff --git a/test/lib/OAuth2/Storage/Bootstrap.php b/test/lib/OAuth2/Storage/Bootstrap.php
index 4a214b3..354a508 100644
--- a/test/lib/OAuth2/Storage/Bootstrap.php
+++ b/test/lib/OAuth2/Storage/Bootstrap.php
@@ -91,4 +91,4 @@ class OAuth2_Storage_Bootstrap
{
return dirname(__FILE__).'/../../../config/test.sqlite';
}
-} \ No newline at end of file
+}