public function CasValidatorTest::testValidateTicketException in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Service/CasValidatorTest.php \Drupal\Tests\cas\Unit\Service\CasValidatorTest::testValidateTicketException()
Test validation failure conditions for the correct exceptions.
@covers ::validateTicket @covers ::validateVersion1 @covers ::validateVersion2 @covers ::verifyProxyChain @covers ::parseAllowedProxyChains @covers ::parseServerProxyChain
@dataProvider validateTicketExceptionDataProvider
File
- tests/
src/ Unit/ Service/ CasValidatorTest.php, line 305
Class
- CasValidatorTest
- CasValidator unit tests.
Namespace
Drupal\Tests\cas\Unit\ServiceCode
public function testValidateTicketException($version, $response, $is_proxy, $can_be_proxied, $proxy_chains, $exception, $exception_message, $http_client_exception) {
if ($http_client_exception) {
$mock = new MockHandler([
new RequestException($exception_message, new Request('GET', 'test')),
]);
}
else {
$mock = new MockHandler([
new Response(200, [], $response),
]);
}
$handler = HandlerStack::create($mock);
$httpClient = new Client([
'handler' => $handler,
]);
$casHelper = $this
->getMockBuilder('\\Drupal\\cas\\Service\\CasHelper')
->disableOriginalConstructor()
->getMock();
$configFactory = $this
->getConfigFactoryStub([
'cas.settings' => [
'server.hostname' => 'example.com',
'server.port' => 443,
'server.path' => '/cas',
'server.version' => $version,
'proxy.initialize' => $is_proxy,
'proxy.can_be_proxied' => $can_be_proxied,
'proxy.proxy_chains' => $proxy_chains,
],
]);
$urlGenerator = $this
->createMock('\\Drupal\\Core\\Routing\\UrlGeneratorInterface');
$casValidator = new CasValidator($httpClient, $casHelper, $configFactory, $urlGenerator, $this->eventDispatcher);
$this
->expectException($exception, $exception_message);
$ticket = $this
->randomMachineName(24);
$casValidator
->validateTicket($ticket, []);
}