mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-20 03:36:20 +02:00
78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TotpPfTest extends TestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
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'));
|
|
}
|
|
}
|