class SimpleOauthAuthenticationTest in Simple OAuth (OAuth2) & OpenID Connect 8
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.2 tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php \Drupal\Tests\simple_oauth\Unit\Authentication\Provider\SimpleOauthAuthenticationTest
- 8.3 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
Class SimpleOauthAuthenticationTest.
@package Drupal\Tests\simple_oauth\Unit\Authentication\Provider
@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 19
Namespace
Drupal\Tests\simple_oauth\Unit\Authentication\ProviderView source
class SimpleOauthAuthenticationTest extends UnitTestCase {
/**
* The authentication provider.
*
* @var \Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProviderInterface
*/
protected $provider;
/**
* @covers ::getTokenValue
* @covers ::applies
*
* @dataProvider getTokenValueProvider
*/
public function testGetTokenValue(Request $request, $token) {
$this
->assertSame($token, $this->provider
->getTokenValue($request));
}
public function getTokenValueProvider() {
$data = [];
// 1. Authentication header.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Bearer ' . $token);
$data[] = [
$request,
$token,
];
// 2. Authentication header. Fail: wrong token.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Bearer fail--' . $token);
$data[] = [
$request,
'fail--' . $token,
];
// 3. Authentication header. Fail: no token.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$data[] = [
$request,
NULL,
];
// 4. Form encoded parameter.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request
->setMethod(Request::METHOD_POST);
$request->headers
->set('Content-Type', 'application/x-www-form-urlencoded');
$request->request
->set('access_token', $token);
$data[] = [
$request,
$token,
];
// 5. Form encoded parameter. Fail: missing content type.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request
->setMethod(Request::METHOD_POST);
$request->request
->set('access_token', $token);
$data[] = [
$request,
NULL,
];
// 6. Form encoded parameter. Fail: missing token.
$request = new Request();
$request
->setMethod(Request::METHOD_POST);
$request->headers
->set('Content-Type', 'application/x-www-form-urlencoded');
$data[] = [
$request,
NULL,
];
// 7. Form encoded parameter. Fail: wrong method.
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request
->setMethod(Request::METHOD_GET);
$request->headers
->set('Content-Type', 'application/x-www-form-urlencoded');
$request->request
->set('access_token', $token);
$data[] = [
$request,
NULL,
];
return $data;
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$config_factory = $this
->prophesize(ConfigFactoryInterface::class);
$entity_manager = $this
->prophesize(EntityManagerInterface::class);
$this->provider = new SimpleOauthAuthenticationProvider($config_factory
->reveal(), $entity_manager
->reveal());
}
}
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 authentication provider. | |
SimpleOauthAuthenticationTest:: |
public | function | ||
SimpleOauthAuthenticationTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SimpleOauthAuthenticationTest:: |
public | function | @covers ::getTokenValue @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. |