diff --git a/tests/crypto/manager_test.php b/tests/crypto/manager_test.php new file mode 100644 index 0000000000..ce6ac1684f --- /dev/null +++ b/tests/crypto/manager_test.php @@ -0,0 +1,65 @@ +phpbb_container = new phpbb_mock_container_builder; + + // Prepare dependencies for manager and driver + $config = new phpbb_config(array()); + + $crypto_drivers = array( + 'crypto.driver.bcrypt' => new phpbb_crypto_driver_bcrypt($config), + 'crypto.driver.bcrypt_2y' => new phpbb_crypto_driver_bcrypt_2y($config), + 'crypto.driver.salted_md5' => new phpbb_crypto_driver_salted_md5($config), + ); + + foreach ($crypto_drivers as $key => $driver) + { + $this->phpbb_container->set($key, $driver); + } +/* + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; + $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; +*/ + // Set up avatar manager + $this->manager = new phpbb_crypto_manager($config, $this->phpbb_container, $crypto_drivers); + } + + public function hash_password_data() + { + return array( + array('', '2y', 60), + array('crypto.driver.bcrypt_2y', '2y', 60), + array('crypto.driver.bcrypt', '2a', 60), + //array('crypto.driver.salted_md5', '$H$', 45), + ); + } + + /** + * @dataProvider hash_password_data + */ + public function test_hash_password($type, $prefix, $length) + { + $hash = $this->manager->hash_password('foobar', $type); + preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $hash, $match); + $this->assertEquals($prefix, $match[1]); + $this->assertEquals($length, strlen($hash)); + } +}