mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/passwords] Add basic passwords manager test file
PHPBB3-11610
This commit is contained in:
parent
f8bcf99c7f
commit
c9fafcefd3
1 changed files with 65 additions and 0 deletions
65
tests/crypto/manager_test.php
Normal file
65
tests/crypto/manager_test.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
|
class phpbb_crypto_manager_test extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
|
// Mock phpbb_container
|
||||||
|
$this->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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue