diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-10-09 22:53:13 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-10-09 22:53:13 +0200 |
commit | cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c (patch) | |
tree | 343dbdf6fdd3e87788e10479e88cf19f584cd6e3 /tests/passwords/drivers_test.php | |
parent | 3b6038cfcd6e00aaf8e9b5f68f2a925c9a85da51 (diff) | |
download | forums-cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c.tar forums-cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c.tar.gz forums-cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c.tar.bz2 forums-cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c.tar.xz forums-cd74fb094629cf07209b4fa13ebf0ddf5b4ce47c.zip |
[feature/passwords] Increase test coverage to 35 out ouf 36 methods
Only one small code part in the salted md5 driver can't be tested right now.
Passwords helper and passwords driver helper are now fully covered by tests.
PHPBB3-11610
Diffstat (limited to 'tests/passwords/drivers_test.php')
-rw-r--r-- | tests/passwords/drivers_test.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php new file mode 100644 index 0000000000..1fc51b1dd2 --- /dev/null +++ b/tests/passwords/drivers_test.php @@ -0,0 +1,86 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_passwords_helper_test extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + // Prepare dependencies for drivers + $config = new \phpbb\config\config(array()); + $this->driver_helper = new \phpbb\passwords\driver\helper($config); + + $this->passwords_drivers = array( + '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), + '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), + ); + + foreach ($this->passwords_drivers as $key => $driver) + { + $driver->set_name($key); + } + } + + public function data_helper_encode64() + { + return array( + array('foobar', 6, 'axqPW3aQ'), + array('foobar', 7, 'axqPW3aQ..'), + array('foobar', 5, 'axqPW34'), + ); + } + + /** + * @dataProvider data_helper_encode64 + */ + public function test_helper_encode64($input, $length, $output) + { + $return = $this->driver_helper->hash_encode64($input, $length); + $this->assertEquals($output, $return); + } + + public function data_get_random_salt() + { + return array( + array(24, false), + array(24, '/dev/foobar'), + ); + } + + /** + * @dataProvider data_get_random_salt + */ + public function test_get_random_salt($length, $rand_seed) + { + $rand_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed); + $start = microtime(true); + + // Run each test for max. 1 second + while ((microtime(true) - $start) < 1) + { + $urandom_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed); + $this->assertEquals($length, strlen($urandom_string)); + $this->assertNotEquals($rand_string, $urandom_string); + } + } + + public function test_get_hash_settings_salted_md5() + { + $settings = $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings('$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'); + $this->assertEquals(array( + 'count' => pow(2, 11), + 'salt' => 'isfrtKXW', + 'full' => '$H$9isfrtKXW', + ), + $settings + ); + $this->assertEquals(false, $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings(false)); + } +} |