aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2013-06-15 17:56:29 +0200
committerMarc Alexander <admin@m-a-styles.de>2013-09-14 13:52:57 +0200
commite7b3daeb292d3066b12d8e699d0a64b5a165d36a (patch)
treee34a2e21e5bd31b9c8aaad12353f27f0bc9f4097 /tests
parent13d25e6a327728fc5bc28759ffe9f2248f6cb9a0 (diff)
downloadforums-e7b3daeb292d3066b12d8e699d0a64b5a165d36a.tar
forums-e7b3daeb292d3066b12d8e699d0a64b5a165d36a.tar.gz
forums-e7b3daeb292d3066b12d8e699d0a64b5a165d36a.tar.bz2
forums-e7b3daeb292d3066b12d8e699d0a64b5a165d36a.tar.xz
forums-e7b3daeb292d3066b12d8e699d0a64b5a165d36a.zip
[feature/passwords] Add tests for manager check_hash() method
Tests cover all supported hashing algorithms. PHPBB3-11610
Diffstat (limited to 'tests')
-rw-r--r--tests/crypto/manager_test.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/crypto/manager_test.php b/tests/crypto/manager_test.php
index eb1a0eeed3..a6172c52b1 100644
--- a/tests/crypto/manager_test.php
+++ b/tests/crypto/manager_test.php
@@ -11,6 +11,7 @@ require_once dirname(__FILE__) . '/../mock/container_builder.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/crypto/driver/bcrypt.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/crypto/driver/bcrypt_2y.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/crypto/driver/salted_md5.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/crypto/driver/phpass.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/crypto/driver/helper.php';
class phpbb_crypto_manager_test extends PHPUnit_Framework_TestCase
@@ -29,6 +30,7 @@ class phpbb_crypto_manager_test extends PHPUnit_Framework_TestCase
'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),
+ 'crypto.driver.phpass' => new phpbb_crypto_driver_phpass($config),
);
foreach ($crypto_drivers as $key => $driver)
@@ -75,4 +77,42 @@ class phpbb_crypto_manager_test extends PHPUnit_Framework_TestCase
$this->assertEquals($prefix, $match[1]);
$this->assertEquals($length, strlen($hash));
}
+
+ public function check_password_data()
+ {
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ return array(
+ array('foobar', 'crypto.driver.bcrypt'),
+ array('foobar', 'crypto.driver.salted_md5'),
+ array('barfoo', 'crypto.driver.phpass'),
+ );
+ }
+ else
+ {
+ return array(
+ array('foobar', 'crypto.driver.bcrypt_2y'),
+ array('barfoo', 'crypto.driver.bcrypt'),
+ array('foobar', 'crypto.driver.salted_md5'),
+ array('barfoo', 'crypto.driver.phpass'),
+ );
+ }
+ }
+
+ /**
+ * @dataProvider check_password_data
+ */
+ public function test_check_password($password, $hash_type)
+ {
+ $hash = $this->manager->hash_password($password, $hash_type);
+ $test_word = $password;
+ $time = microtime(true);
+
+ // Limit each test to 3 seconds
+ while ((microtime(true) - $time) < 3)
+ {
+ $this->assertEquals($test_word === $password, $this->manager->check_hash($test_word, $hash));
+ $test_word = str_shuffle($test_word);
+ }
+ }
}