You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-06 06:42:37 +03:00
composer format
This commit is contained in:
@@ -80,9 +80,8 @@ class AdminpasswordHandler extends PFAHandler {
|
|||||||
* check if old password is correct
|
* check if old password is correct
|
||||||
*/
|
*/
|
||||||
protected function _validate_oldpass($field, $val) {
|
protected function _validate_oldpass($field, $val) {
|
||||||
|
|
||||||
$l = new Login('admin', 'username');
|
$l = new Login('admin', 'username');
|
||||||
if($l->login($this->id, $val)) {
|
if ($l->login($this->id, $val)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class Login
|
class Login {
|
||||||
{
|
|
||||||
private $table;
|
private $table;
|
||||||
private $id_field;
|
private $id_field;
|
||||||
|
|
||||||
public function __construct(string $tableName, string $idField)
|
public function __construct(string $tableName, string $idField) {
|
||||||
{
|
|
||||||
$this->table = table_by_key($tableName);
|
$this->table = table_by_key($tableName);
|
||||||
$this->id_field = $idField;
|
$this->id_field = $idField;
|
||||||
}
|
}
|
||||||
@@ -19,9 +17,7 @@ class Login
|
|||||||
* @param string $password
|
* @param string $password
|
||||||
* @return boolean true on successful login (i.e. password matches etc)
|
* @return boolean true on successful login (i.e. password matches etc)
|
||||||
*/
|
*/
|
||||||
public function login($username, $password): bool
|
public function login($username, $password): bool {
|
||||||
{
|
|
||||||
|
|
||||||
$active = db_get_boolean(true);
|
$active = db_get_boolean(true);
|
||||||
$query = "SELECT password FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
$query = "SELECT password FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
||||||
|
|
||||||
@@ -48,9 +44,7 @@ class Login
|
|||||||
* @return false|string
|
* @return false|string
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function generatePasswordRecoveryCode(string $username)
|
public function generatePasswordRecoveryCode(string $username) {
|
||||||
{
|
|
||||||
|
|
||||||
$sql = "SELECT count(1) FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
$sql = "SELECT count(1) FROM {$this->table} WHERE {$this->id_field} = :username AND active = :active";
|
||||||
|
|
||||||
$active = db_get_boolean(true);
|
$active = db_get_boolean(true);
|
||||||
@@ -88,9 +82,7 @@ class Login
|
|||||||
* @return boolean true on success; false on failure
|
* @return boolean true on success; false on failure
|
||||||
* @throws \Exception if invalid user, or db update fails.
|
* @throws \Exception if invalid user, or db update fails.
|
||||||
*/
|
*/
|
||||||
public function changePassword($username, $new_password, $old_password): bool
|
public function changePassword($username, $new_password, $old_password): bool {
|
||||||
{
|
|
||||||
|
|
||||||
list(/*NULL*/, $domain) = explode('@', $username);
|
list(/*NULL*/, $domain) = explode('@', $username);
|
||||||
|
|
||||||
$login = new Login($this->table, $this->id_field);
|
$login = new Login($this->table, $this->id_field);
|
||||||
@@ -113,4 +105,4 @@ class Login
|
|||||||
db_log($domain, 'edit_password', $username);
|
db_log($domain, 'edit_password', $username);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,8 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||||||
$h = new AdminHandler();
|
$h = new AdminHandler();
|
||||||
|
|
||||||
$login = new Login('admin', $h->getId_field());
|
$login = new Login('admin', $h->getId_field());
|
||||||
if($login->login($fUsername, $fPassword)) {
|
if ($login->login($fUsername, $fPassword)) {
|
||||||
|
|
||||||
init_session($fUsername, true);
|
init_session($fUsername, true);
|
||||||
|
|
||||||
# they've logged in, so see if they are a domain admin, as well.
|
# they've logged in, so see if they are a domain admin, as well.
|
||||||
|
@@ -48,7 +48,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||||||
|
|
||||||
$h = new MailboxHandler();
|
$h = new MailboxHandler();
|
||||||
|
|
||||||
$login = new Login('mailbox', 'username');;
|
$login = new Login('mailbox', 'username');
|
||||||
|
;
|
||||||
if ($login->login($fUsername, $fPassword)) {
|
if ($login->login($fUsername, $fPassword)) {
|
||||||
init_session($fUsername, false);
|
init_session($fUsername, false);
|
||||||
header("Location: main.php");
|
header("Location: main.php");
|
||||||
|
@@ -38,8 +38,7 @@ if ($context === 'admin' && !Config::read('forgotten_admin_password_reset') || $
|
|||||||
die('Password reset is disabled by configuration option: forgotten_admin_password_reset');
|
die('Password reset is disabled by configuration option: forgotten_admin_password_reset');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCodebyEmail($to, $username, $code)
|
function sendCodebyEmail($to, $username, $code) {
|
||||||
{
|
|
||||||
$https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
|
$https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
|
||||||
|
|
||||||
$_SERVER['REQUEST_SCHEME'] = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : $https;
|
$_SERVER['REQUEST_SCHEME'] = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : $https;
|
||||||
@@ -49,8 +48,7 @@ function sendCodebyEmail($to, $username, $code)
|
|||||||
return smtp_mail($to, Config::read('admin_email'), Config::Lang('pPassword_welcome'), Config::read('admin_smtp_password'), Config::lang_f('pPassword_recovery_email_body', $url));
|
return smtp_mail($to, Config::read('admin_email'), Config::Lang('pPassword_welcome'), Config::read('admin_smtp_password'), Config::lang_f('pPassword_recovery_email_body', $url));
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCodebySMS($to, $username, $code)
|
function sendCodebySMS($to, $username, $code) {
|
||||||
{
|
|
||||||
$text = Config::lang_f('pPassword_recovery_sms_body', $code);
|
$text = Config::lang_f('pPassword_recovery_sms_body', $code);
|
||||||
|
|
||||||
$function = Config::read('sms_send_function');
|
$function = Config::read('sms_send_function');
|
||||||
|
@@ -72,7 +72,6 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($error == 0) {
|
if ($error == 0) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($login->changePassword($username, $fPassword, $fPassword_current)) {
|
if ($login->changePassword($username, $fPassword, $fPassword_current)) {
|
||||||
flash_info(Config::Lang_f('pPassword_result_success', $username));
|
flash_info(Config::Lang_f('pPassword_result_success', $username));
|
||||||
|
@@ -44,8 +44,7 @@ $server = new Zend_XmlRpc_Server();
|
|||||||
* @param string $password
|
* @param string $password
|
||||||
* @return boolean true on success, else false.
|
* @return boolean true on success, else false.
|
||||||
*/
|
*/
|
||||||
function login($username, $password)
|
function login($username, $password) {
|
||||||
{
|
|
||||||
$h = new MailboxHandler();
|
$h = new MailboxHandler();
|
||||||
$login = new Login('mailbox', 'username');
|
$login = new Login('mailbox', 'username');
|
||||||
if ($login->login($username, $password)) {
|
if ($login->login($username, $password)) {
|
||||||
@@ -68,16 +67,14 @@ if (!isset($_SESSION['authenticated'])) {
|
|||||||
echo $server->handle();
|
echo $server->handle();
|
||||||
|
|
||||||
|
|
||||||
class UserProxy
|
class UserProxy {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $old_password
|
* @param string $old_password
|
||||||
* @param string $new_password
|
* @param string $new_password
|
||||||
* @return boolean true on success
|
* @return boolean true on success
|
||||||
*/
|
*/
|
||||||
public function changePassword($old_password, $new_password)
|
public function changePassword($old_password, $new_password) {
|
||||||
{
|
|
||||||
$uh = new MailboxHandler();
|
$uh = new MailboxHandler();
|
||||||
$username = $_SESSION['sessid']['username'] ?? '';
|
$username = $_SESSION['sessid']['username'] ?? '';
|
||||||
|
|
||||||
@@ -96,7 +93,6 @@ class UserProxy
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,20 +100,17 @@ class UserProxy
|
|||||||
* @param string $password
|
* @param string $password
|
||||||
* @return boolean true if successful.
|
* @return boolean true if successful.
|
||||||
*/
|
*/
|
||||||
public function login($username, $password)
|
public function login($username, $password) {
|
||||||
{
|
|
||||||
$login = new Login('mailbox', 'username');
|
$login = new Login('mailbox', 'username');
|
||||||
return $login->login($username, $password);
|
return $login->login($username, $password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VacationProxy
|
class VacationProxy {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @return boolean true if the vacation is removed successfully. Else false.
|
* @return boolean true if the vacation is removed successfully. Else false.
|
||||||
*/
|
*/
|
||||||
public function remove()
|
public function remove() {
|
||||||
{
|
|
||||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||||
return $vh->remove();
|
return $vh->remove();
|
||||||
}
|
}
|
||||||
@@ -126,8 +119,7 @@ class VacationProxy
|
|||||||
* @return boolean true if vacation stuff is enabled in this instance of postfixadmin
|
* @return boolean true if vacation stuff is enabled in this instance of postfixadmin
|
||||||
* and the user has the ability to make changes to it.
|
* and the user has the ability to make changes to it.
|
||||||
*/
|
*/
|
||||||
public function isVacationSupported()
|
public function isVacationSupported() {
|
||||||
{
|
|
||||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||||
return $vh->vacation_supported();
|
return $vh->vacation_supported();
|
||||||
}
|
}
|
||||||
@@ -135,8 +127,7 @@ class VacationProxy
|
|||||||
/**
|
/**
|
||||||
* @return boolean true if the user has an active vacation record etc.
|
* @return boolean true if the user has an active vacation record etc.
|
||||||
*/
|
*/
|
||||||
public function checkVacation()
|
public function checkVacation() {
|
||||||
{
|
|
||||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||||
return $vh->check_vacation();
|
return $vh->check_vacation();
|
||||||
}
|
}
|
||||||
@@ -144,8 +135,7 @@ class VacationProxy
|
|||||||
/**
|
/**
|
||||||
* @return array|bool - either array of vacation details or boolean false if the user has none.
|
* @return array|bool - either array of vacation details or boolean false if the user has none.
|
||||||
*/
|
*/
|
||||||
public function getDetails()
|
public function getDetails() {
|
||||||
{
|
|
||||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||||
return $vh->get_details();
|
return $vh->get_details();
|
||||||
}
|
}
|
||||||
@@ -159,20 +149,17 @@ class VacationProxy
|
|||||||
* @return boolean true on success.
|
* @return boolean true on success.
|
||||||
* Whatiis @replyType?? for
|
* Whatiis @replyType?? for
|
||||||
*/
|
*/
|
||||||
public function setAway($subject, $body, $interval_time = 0, $activeFrom = '2000-01-01', $activeUntil = '2099-12-31')
|
public function setAway($subject, $body, $interval_time = 0, $activeFrom = '2000-01-01', $activeUntil = '2099-12-31') {
|
||||||
{
|
|
||||||
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
$vh = new VacationHandler($_SESSION['sessid']['username']);
|
||||||
return $vh->set_away($subject, $body, $interval_time, $activeFrom, $activeUntil);
|
return $vh->set_away($subject, $body, $interval_time, $activeFrom, $activeUntil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AliasProxy
|
class AliasProxy {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @return array - array of aliases this user has. Array may be empty.
|
* @return array - array of aliases this user has. Array may be empty.
|
||||||
*/
|
*/
|
||||||
public function get()
|
public function get() {
|
||||||
{
|
|
||||||
$ah = new AliasHandler();
|
$ah = new AliasHandler();
|
||||||
$ah->init($_SESSION['sessid']['username']);
|
$ah->init($_SESSION['sessid']['username']);
|
||||||
/* I see no point in returning special addresses to the user. */
|
/* I see no point in returning special addresses to the user. */
|
||||||
@@ -186,8 +173,7 @@ class AliasProxy
|
|||||||
* @param string flag to set ('forward_and_store' or 'remote_only')
|
* @param string flag to set ('forward_and_store' or 'remote_only')
|
||||||
* @return boolean true
|
* @return boolean true
|
||||||
*/
|
*/
|
||||||
public function update($addresses, $flags)
|
public function update($addresses, $flags) {
|
||||||
{
|
|
||||||
$ah = new AliasHandler();
|
$ah = new AliasHandler();
|
||||||
$ah->init($_SESSION['sessid']['username']);
|
$ah->init($_SESSION['sessid']['username']);
|
||||||
|
|
||||||
@@ -213,8 +199,7 @@ class AliasProxy
|
|||||||
* @return boolean true if the user has 'store_and_forward' set.
|
* @return boolean true if the user has 'store_and_forward' set.
|
||||||
* (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only'
|
* (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only'
|
||||||
*/
|
*/
|
||||||
public function hasStoreAndForward()
|
public function hasStoreAndForward() {
|
||||||
{
|
|
||||||
$ah = new AliasHandler();
|
$ah = new AliasHandler();
|
||||||
$ah->init($_SESSION['sessid']['username']);
|
$ah->init($_SESSION['sessid']['username']);
|
||||||
$ah->view();
|
$ah->view();
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
class AliasHandlerTest extends \PHPUnit\Framework\TestCase {
|
||||||
{
|
protected function setUp(): void {
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
// Fake being an admin.
|
// Fake being an admin.
|
||||||
$_SESSION = [
|
$_SESSION = [
|
||||||
'sessid' => [
|
'sessid' => [
|
||||||
@@ -14,8 +11,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void {
|
||||||
{
|
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
db_query('DELETE FROM alias');
|
db_query('DELETE FROM alias');
|
||||||
db_query('DELETE FROM domain_admins');
|
db_query('DELETE FROM domain_admins');
|
||||||
@@ -24,8 +20,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBasic()
|
public function testBasic() {
|
||||||
{
|
|
||||||
$x = new AliasHandler();
|
$x = new AliasHandler();
|
||||||
$list = $x->getList("");
|
$list = $x->getList("");
|
||||||
$this->assertTrue($list);
|
$this->assertTrue($list);
|
||||||
@@ -34,8 +29,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testCannotAddAliasUntilDomainIsThere()
|
public function testCannotAddAliasUntilDomainIsThere() {
|
||||||
{
|
|
||||||
|
|
||||||
// Fake us being an admin.
|
// Fake us being an admin.
|
||||||
|
|
||||||
@@ -69,8 +63,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
/**
|
/**
|
||||||
* @see https://github.com/postfixadmin/postfixadmin/pull/375 and https://github.com/postfixadmin/postfixadmin/issues/358
|
* @see https://github.com/postfixadmin/postfixadmin/pull/375 and https://github.com/postfixadmin/postfixadmin/issues/358
|
||||||
*/
|
*/
|
||||||
public function testCannotAddAliasThatPointsToItself()
|
public function testCannotAddAliasThatPointsToItself() {
|
||||||
{
|
|
||||||
// Fake being an admin.
|
// Fake being an admin.
|
||||||
$_SESSION = [
|
$_SESSION = [
|
||||||
'sessid' => [
|
'sessid' => [
|
||||||
@@ -153,8 +146,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
], $x->errormsg);
|
], $x->errormsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddingDataEtc()
|
public function testAddingDataEtc() {
|
||||||
{
|
|
||||||
|
|
||||||
// Fake being an admin.
|
// Fake being an admin.
|
||||||
$_SESSION = [
|
$_SESSION = [
|
||||||
@@ -207,8 +199,7 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function addDomain(string $domain, string $username): void
|
private function addDomain(string $domain, string $username): void {
|
||||||
{
|
|
||||||
// Fake being an admin.
|
// Fake being an admin.
|
||||||
$_SESSION = [
|
$_SESSION = [
|
||||||
'sessid' => [
|
'sessid' => [
|
||||||
@@ -265,12 +256,9 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
foreach ($expected as $k => $v) {
|
foreach ($expected as $k => $v) {
|
||||||
$this->assertEquals($v, $result[$domain][$k]);
|
$this->assertEquals($v, $result[$domain][$k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testYouCannotAddMoreAliasesThanTheDomainLimit()
|
public function testYouCannotAddMoreAliasesThanTheDomainLimit() {
|
||||||
{
|
|
||||||
|
|
||||||
$this->addDomain('example.com', 'admin');
|
$this->addDomain('example.com', 'admin');
|
||||||
|
|
||||||
// default limit is 11 aliases.... so it should exit once we get past that.
|
// default limit is 11 aliases.... so it should exit once we get past that.
|
||||||
@@ -288,7 +276,6 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
|
|
||||||
foreach (range(1, 7) as $char) {
|
foreach (range(1, 7) as $char) {
|
||||||
|
|
||||||
$newAlias = $char . '-test@example.com';
|
$newAlias = $char . '-test@example.com';
|
||||||
|
|
||||||
$x = new AliasHandler(1, 'admin', true);
|
$x = new AliasHandler(1, 'admin', true);
|
||||||
@@ -335,13 +322,10 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
'address' => "You have reached your limit to create aliases!",
|
'address' => "You have reached your limit to create aliases!",
|
||||||
0 => "one or more values are invalid!"
|
0 => "one or more values are invalid!"
|
||||||
], $x->errormsg);
|
], $x->errormsg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testLoadsOfAliasesGetHandledByPager()
|
public function testLoadsOfAliasesGetHandledByPager() {
|
||||||
{
|
|
||||||
|
|
||||||
$this->addDomain('example.com', 'admin');
|
$this->addDomain('example.com', 'admin');
|
||||||
|
|
||||||
// default limit is 11 aliases.... so it should exit once we get past that.
|
// default limit is 11 aliases.... so it should exit once we get past that.
|
||||||
@@ -369,7 +353,6 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals(88, $domain['mailboxes']);
|
$this->assertEquals(88, $domain['mailboxes']);
|
||||||
|
|
||||||
foreach (range(1, 80) as $char) {
|
foreach (range(1, 80) as $char) {
|
||||||
|
|
||||||
$newAlias = $char . '-test@example.com';
|
$newAlias = $char . '-test@example.com';
|
||||||
|
|
||||||
$x = new AliasHandler(1, 'admin', true);
|
$x = new AliasHandler(1, 'admin', true);
|
||||||
@@ -401,6 +384,5 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$this->assertEquals(5, count($results));
|
$this->assertEquals(5, count($results));
|
||||||
$this->assertTrue(isset($results['31-test@example.com']));
|
$this->assertTrue(isset($results['31-test@example.com']));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
class DomainHandlerTest extends \PHPUnit\Framework\TestCase {
|
||||||
{
|
public function testBasic() {
|
||||||
public function testBasic()
|
|
||||||
{
|
|
||||||
$x = new DomainHandler();
|
$x = new DomainHandler();
|
||||||
|
|
||||||
$list = $x->getList("");
|
$list = $x->getList("");
|
||||||
@@ -15,8 +13,7 @@ class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertEmpty($results);
|
$this->assertEmpty($results);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddAndUpdate()
|
public function testAddAndUpdate() {
|
||||||
{
|
|
||||||
// Fake being an admin.
|
// Fake being an admin.
|
||||||
$_SESSION = [
|
$_SESSION = [
|
||||||
'sessid' => [
|
'sessid' => [
|
||||||
@@ -101,7 +98,5 @@ class DomainHandlerTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$this->assertEquals(99, $d['aliases']);
|
$this->assertEquals(99, $d['aliases']);
|
||||||
$this->assertEquals(88, $d['mailboxes']);
|
$this->assertEquals(88, $d['mailboxes']);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class LoginTest extends \PHPUnit\Framework\TestCase
|
class LoginTest extends \PHPUnit\Framework\TestCase {
|
||||||
{
|
public function setUp(): void {
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->cleanUp();
|
$this->cleanUp();
|
||||||
|
|
||||||
db_execute("INSERT INTO domain(`domain`, description, transport) values ('example.com', 'test', 'foo')", [], true);
|
db_execute("INSERT INTO domain(`domain`, description, transport) values ('example.com', 'test', 'foo')", [], true);
|
||||||
@@ -24,20 +21,17 @@ VALUES(:username, :password, :name, :maildir, :local_part, :domain)",
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function tearDown(): void
|
public function tearDown(): void {
|
||||||
{
|
|
||||||
$this->cleanUp();
|
$this->cleanUp();
|
||||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cleanUp()
|
private function cleanUp() {
|
||||||
{
|
|
||||||
db_query('DELETE FROM mailbox');
|
db_query('DELETE FROM mailbox');
|
||||||
db_query('DELETE FROM domain');
|
db_query('DELETE FROM domain');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidUsers()
|
public function testInvalidUsers() {
|
||||||
{
|
|
||||||
$login = new Login('mailbox', 'username');
|
$login = new Login('mailbox', 'username');
|
||||||
|
|
||||||
$this->assertFalse($login->login('test', 'password'));
|
$this->assertFalse($login->login('test', 'password'));
|
||||||
@@ -46,23 +40,18 @@ VALUES(:username, :password, :name, :maildir, :local_part, :domain)",
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testValidLogin()
|
public function testValidLogin() {
|
||||||
{
|
|
||||||
$login = new Login('mailbox', 'username');
|
$login = new Login('mailbox', 'username');
|
||||||
|
|
||||||
$this->assertFalse($login->login('test', 'password'));
|
$this->assertFalse($login->login('test', 'password'));
|
||||||
$this->assertFalse($login->login('test', 'foobar'));
|
$this->assertFalse($login->login('test', 'foobar'));
|
||||||
$this->assertFalse($login->login('', ''));
|
$this->assertFalse($login->login('', ''));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPasswordRecovery()
|
public function testPasswordRecovery() {
|
||||||
{
|
|
||||||
|
|
||||||
$login = new Login('mailbox', 'username');
|
$login = new Login('mailbox', 'username');
|
||||||
$this->assertFalse($login->generatePasswordRecoveryCode(''));
|
$this->assertFalse($login->generatePasswordRecoveryCode(''));
|
||||||
$this->assertFalse($login->generatePasswordRecoveryCode('doesnotexist'));
|
$this->assertFalse($login->generatePasswordRecoveryCode('doesnotexist'));
|
||||||
$this->assertNotEmpty($login->generatePasswordRecoveryCode('test@example.com'));
|
$this->assertNotEmpty($login->generatePasswordRecoveryCode('test@example.com'));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,6 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase {
|
|||||||
$results = $x->result();
|
$results = $x->result();
|
||||||
|
|
||||||
$this->assertEmpty($results);
|
$this->assertEmpty($results);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user