diff options
author | Marc Alexander <admin@m-a-styles.de> | 2014-05-27 18:13:06 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2014-06-01 21:31:04 +0200 |
commit | 3508409c89acd53943d7e9d1b32982fd021122f0 (patch) | |
tree | ffdb95b6c5c1b7ace4755bc857d0c6f25942eccc /tests/passwords | |
parent | [ticket/12352] Add driver for phpBB2 hashes with md5 length of 32 (diff) | |
download | phpbb-3508409c89acd53943d7e9d1b32982fd021122f0.tar.gz phpbb-3508409c89acd53943d7e9d1b32982fd021122f0.tar.bz2 phpbb-3508409c89acd53943d7e9d1b32982fd021122f0.zip |
[ticket/12352] Add tests for phpBB2 md5 passwords driver
PHPBB3-12352
Diffstat (limited to 'tests/passwords')
-rw-r--r-- | tests/passwords/drivers_test.php | 37 | ||||
-rw-r--r-- | tests/passwords/manager_test.php | 7 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php index 5e2518cdea..cff03b02c9 100644 --- a/tests/passwords/drivers_test.php +++ b/tests/passwords/drivers_test.php @@ -17,7 +17,10 @@ class phpbb_passwords_helper_test extends \phpbb_test_case { // Prepare dependencies for drivers $config = new \phpbb\config\config(array()); + $request = new phpbb_mock_request(array(), array(), array(), array(), array('password' => 'fööbar')); $this->driver_helper = new \phpbb\passwords\driver\helper($config); + $phpbb_root_path = dirname(__FILE__) . '/../../phpBB/'; + $php_ext = 'php'; $this->passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper), @@ -25,6 +28,7 @@ class phpbb_passwords_helper_test extends \phpbb_test_case '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), + 'passwords.driver.phpbb2_md5' => new \phpbb\passwords\driver\phpbb2_md5($request, $phpbb_root_path, $php_ext), ); } @@ -115,4 +119,37 @@ class phpbb_passwords_helper_test extends \phpbb_test_case { $this->assertSame($expected, $this->passwords_drivers[$driver]->get_settings_only($hash)); } + + public function data_phpbb2_md5_check() + { + return array( + array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96ae'), + array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96aeddsf'), + array(false, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae'), + array(true, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae', utf8_decode('fööbar')), + ); + } + + /** + * @dataProvider data_phpbb2_md5_check + */ + public function test_phpbb2_md5_check($expected, $password, $hash, $request_password = false) + { + if (!$request_password) + { + unset($_REQUEST['password']); + } + else + { + $_REQUEST['password'] = $request_password; + } + $this->assertSame($expected, $this->passwords_drivers['passwords.driver.phpbb2_md5']->check($password, $hash)); + } + + public function test_phpbb2_md5_unneeded_functions() + { + $this->assertSame(false, $this->passwords_drivers['passwords.driver.phpbb2_md5']->hash('foobar')); + + $this->assertSame(false, $this->passwords_drivers['passwords.driver.phpbb2_md5']->get_settings_only('ae2fc75e20ee25d4520766788fbc96ae')); + } } diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php index d0f860c4c5..e925502f18 100644 --- a/tests/passwords/manager_test.php +++ b/tests/passwords/manager_test.php @@ -24,6 +24,9 @@ class phpbb_passwords_manager_test extends \phpbb_test_case // Prepare dependencies for manager and driver $config = new \phpbb\config\config(array()); $this->driver_helper = new \phpbb\passwords\driver\helper($config); + $request = new phpbb_mock_request(array(), array(), array(), array(), array('password' => 'töst')); + $phpbb_root_path = dirname(__FILE__) . '/../../phpBB/'; + $php_ext = 'php'; $this->passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper), @@ -32,6 +35,7 @@ class phpbb_passwords_manager_test extends \phpbb_test_case '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), 'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper), + 'passwords.driver.phpbb2_md5' => new \phpbb\passwords\driver\phpbb2_md5($request, $phpbb_root_path, $php_ext), ); $this->helper = new \phpbb\passwords\helper; @@ -146,6 +150,9 @@ class phpbb_passwords_manager_test extends \phpbb_test_case array('foobar', '6f9e2a1899e1f15708fd2e554103480eb53e8b57', false, array('login_name' => 'test')), array('foobar', '$CP$6f9e2a1899e1f15708fd2e554103480eb53e8b57', true, array('login_name' => 'test')), array('foobar', '6f9e2a1899', false, array('login_name' => 'test')), + array('fööbar', 'ae2fc75e20ee25d4520766788fbc96ae', false), + array('fööbar', '$CP$ae2fc75e20ee25d4520766788fbc96ae', false), + array(utf8_decode('fööbar'), '$CP$ae2fc75e20ee25d4520766788fbc96ae', true), ); } |