You are here

public function CasProxyHelperTest::proxyAuthenticateExceptionDataProvider in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Service/CasProxyHelperTest.php \Drupal\Tests\cas\Unit\Service\CasProxyHelperTest::proxyAuthenticateExceptionDataProvider()

Provides parameters and exceptions for testProxyAuthenticateException.

Return value

array Parameters and exceptions.

See also

\Drupal\Tests\cas\Unit\Service\CasProxyHelperTest::testProxyAuthenticateException

File

tests/src/Unit/Service/CasProxyHelperTest.php, line 236

Class

CasProxyHelperTest
CasHelper unit tests.

Namespace

Drupal\Tests\cas\Unit\Service

Code

public function proxyAuthenticateExceptionDataProvider() {
  $target_service = 'https://example.com';
  $exception_type = '\\Drupal\\cas\\Exception\\CasProxyException';

  // Exception case 1: not configured as proxy.
  $params[] = [
    FALSE,
    TRUE,
    $target_service,
    '',
    FALSE,
    $exception_type,
    'Session state not sufficient for proxying.',
  ];

  // Exception case 2: session pgt not set.
  $params[] = [
    TRUE,
    FALSE,
    $target_service,
    '',
    FALSE,
    $exception_type,
    'Session state not sufficient for proxying.',
  ];

  // Exception case 3: http client exception from proxy app.
  $proxy_ticket = $this
    ->randomMachineName(24);
  $response = "<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n        <cas:proxySuccess>\n          <cas:proxyTicket>PT-{$proxy_ticket}</cas:proxyTicket>\n        </cas:proxySuccess>\n      </cas:serviceResponse>";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    'client',
    $exception_type,
    '',
  ];

  // Exception case 4: http client exception from CAS Server.
  $proxy_ticket = $this
    ->randomMachineName(24);
  $response = "<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n        <cas:proxySuccess>\n          <cas:proxyTicket>PT-{$proxy_ticket}</cas:proxyTicket>\n        </cas:proxySuccess>\n      </cas:serviceResponse>";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    'server',
    $exception_type,
    '',
  ];

  // Exception case 5: non-XML response from CAS server.
  $response = "<> </> </ <..";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    FALSE,
    $exception_type,
    'CAS Server returned non-XML response.',
  ];

  // Exception case 6: CAS Server rejected ticket.
  $response = "<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n         <cas:proxyFailure code=\"INVALID_REQUEST\">\n           'pgt' and 'targetService' parameters are both required\n         </cas:proxyFailure>\n       </cas:serviceResponse>";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    FALSE,
    $exception_type,
    'CAS Server rejected proxy request.',
  ];

  // Exception case 7: Neither proxyFailure nor proxySuccess specified.
  $response = "<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n         <cas:proxy code=\"INVALID_REQUEST\">\n         </cas:proxy>\n       </cas:serviceResponse>";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    FALSE,
    $exception_type,
    'CAS Server returned malformed response.',
  ];

  // Exception case 8: Malformed ticket.
  $response = "<cas:serviceResponse xmlns:cas='http://example.com/cas'>\n        <cas:proxySuccess>\n        </cas:proxySuccess>\n       </cas:serviceResponse>";
  $params[] = [
    TRUE,
    TRUE,
    $target_service,
    $response,
    FALSE,
    $exception_type,
    'CAS Server provided invalid or malformed ticket.',
  ];
  return $params;
}