You are here

public function PasswordPolicyConstraintsTestCase::testBlacklistConstraint in Password Policy 7.2

Tests blacklist constraint.

File

./password_policy.test, line 196
Unit tests for Password policy module.

Class

PasswordPolicyConstraintsTestCase
Test case to verify accuracy of each available policy constraint.

Code

public function testBlacklistConstraint() {

  // Whitespace in blacklist helps test trimming of blacklisted passwords.
  $config = array(
    'blacklist' => array(
      'blacklist' => "123\n abc\t\ndef",
      'blacklist_match_substrings' => FALSE,
    ),
  );
  $policy = $this
    ->createPolicy($config);
  $this
    ->assertFalse($this
    ->checkPolicy($policy, 'ABC'), 'Blacklist constraint fails with password in blacklist.', 'Constraint');
  $this
    ->assertTrue($this
    ->checkPolicy($policy, 'foo'), 'Blacklist constraint passes with password not in blacklist.', 'Constraint');
  $this
    ->assertTrue($this
    ->checkPolicy($policy, 'abc123'), 'Blacklist constraint passes with password containing but not equaling blacklisted passwords.', 'Constraint');

  // Test policy that disallows passwords containing blacklisted passwords.
  $config['blacklist']['blacklist_match_substrings'] = TRUE;
  $policy = $this
    ->createPolicy($config);
  $this
    ->assertFalse($this
    ->checkPolicy($policy, 'ABC'), 'Blacklist constraint fails with password in blacklist.', 'Constraint');
  $this
    ->assertTrue($this
    ->checkPolicy($policy, 'foo'), 'Blacklist constraint passes with password not in blacklist.', 'Constraint');
  $this
    ->assertFalse($this
    ->checkPolicy($policy, 'abc123'), 'Blacklist constraint fails with password containing but not equaling blacklisted passwords.', 'Constraint');
}