moodle/lib/password_compat/tests/PasswordNeedsRehashTest.php
2013-02-09 06:47:57 +13:00

37 lines
1.2 KiB
PHP

<?php
global $CFG;
require_once($CFG->dirroot . '/lib/password_compat/lib/password.php');
class PasswordNeedsRehashTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
if (password_compat_not_supported()) {
// Skip test if password_compat is not supported.
$this->markTestSkipped('password_compat not supported');
}
}
public static function provideCases() {
return array(
array('foo', 0, array(), false),
array('foo', 1, array(), true),
array('$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi', PASSWORD_BCRYPT, array(), true),
array('$2y$07$usesomesillystringfore2udlvp1ii2e./u9c8sbjqp8i90dh6hi', PASSWORD_BCRYPT, array('cost' => 7), false),
array('$2y$07$usesomesillystringfore2udlvp1ii2e./u9c8sbjqp8i90dh6hi', PASSWORD_BCRYPT, array('cost' => 5), true),
);
}
public function testFuncExists() {
$this->assertTrue(function_exists('password_needs_rehash'));
}
/**
* @dataProvider provideCases
*/
public function testCases($hash, $algo, $options, $valid) {
$this->assertEquals($valid, password_needs_rehash($hash, $algo, $options));
}
}