public function CasValidatorTest::validateTicketExceptionDataProvider in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Service/CasValidatorTest.php \Drupal\Tests\cas\Unit\Service\CasValidatorTest::validateTicketExceptionDataProvider()
Provides parameters and return values for testValidateTicketException.
Return value
array Parameters and return values.
See also
\Drupal\Tests\cas\Unit\Service\CasValidatorTest::testValidateTicketException
File
- tests/
src/ Unit/ Service/ CasValidatorTest.php, line 350
Class
- CasValidatorTest
- CasValidator unit tests.
Namespace
Drupal\Tests\cas\Unit\ServiceCode
public function validateTicketExceptionDataProvider() {
/* There are nine different exception messages that can occur. We test for
* each one. Currently, they are all of type 'CasValidateException', so we
* set that up front. If that changes in the future, we can rework this bit
* without changing the function signature.
*/
$exception_type = '\\Drupal\\cas\\Exception\\CasValidateException';
/* The first exception is actually a 'recasting' of an http client
* exception.
*/
$params[] = [
'2.0',
'',
FALSE,
FALSE,
'',
$exception_type,
'External http client exception',
TRUE,
];
/* Protocol version 1 can throw two exceptions: 'no' text is found, or
* 'yes' text is not found (in that order).
*/
$params[] = [
'1.0',
"no\n\n",
FALSE,
FALSE,
'',
$exception_type,
'Ticket did not pass validation.',
FALSE,
];
$params[] = [
'1.0',
"Foo\nBar?\n",
FALSE,
FALSE,
'',
$exception_type,
'Malformed response from CAS server.',
FALSE,
];
// Protocol version 2: Malformed XML.
$params[] = [
'2.0',
"<> </ </> <<",
FALSE,
FALSE,
'',
$exception_type,
'XML from CAS server is not valid.',
FALSE,
];
// Protocol version 2: Authentication failure.
$ticket = $this
->randomMachineName(24);
$params[] = [
'2.0',
'<cas:serviceResponse xmlns:cas="http://example.com/cas">
<cas:authenticationFailure code="INVALID_TICKET">
Ticket ' . $ticket . ' not recognized
</cas:authenticationFailure>
</cas:serviceResponse>',
FALSE,
FALSE,
'',
$exception_type,
"Error Code INVALID_TICKET: Ticket {$ticket} not recognized",
FALSE,
];
// Protocol version 2: Neither authentication failure nor authentication
// succes found.
$params[] = [
'2.0',
"<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n <cas:authentication>\n Username\n </cas:authentication>\n </cas:serviceResponse>",
FALSE,
FALSE,
'',
$exception_type,
"XML from CAS server is not valid.",
FALSE,
];
// Protocol version 2: No user specified in authenticationSuccess.
$params[] = [
'2.0',
"<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n <cas:authenticationSuccess>\n Username\n </cas:authenticationSuccess>\n </cas:serviceResponse>",
FALSE,
FALSE,
'',
$exception_type,
"No user found in ticket validation response.",
FALSE,
];
// Protocol version 2: Proxy chain mismatch.
$proxy_chains = '/https:\\/\\/example\\.com/ /https:\\/\\/foo\\.com/' . PHP_EOL . '/https:\\/\\/bar\\.com/';
$params[] = [
'2.0',
"<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n <cas:authenticationSuccess>\n <cas:user>username</cas:user>\n <cas:proxies>\n <cas:proxy>https://example.com</cas:proxy>\n <cas:proxy>https://bar.com</cas:proxy>\n </cas:proxies>\n </cas:authenticationSuccess>\n </cas:serviceResponse>",
FALSE,
TRUE,
$proxy_chains,
$exception_type,
"Proxy chain did not match allowed list.",
FALSE,
];
// Protocol version 2: Proxy chain mismatch with non-regex proxy chain.
$proxy_chains = 'https://bar.com /https:\\/\\/foo\\.com/' . PHP_EOL . '/https:\\/\\/bar\\.com/';
$params[] = [
'2.0',
"<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n <cas:authenticationSuccess>\n <cas:user>username</cas:user>\n <cas:proxies>\n <cas:proxy>https://example.com</cas:proxy>\n <cas:proxy>https://bar.com</cas:proxy>\n </cas:proxies>\n </cas:authenticationSuccess>\n </cas:serviceResponse>",
FALSE,
TRUE,
$proxy_chains,
$exception_type,
"Proxy chain did not match allowed list.",
FALSE,
];
// Protocol version 2: No PGTIOU provided when initialized as proxy.
$params[] = [
'2.0',
"<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n <cas:authenticationSuccess>\n <cas:user>username</cas:user>\n </cas:authenticationSuccess>\n </cas:serviceResponse>",
TRUE,
FALSE,
'',
$exception_type,
"Proxy initialized, but no PGTIOU provided in response.",
FALSE,
];
// Unknown protocol version.
$params[] = [
'foobarbaz',
"<text>",
FALSE,
FALSE,
'',
$exception_type,
"Unknown CAS protocol version specified: foobarbaz",
FALSE,
];
return $params;
}