123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- class PasswordHashingTest extends DrupalWebTestCase {
- protected $profile = 'testing';
- public static function getInfo() {
- return array(
- 'name' => 'Password hashing',
- 'description' => 'Password hashing unit tests.',
- 'group' => 'System',
- );
- }
- function setUp() {
- require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
- parent::setUp();
- }
-
- function testPasswordHashing() {
-
-
- variable_set('password_count_log2', 1);
-
- $password = 'baz';
- $account = (object) array('name' => 'foo', 'pass' => md5($password));
-
- $this->assertTrue(user_needs_new_hash($account), t('User with md5 password needs a new hash.'));
-
- $old_hash = $account->pass;
- $account->pass = user_hash_password($password);
- $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT, t('Re-hashed password has the minimum number of log2 iterations.'));
- $this->assertTrue($account->pass != $old_hash, t('Password hash changed.'));
- $this->assertTrue(user_check_password($password, $account), t('Password check succeeds.'));
-
-
- $this->assertFalse(user_needs_new_hash($account), t('User does not need a new hash.'));
-
- variable_set('password_count_log2', DRUPAL_MIN_HASH_COUNT + 1);
- $this->assertTrue(user_needs_new_hash($account), t('User needs a new hash after incrementing the log2 count.'));
-
- $old_hash = $account->pass;
- $account->pass = user_hash_password($password);
- $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT + 1, t('Re-hashed password has the correct number of log2 iterations.'));
- $this->assertTrue($account->pass != $old_hash, t('Password hash changed again.'));
-
- $this->assertFalse(user_needs_new_hash($account), t('Re-hashed password does not need a new hash.'));
- $this->assertTrue(user_check_password($password, $account), t('Password check succeeds with re-hashed password.'));
- }
- }
|