View source
<?php
namespace Drupal\Tests\simple_oauth\Unit\Authentication\Provider;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\simple_oauth\Authentication\Provider\SimpleOauthAuthenticationProvider;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
class SimpleOauthAuthenticationTest extends UnitTestCase {
protected $provider;
public function testGetTokenValue(Request $request, $token) {
$this
->assertSame($token, $this->provider
->getTokenValue($request));
}
public function getTokenValueProvider() {
$data = [];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Bearer ' . $token);
$data[] = [
$request,
$token,
];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request->headers
->set('Authorization', 'Bearer fail--' . $token);
$data[] = [
$request,
'fail--' . $token,
];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$data[] = [
$request,
NULL,
];
$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,
];
$token = $this
->getRandomGenerator()
->name();
$request = new Request();
$request
->setMethod(Request::METHOD_POST);
$request->request
->set('access_token', $token);
$data[] = [
$request,
NULL,
];
$request = new Request();
$request
->setMethod(Request::METHOD_POST);
$request->headers
->set('Content-Type', 'application/x-www-form-urlencoded');
$data[] = [
$request,
NULL,
];
$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;
}
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());
}
}