add more tests

pull/32/merge
David Goodwin 7 years ago
parent f543c7d403
commit 2f2730ffa0

@ -0,0 +1,21 @@
<?php
require_once('common.php');
class GeneratePasswordTest extends PHPUnit_Framework_TestCase
{
public function testBasic()
{
$one = generate_password();
$two = generate_password();
$this->assertNotEquals($one, $two);
$this->assertNotEmpty($one);
$this->assertNotEmpty($two);
}
}

@ -2,8 +2,10 @@
require_once('common.php');
class PaCryptTest extends PHPUnit_Framework_TestCase {
public function testMd5Crypt() {
class PaCryptTest extends PHPUnit_Framework_TestCase
{
public function testMd5Crypt()
{
$hash = _pacrypt_md5crypt('test', '');
$this->assertNotEmpty($hash);
@ -12,19 +14,21 @@ class PaCryptTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($hash, _pacrypt_md5crypt('test', $hash));
}
public function testCrypt() {
public function testCrypt()
{
// E_NOTICE if we pass in '' for the salt
$hash = _pacrypt_crypt('test', 'sa');
$this->assertNotEmpty($hash);
$this->assertNotEquals('test', $hash);
$this->assertEquals($hash, _pacrypt_crypt('test', $hash));
}
public function testMySQLEncrypt() {
public function testMySQLEncrypt()
{
if (!db_mysql()) {
$this->markTestSkipped('Not using MySQL');
}
@ -44,7 +48,8 @@ class PaCryptTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($hash2, _pacrypt_mysql_encrypt('test', 'salt'));
}
public function testAuthlib() {
public function testAuthlib()
{
// too many options!
foreach (
@ -62,7 +67,8 @@ class PaCryptTest extends PHPUnit_Framework_TestCase {
}
}
public function testPacryptDovecot() {
public function testPacryptDovecot()
{
global $CONF;
if (!file_exists('/usr/bin/doveadm')) {
$this->markTestSkipped("No /usr/bin/doveadm");
@ -77,6 +83,40 @@ class PaCryptTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash));
}
public function testPhpCrypt()
{
global $CONF;
$config = Config::getInstance();
Config::write('encrypt', 'php_crypt:MD5');
$CONF = Config::getInstance()->getAll();
$expected = '$1$z2DG4z9d$jBu3Cl3BPQZrkNqnflnSO.';
$enc = _pacrypt_php_crypt('foo', $expected);
$this->assertEquals($enc, $expected);
$fail = _pacrypt_php_crypt('bar', $expected);
$this->assertNotEquals($fail, $expected);
}
public function testPhpCryptRandomString(){
$str1 = _php_crypt_random_string('abcdefg123456789', 2);
$str2 = _php_crypt_random_string('abcdefg123456789', 2);
$this->assertNotEmpty($str1);
$this->assertNotEmpty($str2);
$this->assertNotEquals($str1, $str2);
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */

@ -0,0 +1,25 @@
<?php
require_once('common.php');
class ValidatePasswordTest extends PHPUnit_Framework_TestCase
{
public function testBasic()
{
$config = Config::getInstance();
// Set to the defaults, just to make sure.
Config::write('password_validation', array(
# '/regular expression/' => '$PALANG key (optional: + parameter)',
'/.{5}/' => 'password_too_short 5', # minimum length 5 characters
'/([a-zA-Z].*){3}/' => 'password_no_characters 3', # must contain at least 3 characters
'/([0-9].*){2}/' => 'password_no_digits 2', # must contain at least 2 digits
));
$this->assertEmpty(validate_password('fishSheep01'));
$this->assertEmpty(validate_password('Password01'));
$this->assertNotEmpty(validate_password('pas')); // notEmpty == fail
$this->assertNotEmpty(validate_password('pa1'));
}
}
Loading…
Cancel
Save