You are here

function LdapAuthenticationTestCase::testMixedModeUserLogon in Lightweight Directory Access Protocol (LDAP) 8.2

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

LDAP Authentication Mixed Mode User Logon Test (ids = LDAP_authen.MM.ULT.*)

File

ldap_authentication/tests/ldap_authentication.test, line 62

Class

LdapAuthenticationTestCase

Code

function testMixedModeUserLogon() {
  $sid = 'activedirectory1';
  $testid = 'MixedModeUserLogon3';
  $sids = array(
    $sid,
  );
  $this
    ->prepTestData(LDAP_TEST_LDAP_NAME, $sids, 'provisionToDrupal', 'MixedModeUserLogon3', 'drupal_role_authentication_test');
  $ldap_servers = ldap_servers_get_servers($sid, 'enabled');
  $this
    ->assertTrue(count($ldap_servers) == 1, ' ldap_authentication test server setup successful', $testid);

  /**
   * LDAP_authen.MM.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.MM.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.MM.ULT.drupal.goodpwd - result: Successful 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('Member for'), 'Drupal user (not ldap associated) successfully authenticated', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.MM.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  (not ldap associated) with bad password failed to authenticate.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.MM.ULT.ldap.newaccount.badpwd - result: Drupal logon error message. **/
  $edit = array(
    'name' => 'hpotter',
    '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.MM.ULT.ldap.newaccount.goodpwd - result: Successful logon, with user record created and authmapped to ldap **/
  $edit = array(
    'name' => 'hpotter',
    '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('hpotter'), 'Ldap user properly authmapped.', $testid);
  $this
    ->drupalGet('user/logout');

  /** LDAP_authen.MM.ULT.existingacct.badpwd - result: Drupal logon error message. **/
  $edit = array(
    'name' => 'hpotter',
    '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' => 'hpotter',
    '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('hpotter'), 'Existing Ldap user still properly authmapped.', $testid);
  $this
    ->drupalGet('user/logout');
}