mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
test updates
This commit is contained in:
parent
6e1cba7802
commit
8faf1dc2ff
@ -5,13 +5,73 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TotpPfTest extends TestCase
|
||||
{
|
||||
public function testBasic()
|
||||
public function setUp(): void
|
||||
{
|
||||
$x = new TotpPf('mailbox');
|
||||
db_execute("INSERT INTO domain(domain, description, transport) values ('example.com', 'test', 'foo')", [], true);
|
||||
|
||||
db_execute(
|
||||
"INSERT INTO mailbox(username, password, name, maildir, local_part, domain) VALUES(:username, :password, :name, :maildir, :local_part, :domain)",
|
||||
[
|
||||
'username' => 'test@example.com',
|
||||
'password' => pacrypt('foobar'),
|
||||
'name' => 'test user',
|
||||
'maildir' => '/foo/bar',
|
||||
'local_part' => 'test',
|
||||
'domain' => 'example.com',
|
||||
]);
|
||||
|
||||
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->cleanUp();
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
private function cleanUp()
|
||||
{
|
||||
db_query('DELETE FROM alias');
|
||||
db_query('DELETE FROM alias_domain');
|
||||
db_query('DELETE FROM mailbox');
|
||||
db_query('DELETE FROM domain_admins');
|
||||
db_query('DELETE FROM domain');
|
||||
}
|
||||
|
||||
|
||||
public function testBasicTotpStuff()
|
||||
{
|
||||
$x = new TotpPf('mailbox', new Login('mailbox'));
|
||||
$array = $x->generate('test@example.com');
|
||||
|
||||
$this->assertIsArray($array);
|
||||
$this->assertIsString($array[0]);
|
||||
$this->assertIsString($array[1]);
|
||||
|
||||
|
||||
$y = $x->checkUserTOTP('test@example.com', '123456');
|
||||
|
||||
$z = $x->checkTOTP('asdf', 'fakecode');
|
||||
|
||||
$this->assertFalse($y);
|
||||
$this->assertFalse($z);
|
||||
|
||||
$totp = \OTPHP\TOTP::create('asdf');
|
||||
|
||||
$currentCode = $totp->now();
|
||||
$this->assertNotEmpty($totp);
|
||||
$this->assertTrue($x->checkTOTP('asdf', $currentCode));
|
||||
|
||||
$this->assertNotEmpty($currentCode);
|
||||
}
|
||||
|
||||
public function testDbOperations()
|
||||
{
|
||||
$x = new TotpPf('mailbox', new Login('mailbox'));
|
||||
|
||||
$this->assertNull($x->getException(1));
|
||||
|
||||
var_dump($x->addException('test@example.com', 'foobar', '1.2.3.4', 'another.test@example.com', 'test'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user