You are here

function cas_test_cas_phpcas_alter in CAS 7

Same name and namespace in other branches
  1. 6.3 tests/cas_test.module \cas_test_cas_phpcas_alter()

File

tests/cas_test.module, line 11
Dummy module implementing a CAS Server.

Code

function cas_test_cas_phpcas_alter() {

  // Set the User-Agent field which is used by SimpleTest to identify testing
  // requests.
  $test_info =& $GLOBALS['drupal_test_info'];
  if (!empty($test_info['test_run_id'])) {
    phpCAS::setExtraCurlOption(CURLOPT_USERAGENT, drupal_generate_test_ua($test_info['test_run_id']));
  }

  // Set all CAS server URLs manually, as this is the only way to specify an
  // HTTP (i.e., not HTTPS) connection.
  $service_url = phpCAS::getServiceURL();
  phpCAS::setServerLoginURL(url('cas_test/login', array(
    'query' => array(
      'service' => $service_url,
    ),
    'absolute' => TRUE,
  )));
  switch (variable_get('cas_version', '3.0')) {
    case CAS_VERSION_1_0:
      phpCAS::setServerServiceValidateURL(url('cas_test/validate', array(
        'absolute' => TRUE,
      )));
      break;
    case CAS_VERSION_2_0:
      phpCAS::setServerServiceValidateURL(url('cas_test/serviceValidate', array(
        'absolute' => TRUE,
      )));
      phpCAS::setServerProxyValidateURL(url('cas_test/proxyValidate', array(
        'absolute' => TRUE,
      )));
      break;
    case CAS_VERSION_3_0:
      phpCAS::setServerServiceValidateURL(url('cas_test/p3/serviceValidate', array(
        'absolute' => TRUE,
      )));
      phpCAS::setServerProxyValidateURL(url('cas_test/p3/proxyValidate', array(
        'absolute' => TRUE,
      )));
      break;
    default:
      throw new Exception('Unknown CAS server version.');
      break;
  }
  phpCAS::setServerLogoutURL(url('cas_test/logout', array(
    'absolute' => TRUE,
  )));

  // SAML not currently implemented.
  // phpCAS::setServerSamlValidateURL(url('cas_test/samlValidate', array('absolute' => TRUE)));
}