2022-12-26 23:27:04 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Auth\Validator;
|
|
|
|
|
|
|
|
use Appwrite\Auth\Validator\PasswordDictionary;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
class PasswordDictionaryTest extends TestCase
|
|
|
|
{
|
|
|
|
protected ?PasswordDictionary $object = null;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->object = new PasswordDictionary(
|
2023-02-20 14:38:57 +13:00
|
|
|
['password' => true, '123456' => true],
|
|
|
|
true
|
|
|
|
);
|
2022-12-26 23:27:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testValues(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals($this->object->isValid('1'), false); // to check parent is being called
|
|
|
|
$this->assertEquals($this->object->isValid('123456'), false);
|
|
|
|
$this->assertEquals($this->object->isValid('password'), false);
|
|
|
|
$this->assertEquals($this->object->isValid('myPasswordIsRight'), true);
|
2024-01-02 23:59:35 +13:00
|
|
|
|
|
|
|
$pass = ''; // 256 chars
|
|
|
|
for ($i = 0; $i < 256; $i++) {
|
|
|
|
$pass .= 'p';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($this->object->isValid($pass), true);
|
|
|
|
|
|
|
|
$pass .= 'p'; // 257 chars
|
|
|
|
|
|
|
|
$this->assertEquals($this->object->isValid($pass), false);
|
2022-12-26 23:27:04 +13:00
|
|
|
}
|
|
|
|
}
|