aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2016-12-03 14:07:56 +0100
committerTristan Darricau <github@nicofuma.fr>2016-12-03 14:07:56 +0100
commit487df8befc9477c742b2794593c2ddb290c1c678 (patch)
tree7e04e7c2a5bcdcc1a7e19327669ec5ec52a57e88 /tests
parent48db9cbcf035001a9a39e88973d297104e89bbcb (diff)
parent380be9f1fd713dbcee91f12f18060d6b3ff4819e (diff)
downloadforums-487df8befc9477c742b2794593c2ddb290c1c678.tar
forums-487df8befc9477c742b2794593c2ddb290c1c678.tar.gz
forums-487df8befc9477c742b2794593c2ddb290c1c678.tar.bz2
forums-487df8befc9477c742b2794593c2ddb290c1c678.tar.xz
forums-487df8befc9477c742b2794593c2ddb290c1c678.zip
Merge pull request #4405 from marc1706/ticket/14733
[ticket/14733] Support increasing hashing cost factor * marc1706/ticket/14733: [ticket/14733] Make sure detect_algorithm() works correctly and add tests [ticket/14733] Extend passwords driver_interface in rehashable_driver_interface [ticket/14733] Use new interface to preserve backwards compatibility [ticket/14733] Use default cost factor in bcrypt constructor [ticket/14733] Support increasing hashing cost factor
Diffstat (limited to 'tests')
-rw-r--r--tests/passwords/drivers_test.php23
-rw-r--r--tests/passwords/manager_test.php54
2 files changed, 73 insertions, 4 deletions
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php
index 5f9fd523c9..01c69a38bb 100644
--- a/tests/passwords/drivers_test.php
+++ b/tests/passwords/drivers_test.php
@@ -23,8 +23,8 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
$php_ext = 'php';
$this->passwords_drivers = array(
- 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
- 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper, 10),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper, 10),
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper),
@@ -413,4 +413,23 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
);
return strtr($string, $transform);
}
+
+ public function data_needs_rehash()
+ {
+ return array(
+ array('passwords.driver.bcrypt_2y', '$2y$10$somerandomhash', false),
+ array('passwords.driver.bcrypt', '$2a$10$somerandomhash', false),
+ array('passwords.driver.salted_md5', 'foobar', false),
+ array('passwords.driver.bcrypt_2y', '$2y$9$somerandomhash', true),
+ array('passwords.driver.bcrypt', '$2a$04$somerandomhash', true),
+ );
+ }
+
+ /**
+ * @dataProvider data_needs_rehash
+ */
+ public function test_needs_rehash($driver, $hash, $expected)
+ {
+ $this->assertSame($this->passwords_drivers[$driver]->needs_rehash($hash), $expected);
+ }
}
diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php
index 333834ee07..0410d7035f 100644
--- a/tests/passwords/manager_test.php
+++ b/tests/passwords/manager_test.php
@@ -29,8 +29,8 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
$php_ext = 'php';
$this->passwords_drivers = array(
- 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
- 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper, 10),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper, 10),
'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
'passwords.driver.convert_password' => new \phpbb\passwords\driver\convert_password($config, $this->driver_helper),
@@ -344,4 +344,54 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
{
$this->assertSame($expected, $this->driver_helper->string_compare($a, $b));
}
+
+ public function data_driver_interface_driver()
+ {
+ return array(
+ array(false, false, false),
+ array(true, false, false),
+ array(true, true, true),
+ );
+ }
+
+ /**
+ * @dataProvider data_driver_interface_driver
+ */
+ public function test_driver_interface_driver($use_new_interface, $needs_rehash, $expected)
+ {
+ if ($use_new_interface)
+ {
+ $test_driver = $this->getMock('\phpbb\passwords\driver\rehashable_driver_interface', array('needs_rehash', 'get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
+ $test_driver->method('needs_rehash')
+ ->willReturn($needs_rehash);
+ }
+ else
+ {
+ $test_driver = $this->getMock('\phpbb\passwords\driver\driver_interface', array('get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
+ }
+ $config = new \phpbb\config\config(array());
+
+ $test_driver->method('is_supported')
+ ->willReturn(true);
+ $test_driver->method('get_prefix')
+ ->willReturn('$test$');
+ $test_driver->method('check')
+ ->with($this->anything())
+ ->willReturn(true);
+ $passwords_drivers = array(
+ 'passwords.driver.foobar' => $test_driver,
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper, 10),
+ );
+ // Set up another manager
+ $foobar_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $this->helper, array('passwords.driver.foobar'));
+
+ $this->assertTrue($foobar_manager->check('foobar', '$test$somerandomstuff'));
+ $this->assertEquals($expected, $foobar_manager->convert_flag);
+
+ // Should always return true in case a different driver is default
+ $foobar_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $this->helper, array('passwords.driver.bcrypt_2y', 'passwords.driver.foobar'));
+
+ $this->assertTrue($foobar_manager->check('foobar', '$test$somerandomstuff'));
+ $this->assertTrue($foobar_manager->convert_flag);
+ }
}