SimpleOauthAuthenticationTest.php in Simple OAuth (OAuth2) & OpenID Connect 8.2
File
tests/src/Unit/Authentication/Provider/SimpleOauthAuthenticationTest.php
View source
<?php
namespace Drupal\Tests\simple_oauth\Unit\Authentication\Provider;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider;
use Drupal\simple_oauth\Server\ResourceServerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
class SimpleOauthAuthenticationTest extends UnitTestCase {
protected $provider;
protected function setUp() {
parent::setUp();
$resource_server = $this
->prophesize(ResourceServerInterface::class);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->provider = new SimpleOauthAuthenticationProvider($resource_server
->reveal(), $entity_type_manager
->reveal());
}
public function testHasTokenValue(Request $request, $has_token) {
$this
->assertSame($has_token, $this->provider
->hasTokenValue($request));
}
public function hasTokenValueProvider() {
$data = [];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Bearer ' . $token);
$data[] = [
$request,
TRUE,
];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', ' Bearer ' . $token);
$data[] = [
$request,
TRUE,
];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Foo' . $token);
$data[] = [
$request,
FALSE,
];
$request = new Request();
$data[] = [
$request,
FALSE,
];
return $data;
}
}