diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-10-02 17:24:11 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-10-02 17:24:11 +0200 |
commit | e7e11112b17d6a8d4811d28376f1cc545243c08c (patch) | |
tree | af3ed5dc98c290c065f575d6f13025f221ac0053 /tests | |
parent | 3aba3235d5590efc6fbccd537641ebc87b3cfbfa (diff) | |
download | forums-e7e11112b17d6a8d4811d28376f1cc545243c08c.tar forums-e7e11112b17d6a8d4811d28376f1cc545243c08c.tar.gz forums-e7e11112b17d6a8d4811d28376f1cc545243c08c.tar.bz2 forums-e7e11112b17d6a8d4811d28376f1cc545243c08c.tar.xz forums-e7e11112b17d6a8d4811d28376f1cc545243c08c.zip |
[feature/passwords] Fix tests after changes to phpBB hashing functions
PHPBB3-11610
Diffstat (limited to 'tests')
-rw-r--r-- | tests/security/hash_test.php | 27 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 33 |
2 files changed, 59 insertions, 1 deletions
diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php index 0c2580c19b..b4c4dba48f 100644 --- a/tests/security/hash_test.php +++ b/tests/security/hash_test.php @@ -13,6 +13,33 @@ class phpbb_security_hash_test extends phpbb_test_case { public function test_check_hash_with_phpass() { + global $phpbb_container; + + $config = new phpbb\config\config(array()); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $driver_helper = new phpbb\passwords\driver\helper($config); + $passwords_drivers = array( + 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + ); + + foreach ($passwords_drivers as $key => $driver) + { + $driver->set_name($key); + } + + $passwords_helper = new phpbb\passwords\helper; + // Set up passwords manager + $passwords_manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('passwords.manager') + ->will($this->returnValue($passwords_manager)); + $this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); $this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); $this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f87b3538a1..065227b050 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -509,6 +509,7 @@ class phpbb_functional_test_case extends phpbb_test_case set_config(null, null, null, $config); set_config_count(null, null, null, $config); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $passwords_manager = $this->get_passwords_manager(); $user_row = array( 'username' => $username, @@ -518,7 +519,7 @@ class phpbb_functional_test_case extends phpbb_test_case 'user_lang' => 'en', 'user_timezone' => 0, 'user_dateformat' => '', - 'user_password' => phpbb_hash($username . $username), + 'user_password' => $passwords_manager->hash($username . $username), ); return user_add($user_row); } @@ -995,4 +996,34 @@ class phpbb_functional_test_case extends phpbb_test_case } return null; } + + /** + * Return a passwords manager instance + * + * @return phpbb\passwords\manager + */ + public function get_passwords_manager() + { + // Prepare dependencies for manager and driver + $config = new phpbb\config\config(array()); + $driver_helper = new phpbb\passwords\driver\helper($config); + + $passwords_drivers = array( + 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + ); + + foreach ($passwords_drivers as $key => $driver) + { + $driver->set_name($key); + } + + $passwords_helper = new phpbb\passwords\helper; + // Set up passwords manager + $manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + + return $manager; + } } |