diff options
-rw-r--r-- | tests/mock/request.php | 19 | ||||
-rw-r--r-- | tests/passwords/drivers_test.php | 37 | ||||
-rw-r--r-- | tests/passwords/manager_test.php | 7 |
3 files changed, 63 insertions, 0 deletions
diff --git a/tests/mock/request.php b/tests/mock/request.php index 89d5321a25..304fcf0eaf 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -15,6 +15,8 @@ class phpbb_mock_request implements \phpbb\request\request_interface { protected $data; + protected $super_globals_disabled = false; + public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array()) { $this->data[\phpbb\request\request_interface::GET] = $get; @@ -23,6 +25,8 @@ class phpbb_mock_request implements \phpbb\request\request_interface $this->data[\phpbb\request\request_interface::REQUEST] = ($request === false) ? $post + $get : $request; $this->data[\phpbb\request\request_interface::SERVER] = $server; $this->data[\phpbb\request\request_interface::FILES] = $files; + + $this->disable_super_globals(); } public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST) @@ -83,6 +87,21 @@ class phpbb_mock_request implements \phpbb\request\request_interface return $this->data[$super_global]; } + public function super_globals_disabled() + { + return $this->super_globals_disabled; + } + + public function disable_super_globals() + { + $this->super_globals_disabled = true; + } + + public function enable_super_globals() + { + $this->super_globals_disabled = false; + } + /* custom methods */ public function set_header($header_name, $value) 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), ); } |