1 user.test | public UserCreateTestCase::testUserWithWeakPassword() |
Tests setting a weak password.
A user should not be able to set a weak password if required.
File
- core/
modules/ user/ tests/ user.test, line 2020 - Tests for user.module.
Class
- UserCreateTestCase
- Test the create user administration page.
Code
public function testUserWithWeakPassword() {
$admin = $this->backdropCreateUser(array('administer users'));
$this->backdropLogin($admin);
// Set required strong password.
$config = config('system.core');
$config->set('user_password_reject_weak', TRUE);
$config->set('user_password_strength_threshold', 50);
$config->save();
$name = $this->randomName();
$email = $this->randomName() . '@example.com';
$edit = array(
'name' => $name,
'mail' => $email,
'pass' => $name,
'notify' => FALSE,
);
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("The password cannot be the same as the username."));
$edit['pass'] = $email;
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("The password cannot be the same as the email."));
$edit['pass'] = '123abcdef';
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("The password is too weak. Please consider making your password longer or more complex"));
// Require a "strong" password, not just the default "fair".
$config->set('user_password_strength_threshold', 90);
$config->save();
$edit['name'] = $this->randomName();
$edit['mail'] = $this->randomName() . '@example.com';
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("The password is too weak. Please consider making your password longer or more complex"));
$edit['pass'] = '123abcdefghijklmnopqrstuvwx';
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("Created a new user account"));
// Allow weak passwords.
$config->set('user_password_reject_weak', FALSE);
$config->save();
$edit['name'] = $this->randomName();
$edit['mail'] = $this->randomName() . '@example.com';
$edit['pass'] = '123';
$this->backdropPost('admin/people/create', $edit, t('Create new account'));
$this->assertRaw(t("Created a new user account"));
}