You are here

public function LdapAuthenticationTestCase::testSSOUserLogon in Lightweight Directory Access Protocol (LDAP) 7.2

LDAP Authentication Exclusive Mode User Logon Test (ids = LDAP_authen.EM.ULT.*)

File

ldap_authentication/tests/ldap_authentication.test, line 350

Class

LdapAuthenticationTestCase
LdapAuthenticationTestCase.

Code

public function testSSOUserLogon() {
  module_enable([
    'ldap_sso',
    'ldap_help',
  ]);
  $sid = 'activedirectory1';
  $testid = 'SSOUserLogon3';
  $sids = [
    $sid,
  ];
  $this
    ->prepTestData(LDAP_TEST_LDAP_NAME, $sids, 'ad_authentication', 'SSOUserLogon');
  $this
    ->setSsoServerEnvironment('REMOTE_USER', 'hpotter', 'mod_auth_sspi', TRUE);
  $this
    ->drupalGet('user/logout');
  $this
    ->drupalGet('user');

  // Just test that the setup works.
  $authenticationConf = new LdapAuthenticationConfAdmin();
  $this
    ->assertTrue(ldap_servers_get_globals('_SERVER', 'REMOTE_USER', TRUE) == 'hpotter', '$_SERVER[REMOTE_USER] and $_SERVER[REDIRECT_REMOTE_USER] set properly for test with remote server ' . ldap_servers_get_globals('_SERVER', 'REMOTE_ADDR'), $testid);
  $setup_success = $authenticationConf->ssoEnabled == TRUE && $authenticationConf->ssoRemoteUserStripDomainName == FALSE && $authenticationConf->seamlessLogin == TRUE && $authenticationConf->ldapImplementation == 'mod_auth_sspi';
  $this
    ->assertTrue($setup_success, 'setup ldap sso test worked ', $testid);
  if (!$setup_success) {
    debug('authenticationConf');
    debug($authenticationConf);
  }
  $ldap_servers = ldap_servers_get_servers($sid, 'enabled');
  $this
    ->assertTrue(count($ldap_servers) == 1, ' ldap_authentication test server setup successful', $testid);
  $hpotter_drupal = user_load_by_name('hpotter');
  $ldap_user_conf = ldap_user_conf('admin', TRUE);
  $hpotter_ldap = $ldap_user_conf
    ->getProvisionRelatedLdapEntry($hpotter_drupal);
  debug('hpotter ldap entry');
  debug($hpotter_drupal);
  $tests = [
    'dontstripnames' => [
      'sso_name' => 'hpotter',
    ],
    'stripnames' => [
      'sso_name' => 'hpotter@hogwarts',
    ],
  ];
  foreach ($tests as $testid => $conf) {
    foreach ([
      'REMOTE_USER',
    ] as $server_var_key) {

      // ,'user/login/sso'.
      foreach ([
        'user',
      ] as $test_path) {

        // , 'mod_auth_kerb'.
        foreach ([
          'mod_auth_sspi',
          'mod_auth_kerb',
        ] as $ldapImplementation) {

          // , FALSE.
          foreach ([
            TRUE,
            FALSE,
          ] as $seamlessLogin) {
            $sso_name = $conf['sso_name'];
            $this->ldapTestId = "testSSO._SERVER-key={$server_var_key} sso_name={$sso_name} path={$test_path} ldapImplementation={$ldapImplementation} seamlessLogin={$seamlessLogin}";
            $ldapAuthenticationConf = $this
              ->setSsoServerEnvironment($server_var_key, $sso_name, $ldapImplementation, $seamlessLogin);
            $this
              ->drupalGet($test_path);

            // @FIXME: Broken test
            // $this->assertText(t('Member for'), 'Successful logon.', $this->ldapTestId);
            $this
              ->drupalGet('user/logout');
          }
        }
      }
    }
  }
}