-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the authbucket/oauth2-bundle package. | ||
* | ||
* (c) Wong Hoi Sing Edison <hswong3i@pantarei-design.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; | ||
|
||
use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface; | ||
use AuthBucket\OAuth2\ResourceType\ResourceTypeHandlerInterface; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class BarResourceTypeHandler implements ResourceTypeHandlerInterface | ||
{ | ||
public function handle( | ||
HttpKernelInterface $httpKernel, | ||
ModelManagerFactoryInterface $modelManagerFactory, | ||
$accessToken, | ||
array $options = array() | ||
) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the authbucket/oauth2-bundle package. | ||
* | ||
* (c) Wong Hoi Sing Edison <hswong3i@pantarei-design.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; | ||
|
||
class FooResourceTypeHandler | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the authbucket/oauth2-bundle package. | ||
* | ||
* (c) Wong Hoi Sing Edison <hswong3i@pantarei-design.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; | ||
|
||
use AuthBucket\OAuth2\ResourceType\ResourceTypeHandlerFactory; | ||
|
||
class ResourceTypeHandlerFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException | ||
*/ | ||
public function testNonExistsResourceTypeHandler() | ||
{ | ||
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(array( | ||
'foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\NonExistsResourceTypeHandler', | ||
)); | ||
$resourceTypeHandlerFactory->addResourceTypeHandler('foo', $responseTypeHandler); | ||
} | ||
|
||
/** | ||
* @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException | ||
*/ | ||
public function testBadAddResourceTypeHandler() | ||
{ | ||
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(array( | ||
'foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\FooResourceTypeHandler', | ||
)); | ||
$resourceTypeHandlerFactory->addResourceTypeHandler('foo', $responseTypeHandler); | ||
} | ||
|
||
/** | ||
* @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException | ||
*/ | ||
public function testBadGetResourceTypeHandler() | ||
{ | ||
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(array( | ||
'bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\BarResourceTypeHandler', | ||
)); | ||
$resourceTypeHandlerFactory->getResourceTypeHandler('foo'); | ||
} | ||
|
||
public function testGoodGetResourceTypeHandler() | ||
{ | ||
$resourceTypeHandlerFactory = new ResourceTypeHandlerFactory(array( | ||
'bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\BarResourceTypeHandler', | ||
)); | ||
$resourceTypeHandlerFactory->getResourceTypeHandler('bar'); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Tests/Security/Authentication/Provider/ResourceProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the authbucket/oauth2-bundle package. | ||
* | ||
* (c) Wong Hoi Sing Edison <hswong3i@pantarei-design.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Security\Authentication\Provider; | ||
|
||
use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ResourceProviderTest extends WebTestCase | ||
{ | ||
public function testNonCompatibileScope() | ||
{ | ||
$parameters = array( | ||
'debug_token' => 'bcc105b66698a64ed23c87b967885289', | ||
); | ||
$server = array( | ||
'HTTP_Authorization' => implode(' ', array('Bearer', 'bcc105b66698a64ed23c87b967885289')), | ||
); | ||
$client = $this->createClient(); | ||
$crawler = $client->request('GET', '/resource/debug/model', $parameters, array(), $server); | ||
$resourceResponse = json_decode($client->getResponse()->getContent(), true); | ||
$this->assertEquals('invalid_scope', $resourceResponse['error']); | ||
} | ||
|
||
public function testEnoughScope() | ||
{ | ||
$parameters = array( | ||
'debug_token' => 'eeb5aa92bbb4b56373b9e0d00bc02d93', | ||
); | ||
$server = array( | ||
'HTTP_Authorization' => implode(' ', array('Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93')), | ||
); | ||
$client = $this->createClient(); | ||
$crawler = $client->request('GET', '/resource/debug/model', $parameters, array(), $server); | ||
$resourceResponse = json_decode($client->getResponse()->getContent(), true); | ||
$this->assertEquals('demousername1', $resourceResponse['username']); | ||
} | ||
|
||
public function testMoreScope() | ||
{ | ||
$parameters = array( | ||
'debug_token' => 'ba2e8d1f54ed3e3d96935796576f1a06', | ||
); | ||
$server = array( | ||
'HTTP_Authorization' => implode(' ', array('Bearer', 'ba2e8d1f54ed3e3d96935796576f1a06')), | ||
); | ||
$client = $this->createClient(); | ||
$crawler = $client->request('GET', '/resource/debug/model', $parameters, array(), $server); | ||
$resourceResponse = json_decode($client->getResponse()->getContent(), true); | ||
$this->assertEquals('demousername1', $resourceResponse['username']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters