From fb518715ce89dc3609e754994838f3b221b953e7 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 21 Mar 2013 16:25:44 +0000 Subject: [PATCH] Updated authserver tests --- tests/authorization/AuthServerTest.php | 56 +++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/tests/authorization/AuthServerTest.php b/tests/authorization/AuthServerTest.php index 8a83faff..bf534b64 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -103,10 +103,10 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertFalse($v); } - public function test_defaultScope() + public function test_setDefaultScope() { $a = $this->returnDefault(); - $a->defaultScope('test.default'); + $a->setDefaultScope('test.default'); $reflector = new ReflectionClass($a); $requestProperty = $reflector->getProperty('defaultScope'); @@ -116,6 +116,13 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertEquals('test.default', $v); } + public function test_getDefaultScope() + { + $a = $this->returnDefault(); + $a->setDefaultScope('test.default'); + $this->assertEquals('test.default', $a->getDefaultScope()); + } + public function test_requireStateParam() { $a = $this->returnDefault(); @@ -195,6 +202,20 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase )); } + /** + * @expectedException OAuth2\Exception\ClientException + * @expectedExceptionCode 0 + */ + public function test_checkAuthoriseParams_noRequiredState() + { + $a = $this->returnDefault(); + $a->requireStateParam(true); + $a->checkAuthoriseParams(array( + 'client_id' => 1234, + 'redirect_uri' => 'http://foo/redirect' + )); + } + /** * @expectedException OAuth2\Exception\ClientException * @expectedExceptionCode 8 @@ -275,6 +296,37 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase )); } + public function test_checkAuthoriseParams_defaultScope() + { + $this->client->shouldReceive('getClient')->andReturn(array( + 'client_id' => 1234, + 'client_secret' => 5678, + 'redirect_uri' => 'http://foo/redirect', + 'name' => 'Example Client' + )); + + $this->scope->shouldReceive('getScope')->andReturn(array( + 'id' => 1, + 'scope' => 'foo', + 'name' => 'Foo Name', + 'description' => 'Foo Name Description' + )); + + $a = $this->returnDefault(); + $a->addGrantType(new OAuth2\Grant\AuthCode($a)); + $a->setDefaultScope('test.scope'); + $a->requireScopeParam(false); + + $params = $a->checkAuthoriseParams(array( + 'client_id' => 1234, + 'redirect_uri' => 'http://foo/redirect', + 'response_type' => 'code', + 'scope' => '' + )); + + $this->assertArrayHasKey('scopes', $params); + } + /** * @expectedException OAuth2\Exception\ClientException * @expectedExceptionCode 4