You are here

function cas_test_single_sign_out in CAS 7

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

Sign out the specified CAS user.

Parameters

$cas_user:

2 calls to cas_test_single_sign_out()
CasSingleSignOutTestCase::testSingleSignOut in ./cas.test
CasSingleSignOutTestCase::testSingleSignOutDoubleEncode in ./cas.test

File

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

Code

function cas_test_single_sign_out($cas_name, $double_encode = FALSE) {
  $sso = variable_get('cas_test_sso', array());
  foreach ($sso[$cas_name] as $service => $tickets) {
    foreach ($tickets as $ticket) {

      // Generate posting:
      $data = array(
        'logoutRequest' => t("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"!id\" Version=\"2.0\" IssueInstant=\"!time\">\n<saml:NameID>@NOT_USED@</saml:NameID>\n<samlp:SessionIndex>!ticket</samlp:SessionIndex>\n</samlp:LogoutRequest>", array(
          '!id' => user_password(10),
          '!time' => time(),
          '!ticket' => $ticket,
        )),
      );
      if ($double_encode) {

        // Certain CAS servers urlencode the logoutRequest.
        $data['logoutRequest'] = urlencode($data['logoutRequest']);
      }

      // Sign out the user.
      $options = array(
        'method' => 'POST',
        'headers' => array(
          'Content-Type' => 'application/x-www-form-urlencoded',
        ),
        'data' => drupal_http_build_query($data),
      );
      drupal_http_request($service, $options);
    }
  }
  unset($sso[$cas_name]);
  variable_set('cas_test_sso', $sso);
}