aboutsummaryrefslogtreecommitdiffstats
path: root/tests/passwords
diff options
context:
space:
mode:
Diffstat (limited to 'tests/passwords')
-rw-r--r--tests/passwords/drivers_test.php57
-rw-r--r--tests/passwords/manager_test.php160
2 files changed, 101 insertions, 116 deletions
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php
index 01c69a38bb..fc11ca0bc7 100644
--- a/tests/passwords/drivers_test.php
+++ b/tests/passwords/drivers_test.php
@@ -13,7 +13,7 @@
class phpbb_passwords_helper_test extends \phpbb_test_case
{
- public function setUp()
+ public function setUp(): void
{
// Prepare dependencies for drivers
$config = new \phpbb\config\config(array());
@@ -21,6 +21,13 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
$this->driver_helper = new \phpbb\passwords\driver\helper($config);
$phpbb_root_path = dirname(__FILE__) . '/../../phpBB/';
$php_ext = 'php';
+
+ // Initialize argon2 default options
+ $this->argon2_default_cost_options = [
+ 'memory_cost' => 1024,
+ 'time_cost' => 2,
+ 'threads' => 2
+ ];
$this->passwords_drivers = array(
'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper, 10),
@@ -37,13 +44,26 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
);
$this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext);
$this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper);
+
+ $pwhash_supported = function_exists('password_hash') && function_exists('password_needs_rehash') && function_exists('password_verify');
+ if (defined('PASSWORD_ARGON2I') && $pwhash_supported)
+ {
+ $this->passwords_drivers['passwords.driver.argon2i'] = new \phpbb\passwords\driver\argon2i($config, $this->driver_helper);
+ $this->argon2_default_cost_options = $this->passwords_drivers['passwords.driver.argon2i']->get_options();
+ }
+
+ if (defined('PASSWORD_ARGON2ID') && $pwhash_supported)
+ {
+ $this->passwords_drivers['passwords.driver.argon2id'] = new \phpbb\passwords\driver\argon2id($config, $this->driver_helper);
+ $this->argon2_default_cost_options = $this->passwords_drivers['passwords.driver.argon2id']->get_options();
+ }
}
public function data_helper_encode64()
{
return array(
- array('foobar', 6, 'axqPW3aQ'),
- array('foobar', 7, 'axqPW3aQ..'),
+ array('foobars', 6, 'axqPW3aQ'),
+ array('foobarss', 7, 'axqPW3aQn/'),
array('foobar', 5, 'axqPW34'),
);
}
@@ -416,13 +436,34 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
public function data_needs_rehash()
{
- return array(
+ $data_array = [
array('passwords.driver.bcrypt_2y', '$2y$10$somerandomhash', false),
array('passwords.driver.bcrypt', '$2a$10$somerandomhash', false),
array('passwords.driver.salted_md5', 'foobar', false),
array('passwords.driver.bcrypt_2y', '$2y$9$somerandomhash', true),
array('passwords.driver.bcrypt', '$2a$04$somerandomhash', true),
- );
+ ];
+
+ if (isset($this->passwords_drivers['passwords.driver.argon2i']))
+ {
+ $data_array = array_merge($data_array, [
+ array('passwords.driver.argon2i', '$argon2i$v=19$m=' . $this->argon2_default_cost_options['memory_cost'] . ',t=' . $this->argon2_default_cost_options['time_cost'] . ',p=' . $this->argon2_default_cost_options['threads'] . '$NEF0S1JSN04yNGQ1UVRKdA$KYGNI9CbjoKh1UEu1PpdlqbuLbveGwkMcwcT2Un9pPM', false),
+ array('passwords.driver.argon2i', '$argon2i$v=19$m=128,t=2,p=2$M29GUi51QjdKLjIzbC9scQ$6h1gZDqn7JTmVdQ0lJh1x5nyvgO/DaJWUKOFJ0itCJ0', true),
+ array('passwords.driver.argon2i', '$argon2i$v=19$m=1024,t=1,p=2$UnFHb2F4NER3M0xWWmxMUQ$u3javvoAZJeIyR1P3eg0tb8VjEeXvQPagqwetonq1NA', true),
+ array('passwords.driver.argon2i', '$argon2i$v=19$m=1024,t=2,p=1$bm5SeGJ3R3ZRY1A0YXJPNg$v1A9m4sJW+ge0RBtpJ4w9861+J9xkguKBAsZHrG8LQU', true),
+ ]);
+ }
+
+ if (isset($this->passwords_drivers['passwords.driver.argon2id']))
+ {
+ $data_array = array_merge($data_array, [
+ array('passwords.driver.argon2id', '$argon2id$v=19$m=' . $this->argon2_default_cost_options['memory_cost'] . ',t=' . $this->argon2_default_cost_options['time_cost'] . ',p=' . $this->argon2_default_cost_options['threads'] . '$MXB4OW5sczE5TnFPYkEuYQ$2bxaMIp8+9x37O6v8zkqpBU72ohCibUrtgVZw7vyr5Q', false),
+ array('passwords.driver.argon2id', '$argon2id$v=19$m=128,t=2,p=2$RWV2VFAuWXk5bTVjbktOLg$Nt7Z7koa25SVRSKr3RKqjwKz26FENDuU+aL1DfMcWRo', true),
+ array('passwords.driver.argon2id', '$argon2id$v=19$m=1024,t=1,p=2$Rmw5M21IUFZDVEltYU0uTA$GIObGbHV6sOw5OQEtF8z+2ESztT96OWhCk17sUlwLAY', true),
+ ]);
+ }
+
+ return $data_array;
}
/**
@@ -430,6 +471,10 @@ class phpbb_passwords_helper_test extends \phpbb_test_case
*/
public function test_needs_rehash($driver, $hash, $expected)
{
- $this->assertSame($this->passwords_drivers[$driver]->needs_rehash($hash), $expected);
+ if (!$this->passwords_drivers[$driver]->is_supported())
+ {
+ $this->markTestSkipped($driver . ' is not supported');
+ }
+ $this->assertSame($expected, $this->passwords_drivers[$driver]->needs_rehash($hash));
}
}
diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php
index 0410d7035f..90dbb47f46 100644
--- a/tests/passwords/manager_test.php
+++ b/tests/passwords/manager_test.php
@@ -19,7 +19,7 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
protected $default_pw = 'foobar';
- public function setUp()
+ public function setUp(): void
{
// Prepare dependencies for manager and driver
$config = new \phpbb\config\config(array());
@@ -51,26 +51,13 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
public function hash_password_data()
{
- if (version_compare(PHP_VERSION, '5.3.7', '<'))
- {
- return array(
- array('', '2a', 60),
- array('passwords.driver.bcrypt_2y', '2a', 60),
- array('passwords.driver.bcrypt', '2a', 60),
- array('passwords.driver.salted_md5', 'H', 34),
- array('passwords.driver.foobar', '', false),
- );
- }
- else
- {
- return array(
- array('', '2y', 60),
- array('passwords.driver.bcrypt_2y', '2y', 60),
- array('passwords.driver.bcrypt', '2a', 60),
- array('passwords.driver.salted_md5', 'H', 34),
- array('passwords.driver.foobar', '', false),
- );
- }
+ return array(
+ array('', '2y', 60),
+ array('passwords.driver.bcrypt_2y', '2y', 60),
+ array('passwords.driver.bcrypt', '2a', 60),
+ array('passwords.driver.salted_md5', 'H', 34),
+ array('passwords.driver.foobar', '', false),
+ );
}
/**
@@ -100,23 +87,12 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
public function check_password_data()
{
- if (version_compare(PHP_VERSION, '5.3.7', '<'))
- {
- return array(
- array('passwords.driver.bcrypt'),
- array('passwords.driver.salted_md5'),
- array('passwords.driver.phpass'),
- );
- }
- else
- {
- return array(
- array('passwords.driver.bcrypt_2y'),
- array('passwords.driver.bcrypt'),
- array('passwords.driver.salted_md5'),
- array('passwords.driver.phpass'),
- );
- }
+ return array(
+ array('passwords.driver.bcrypt_2y'),
+ array('passwords.driver.bcrypt'),
+ array('passwords.driver.salted_md5'),
+ array('passwords.driver.phpass'),
+ );
}
/**
@@ -136,7 +112,7 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
}
// Check if convert_flag is correctly set
- $default_type = (version_compare(PHP_VERSION, '5.3.7', '<')) ? 'passwords.driver.bcrypt' : 'passwords.driver.bcrypt_2y';
+ $default_type = 'passwords.driver.bcrypt_2y';
$this->assertEquals(($hash_type !== $default_type), $this->manager->convert_flag);
}
@@ -200,79 +176,43 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
public function test_hash_password_8bit_bcrypt()
{
$this->assertEquals(false, $this->manager->hash('foobarš¯„˛', 'passwords.driver.bcrypt'));
- if (version_compare(PHP_VERSION, '5.3.7', '<'))
- {
- $this->assertEquals(false, $this->manager->hash('foobarš¯„˛', 'passwords.driver.bcrypt_2y'));
- }
- else
- {
- $this->assertNotEquals(false, $this->manager->hash('foobarš¯„˛', 'passwords.driver.bcrypt_2y'));
- }
+ $this->assertNotEquals(false, $this->manager->hash('foobarš¯„˛', 'passwords.driver.bcrypt_2y'));
}
public function combined_hash_data()
{
- if (version_compare(PHP_VERSION, '5.3.7', '<'))
- {
- return array(
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.bcrypt'),
- ),
- array(
- 'passwords.driver.phpass',
- array('passwords.driver.salted_md5'),
- ),
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.phpass', 'passwords.driver.bcrypt'),
- ),
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.salted_md5'),
- false,
- ),
- array(
- '$H$',
- array('$2a$'),
- ),
- );
- }
- else
- {
- return array(
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.bcrypt_2y'),
- ),
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.bcrypt'),
- ),
- array(
- 'passwords.driver.phpass',
- array('passwords.driver.salted_md5'),
- ),
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.bcrypt_2y', 'passwords.driver.bcrypt'),
- ),
- array(
- 'passwords.driver.salted_md5',
- array('passwords.driver.salted_md5'),
- false,
- ),
- array(
- 'passwords.driver.bcrypt_2y',
- array('passwords.driver.salted_md4'),
- false,
- ),
- array(
- '$H$',
- array('$2y$'),
- ),
- );
- }
+ return array(
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt_2y'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.phpass',
+ array('passwords.driver.salted_md5'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt_2y', 'passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.salted_md5'),
+ false,
+ ),
+ array(
+ 'passwords.driver.bcrypt_2y',
+ array('passwords.driver.salted_md4'),
+ false,
+ ),
+ array(
+ '$H$',
+ array('$2y$'),
+ ),
+ );
}
/**
@@ -361,13 +301,13 @@ class phpbb_passwords_manager_test extends \phpbb_test_case
{
if ($use_new_interface)
{
- $test_driver = $this->getMock('\phpbb\passwords\driver\rehashable_driver_interface', array('needs_rehash', 'get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
+ $test_driver = $this->createMock('\phpbb\passwords\driver\rehashable_driver_interface', array('needs_rehash', 'get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
$test_driver->method('needs_rehash')
->willReturn($needs_rehash);
}
else
{
- $test_driver = $this->getMock('\phpbb\passwords\driver\driver_interface', array('get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
+ $test_driver = $this->createMock('\phpbb\passwords\driver\driver_interface', array('get_prefix', 'check', 'is_supported', 'is_legacy', 'hash', 'get_settings_only'));
}
$config = new \phpbb\config\config(array());