public function CasProxyHelperTest::testProxyAuthenticateException in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Service/CasProxyHelperTest.php \Drupal\Tests\cas\Unit\Service\CasProxyHelperTest::testProxyAuthenticateException()
Test the possible exceptions from proxy authentication.
@covers ::proxyAuthenticate @covers ::getServerProxyURL @covers ::parseProxyTicket
@dataProvider proxyAuthenticateExceptionDataProvider
Parameters
bool $is_proxy: expected isProxy method return value.
string $pgt_set: Value for pgt_set session parameter.
string $target_service: Target service.
string $response: Expected response data.
string $client_exception: Expected exception data.
string $exception_type: Expected exception type.
string $exception_message: Expected exception message.
File
- tests/
src/ Unit/ Service/ CasProxyHelperTest.php, line 187
Class
- CasProxyHelperTest
- CasHelper unit tests.
Namespace
Drupal\Tests\cas\Unit\ServiceCode
public function testProxyAuthenticateException($is_proxy, $pgt_set, $target_service, $response, $client_exception, $exception_type, $exception_message) {
if ($pgt_set) {
// Set up the fake pgt in the session.
$this->session
->set('cas_pgt', $this
->randomMachineName(24));
}
// Set up properties so the http client callback knows about them.
$cookie_value = $this
->randomMachineName(24);
$configFactory = $this
->getConfigFactoryStub([
'cas.settings' => [
'server.hostname' => 'example-server.com',
'server.port' => 443,
'server.path' => '/cas',
'proxy.initialize' => $is_proxy,
],
]);
if ($client_exception == 'server') {
$code = 404;
}
else {
$code = 200;
}
if ($client_exception == 'client') {
$secondResponse = new Response(404);
}
else {
$secondResponse = new Response(200, [
'Content-type' => 'text/html',
'Set-Cookie' => 'SESSION=' . $cookie_value,
]);
}
$mock = new MockHandler([
new Response($code, [], $response),
$secondResponse,
]);
$handler = HandlerStack::create($mock);
$httpClient = new Client([
'handler' => $handler,
]);
$casProxyHelper = new CasProxyHelper($httpClient, $this->casHelper, $this->session, $configFactory, $this->database);
$this
->expectException($exception_type, $exception_message);
$casProxyHelper
->proxyAuthenticate($target_service);
}