public function SimpleLdapUserAuthenticationWebTestCase::testBadAuthentication in Simple LDAP 7.2
Same name and namespace in other branches
- 7 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserAuthenticationWebTestCase::testBadAuthentication()
Tests invalid login credentials.
File
- simple_ldap_user/
simple_ldap_user.test, line 405 - Tests for Simple LDAP User module.
Class
Code
public function testBadAuthentication() {
// Load configuration variables.
$attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
// Initialize a user account object, with an invalid password.
$account = new stdClass();
$account->name = $this->ldapUser[0]->{$attribute_name}[0];
$account->pass_raw = $this->userPassword[0] . 'invalid';
// Verify that the test user exists in LDAP.
$ldap_user = new SimpleLdapUser($account->name);
$this
->assertTrue($ldap_user->exists, t(':name exists in LDAP.', array(
':name' => $account->name,
)));
// Verify that the test user does not exist in Drupal.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
$this
->assertIdentical($drupal_user, FALSE, t('The test user does not exist in Drupal.'));
// Verify that the user cannot log in.
$this
->drupalNoLogin($account);
// Verify that the Drupal user was created during the authentication
// attempt.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
$this
->assertNotIdentical($drupal_user, FALSE, t('The test user was created in Drupal.'));
// Verify again that the user cannot log in, now that the account exists in
// both Drupal and LDAP.
$this
->drupalNoLogin($account);
// Create a new Drupal user that is not in LDAP.
$account = $this->drupalUser[0];
$account->pass_raw = $account->pass_raw . 'invalid';
// Verify that the user does not exist in LDAP (by random chance).
$ldap_user = new SimpleLdapUser($account->name);
$this
->assertFalse($ldap_user->exists, t('The user account does not exist in LDAP.'));
// Verify that the user cannot log in.
$this
->drupalNoLogin($account);
// Initialize a random user object.
$account = new stdClass();
$account->name = $this
->randomName();
$account->pass_raw = $this
->randomName();
// Verify that the user does not exist in LDAP (by random chance).
$ldap_user = new SimpleLdapUser($account->name);
$this
->assertFalse($ldap_user->exists, t('The user account does not exist in LDAP.'));
// Verify that the user does not exist in Drupal (by random chance).
$drupal_user = user_load_by_name($account->name);
$this
->assertIdentical($drupal_user, FALSE, t('The user does not exist in Drupal.'));
// Attempt to log in.
$this
->drupalNoLogin($account);
// Verify that the user was not created in LDAP.
$ldap_user = new SimpleLdapUser($account->name);
$this
->assertFalse($ldap_user->exists, t('The user account does not exist in LDAP.'));
// Verify that the user was not created in Drupal.
$drupal_user = user_load_by_name($account->name);
$this
->assertIdentical($drupal_user, FALSE, t('The user does not exist in Drupal.'));
}