You are here

function LdapAuthenticationTestCase::testExclusiveModeUserLogon in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_authentication/tests/ldap_authentication.test \LdapAuthenticationTestCase::testExclusiveModeUserLogon()
  2. 7.2 ldap_authentication/tests/ldap_authentication.test \LdapAuthenticationTestCase::testExclusiveModeUserLogon()

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

File

ldap_authentication/tests/ldap_authentication.test, line 222

Class

LdapAuthenticationTestCase

Code

function testExclusiveModeUserLogon() {

  // TODO: Fix failing tests, excluding to make branch pass.
  return;
  $sid = 'ldapauthen1';
  $testid = 'ExclusiveModeUserLogon';
  $this
    ->prepTestData($sid, $testid);
  $ldap_servers = ldap_servers_get_servers($sid, 'enabled');
  $this
    ->assertTrue(count($ldap_servers) == 1, ' ldap_authentication test server setup successful', $testid);

  /**
   * LDAP_authen.EM.ULT.user1.goodpwd -- result: Successful logon as user 1
   */
  $user1 = user_load(1);
  $password = $this
    ->randomString(20);
  require_once DRUPAL_ROOT . '/includes/password.inc';
  $account = array(
    'name' => $user1->name,
    'pass' => user_hash_password(trim($password)),
  );
  db_update('users')
    ->fields($account)
    ->condition('uid', 1)
    ->execute();
  $edit = array(
    'name' => $user1->name,
    'pass' => $password,
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Member for'), 'User 1 successfully authenticated', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.EM.ULT.user1.badpwd  -- result: Drupal logon error message. **/
  $edit = array(
    'name' => $user1->name,
    'pass' => 'mydabpassword',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'), 'User 1 failed with bad password', $testid);
  $this
    ->drupalLogout();

  /** LDAP_authen.EM.ULT.drupal.goodpwd - result: failed logon **/
  $drupal_user = $this
    ->drupalCreateUser();
  $raw_pass = $drupal_user->pass_raw;
  $edit = array(
    'name' => $drupal_user->name,
    'pass' => $raw_pass,
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'), 'Drupal user successfully authenticated', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.EM.ULT.drupal.badpwd - result: Drupal logon error message. **/
  $edit = array(
    'name' => $drupal_user->name,
    'pass' => 'mydabpassword',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'), 'Drupal user with bad password failed to authenticate.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.EM.ULT.ldap.newaccount.badpwd - result: Drupal logon error message. **/
  $edit = array(
    'name' => 'jkool',
    'pass' => 'mydabpassword',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'), 'New Ldap user with bad password failed to authenticate.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.EM.ULT.ldap.newaccount.goodpwd - result: Successful logon, with user record created and authmapped to ldap **/
  $edit = array(
    'name' => 'jkool',
    'pass' => 'goodpwd',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Member for'), 'New Ldap user with good password authenticated.');
  $this
    ->assertTrue($this->testFunctions
    ->ldapUserIsAuthmapped('jkool'), 'Ldap user properly authmapped.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.EM.ULT.existingacct.badpwd - result: Drupal logon error message. **/
  $edit = array(
    'name' => 'jkool',
    'pass' => 'mydabpassword',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'), 'Existing Ldap user with bad password failed to authenticate.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.MM.ULT.existingacct.goodpwd - result: Successful logon. **/
  $edit = array(
    'name' => 'jkool',
    'pass' => 'goodpwd',
  );
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Member for'), 'Existing Ldap user with good password authenticated.');
  $this
    ->assertTrue($this->testFunctions
    ->ldapUserIsAuthmapped('jkool'), 'Existing Ldap user still properly authmapped.', $testid);
  $this
    ->drupalGet('user/logout');
}