mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-24 02:17:40 +02:00
Unittest for Classes Password Policy
This commit is contained in:
parent
39bbc539f3
commit
1782e97c92
102
test/php/library/Icinga/Application/CommonPasswordPolicyTest.php
Normal file
102
test/php/library/Icinga/Application/CommonPasswordPolicyTest.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
use Icinga\Application\Hook\PasswordPolicyHook;
|
||||
use Icinga\Application\ProvidedHook\CommonPasswordPolicy;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class CommonPasswordPolicyTest extends BaseTestCase
|
||||
{
|
||||
private object $object;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->object = new CommonPasswordPolicy();
|
||||
}
|
||||
|
||||
public function testClassIsInstanzOf()
|
||||
{
|
||||
$this->assertInstanceOf(PasswordPolicyHook::class, $this->object);
|
||||
}
|
||||
|
||||
public function testMethodGetName(): void
|
||||
{
|
||||
$this->assertSame('Common', $this->object->getName());
|
||||
}
|
||||
|
||||
public function testValidatePasswordTooShort()
|
||||
{
|
||||
$res = $this->object->validatePassword('Icinga1#');
|
||||
$this->assertSame('Password must be at least 12 characters long', $res[0]);
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordNoNumber()
|
||||
{
|
||||
$res = $this->object->validatePassword('Icingaadmin#');
|
||||
$this->assertSame('Password must contain at least one number', $res[0]);
|
||||
var_dump($res);
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordNoSpecialCharacter()
|
||||
{
|
||||
$res = $this->object->validatePassword('Icingaadmin1');
|
||||
$this->assertSame('Password must contain at least one special character', $res[0]);
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordNoUpperCaseLetters()
|
||||
{
|
||||
$res = $this->object->validatePassword('icingaadmin1#');
|
||||
$this->assertSame('Password must contain at least one uppercase letter', $res[0]);
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordNoLowerCaseLetters()
|
||||
{
|
||||
$res = $this->object->validatePassword('ICINGAADMIN1#');
|
||||
$this->assertSame('Password must contain at least one lowercase letter', $res[0]);
|
||||
$this->assertCount(1, $res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordValid()
|
||||
{
|
||||
$res = $this->object->validatePassword('Icingaadmin1#');
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
|
||||
public function testValidatePasswordOnlyLowerCaseLetters()
|
||||
{
|
||||
$res = $this->object->validatePassword('icingawebadmin');
|
||||
var_dump($res);
|
||||
$this->assertCount(3, $res);
|
||||
$this->assertSame('Password must contain at least one number', $res[0]);
|
||||
$this->assertSame('Password must contain at least one special character', $res[1]);
|
||||
$this->assertSame('Password must contain at least one uppercase letter', $res[2]);
|
||||
}
|
||||
|
||||
public function testValidatePasswordWithLengthAndUpperCaseLetters()
|
||||
{
|
||||
$res = $this->object->validatePassword('ICINGAADMIN');
|
||||
var_dump($res);
|
||||
$this->assertCount(4, $res);
|
||||
$this->assertSame('Password must be at least 12 characters long', $res[0]);
|
||||
$this->assertSame('Password must contain at least one number', $res[1]);
|
||||
$this->assertSame('Password must contain at least one special character', $res[2]);
|
||||
$this->assertSame('Password must contain at least one lowercase letter', $res[3]);
|
||||
}
|
||||
|
||||
public function testValidatePasswordWithManyCharacters()
|
||||
{
|
||||
$longPassword = str_repeat('a', 1000);
|
||||
var_dump($longPassword);
|
||||
$res = $this->object->validatePassword($longPassword);
|
||||
var_dump($res);
|
||||
$this->assertCount(3, $res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
33
test/php/library/Icinga/Application/NoPasswordPolicyTest.php
Normal file
33
test/php/library/Icinga/Application/NoPasswordPolicyTest.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
use Icinga\Application\Hook\PasswordPolicyHook;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Application\ProvidedHook\NoPasswordPolicy;
|
||||
|
||||
class NoPasswordPolicyTest extends BaseTestCase
|
||||
{
|
||||
private object $object;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->object = new NoPasswordPolicy();
|
||||
}
|
||||
|
||||
public function testClassIsInstanzOf()
|
||||
{
|
||||
$this->assertInstanceOf(PasswordPolicyHook::class, $this->object);
|
||||
}
|
||||
|
||||
public function testMethodGetName(): void
|
||||
{
|
||||
$this->assertSame('None', $this->object->getName());
|
||||
}
|
||||
|
||||
public function testValidatePasswordValid()
|
||||
{
|
||||
$res = $this->object->validatePassword('icingaadmin');
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user