class SimpleOauthAuthenticationTest in Simple OAuth (OAuth2) & OpenID Connect 8.3
Same name and namespace in other branches
- 8.4 tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
- 8 tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
- 8.2 tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
- 5.x tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
@coversDefaultClass \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider @group simple_oauth
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
Expanded class hierarchy of SimpleOauthAuthenticationTest
File
- tests/
src/ Unit/ Authentication/ Provider/ SimpleOauthAuthenticationTest.php, line 17
Namespace
Drupal\Tests\simple_oauth\Unit\Authentication\ProviderView source
class SimpleOauthAuthenticationTest extends UnitTestCase {
/**
* The authentication provider.
*
* @var \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider
*/
protected $provider;
/**
* The OAuth page cache request policy.
*
* @var \Drupal\simple_oauth\PageCache\SimpleOauthRequestPolicyInterface
*/
protected $oauthPageCacheRequestPolicy;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$resource_server = $this
->prophesize(ResourceServerInterface::class);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->oauthPageCacheRequestPolicy = new DisallowSimpleOauthRequests();
$this->provider = new SimpleOauthAuthenticationProvider($resource_server
->reveal(), $entity_type_manager
->reveal(), $this->oauthPageCacheRequestPolicy);
}
/**
* @covers ::applies
*
* @dataProvider hasTokenValueProvider
*/
public function testHasTokenValue($authorization, $has_token) {
$request = new Request();
if ($authorization !== NULL) {
$request->headers
->set('Authorization', $authorization);
}
$this
->assertSame($has_token, $this->provider
->applies($request));
$this
->assertSame($has_token ? RequestPolicyInterface::DENY : NULL, $this->oauthPageCacheRequestPolicy
->check($request));
}
public function hasTokenValueProvider() {
$token = $this
->getRandomGenerator()
->name();
$data = [];
// 1. Authentication header.
$data[] = [
'Bearer ' . $token,
TRUE,
];
// 2. Authentication header. Trailing white spaces.
$data[] = [
' Bearer ' . $token,
TRUE,
];
// 3. Authentication header. No white spaces.
$data[] = [
'Foo' . $token,
FALSE,
];
// 4. Authentication header. Empty value.
$data[] = [
'',
FALSE,
];
// 5. Authentication header. Fail: no token.
$data[] = [
NULL,
FALSE,
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SimpleOauthAuthenticationTest:: |
protected | property | The OAuth page cache request policy. | |
SimpleOauthAuthenticationTest:: |
protected | property | The authentication provider. | |
SimpleOauthAuthenticationTest:: |
public | function | ||
SimpleOauthAuthenticationTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SimpleOauthAuthenticationTest:: |
public | function | @covers ::applies | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |