more unit-tests
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -88,6 +88,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param string $new_loginname
|
||||
* @param string $admin_password
|
||||
* optional, default auto-generated
|
||||
* @param string $def_language
|
||||
@@ -168,13 +169,13 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
// required parameters
|
||||
$name = $this->getParam('name');
|
||||
$email = $this->getParam('email');
|
||||
$loginname = $this->getParam('new_loginname');
|
||||
|
||||
// parameters
|
||||
$def_language = $this->getParam('def_language', true, Settings::Get('panel.standardlanguage'));
|
||||
$custom_notes = $this->getParam('custom_notes', true, '');
|
||||
$custom_notes_show = $this->getParam('custom_notes_show', true, 0);
|
||||
$password = $this->getParam('admin_password', true, '');
|
||||
$loginname = $this->getParam('new_loginname', true, '');
|
||||
|
||||
$diskspace = $this->getUlParam('diskspace', 'diskspace_ul', true, 0);
|
||||
$traffic = $this->getUlParam('traffic', 'traffic_ul', true, 0);
|
||||
@@ -239,28 +240,13 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
'login' => $loginname
|
||||
), true, true);
|
||||
|
||||
if ($loginname == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
'myloginname'
|
||||
), '', true);
|
||||
} elseif (strtolower($loginname_check['loginname']) == strtolower($loginname) || strtolower($loginname_check_admin['loginname']) == strtolower($loginname)) {
|
||||
if (strtolower($loginname_check['loginname']) == strtolower($loginname) || strtolower($loginname_check_admin['loginname']) == strtolower($loginname)) {
|
||||
standard_error('loginnameexists', $loginname, true);
|
||||
} // Accounts which match systemaccounts are not allowed, filtering them
|
||||
elseif (preg_match('/^' . preg_quote(Settings::Get('customer.accountprefix'), '/') . '([0-9]+)/', $loginname)) {
|
||||
standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix'), true);
|
||||
} elseif (! validateUsername($loginname)) {
|
||||
standard_error('loginnameiswrong', $loginname, true);
|
||||
} elseif ($name == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
'myname'
|
||||
), '', true);
|
||||
} elseif ($email == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
'emailadd'
|
||||
), '', true);
|
||||
} elseif (! validateEmail($email)) {
|
||||
standard_error('emailiswrong', $email, true);
|
||||
} else {
|
||||
@@ -548,17 +534,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
$theme = Settings::Get('panel.default_theme');
|
||||
}
|
||||
|
||||
if ($name == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
'myname'
|
||||
), '', true);
|
||||
} elseif ($email == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
'emailadd'
|
||||
), '', true);
|
||||
} elseif (! validateEmail($email)) {
|
||||
if (! validateEmail($email)) {
|
||||
standard_error('emailiswrong', $email, true);
|
||||
} else {
|
||||
|
||||
|
||||
@@ -51,6 +51,78 @@ class AdminsTest extends TestCase
|
||||
$this->assertEquals(0, $result['customers_see_all']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminAdminsAdd
|
||||
*/
|
||||
public function testAdminAdminsAddLoginnameExists()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'reseller',
|
||||
'email' => 'testreseller@froxlor.org',
|
||||
'name' => 'Testreseller'
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Loginname reseller already exists');
|
||||
Admins::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminAdminsAddLoginnameExists
|
||||
*/
|
||||
public function testAdminAdminsAddLoginnameIsSystemaccount()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'web2',
|
||||
'email' => 'testreseller@froxlor.org',
|
||||
'name' => 'Testreseller'
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('You cannot create accounts which are similar to system accounts (as for example begin with "web"). Please enter another account name.');
|
||||
Admins::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminAdminsAddLoginnameIsSystemaccount
|
||||
*/
|
||||
public function testAdminAdminsAddLoginnameInvalid()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'reslr-',
|
||||
'email' => 'testreseller@froxlor.org',
|
||||
'name' => 'Testreseller'
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Loginname "reslr-" contains illegal characters.');
|
||||
Admins::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminAdminsAddLoginnameIsSystemaccount
|
||||
*/
|
||||
public function testAdminAdminsAddLoginnameInvalidEmail()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'reslr',
|
||||
'email' => 'testreseller.froxlor.org',
|
||||
'name' => 'Testreseller'
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Email-address testreseller.froxlor.org contains invalid characters or is incomplete');
|
||||
Admins::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
public function testAdminAdminsAddNotAllowed()
|
||||
{
|
||||
global $admin_userdata;
|
||||
@@ -160,8 +232,7 @@ class AdminsTest extends TestCase
|
||||
$data = [
|
||||
'new_loginname' => 'resellertest',
|
||||
'email' => 'testreseller@froxlor.org',
|
||||
'name' => 'Testreseller',
|
||||
'admin_password' => 'h0lYmo1y'
|
||||
'name' => 'Testreseller'
|
||||
];
|
||||
|
||||
$json_result = Admins::getLocal($admin_userdata, $data)->add();
|
||||
|
||||
@@ -10,10 +10,69 @@ use PHPUnit\Framework\TestCase;
|
||||
class CustomerBackupsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testAdminCustomerBackupsNotEnabled()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('system.backupenabled', 0, true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$this->expectExceptionCode(405);
|
||||
$this->expectExceptionMessage("You cannot access this resource");
|
||||
CustomerBackups::getLocal($customer_userdata)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAdminCustomerBackupsNotEnabled
|
||||
*/
|
||||
public function testAdminCustomerBackupsExtrasHidden()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('system.backupenabled', 1, true);
|
||||
Settings::Set('panel.customer_hide_options', 'extras', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$this->expectExceptionCode(405);
|
||||
$this->expectExceptionMessage("You cannot access this resource");
|
||||
CustomerBackups::getLocal($customer_userdata)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAdminCustomerBackupsExtrasHidden
|
||||
*/
|
||||
public function testAdminCustomerBackupsExtrasBackupHidden()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', 'extras.backup', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$this->expectExceptionCode(405);
|
||||
$this->expectExceptionMessage("You cannot access this resource");
|
||||
CustomerBackups::getLocal($customer_userdata)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAdminCustomerBackupsExtrasBackupHidden
|
||||
*/
|
||||
public function testCustomerCustomerBackupsAdd()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', '', true);
|
||||
Database::query("TRUNCATE TABLE `panel_tasks`;");
|
||||
|
||||
// get customer
|
||||
@@ -24,16 +83,16 @@ class CustomerBackupsTest extends TestCase
|
||||
|
||||
$data = [
|
||||
'path' => '/my-backup',
|
||||
'backup_dbs' => 1,
|
||||
'backup_mail' => 2,
|
||||
'backup_web' => 1
|
||||
'backup_dbs' => 2,
|
||||
'backup_mail' => 3,
|
||||
'backup_web' => 4
|
||||
];
|
||||
$json_result = CustomerBackups::getLocal($customer_userdata, $data)->add();
|
||||
$result = json_decode($json_result, true)['data'];
|
||||
$this->assertEquals($customer_userdata['documentroot'] . 'my-backup/', $result['destdir']);
|
||||
$this->assertEquals('1', $result['backup_dbs']);
|
||||
$this->assertEquals('0', $result['backup_dbs']);
|
||||
$this->assertEquals('0', $result['backup_mail']);
|
||||
$this->assertEquals('1', $result['backup_web']);
|
||||
$this->assertEquals('0', $result['backup_web']);
|
||||
}
|
||||
|
||||
public function testAdminCustomerBackupsGet()
|
||||
@@ -61,9 +120,9 @@ class CustomerBackupsTest extends TestCase
|
||||
$json_result = CustomerBackups::getLocal($admin_userdata)->listing();
|
||||
$result = json_decode($json_result, true)['data'];
|
||||
$this->assertEquals(1, $result['count']);
|
||||
$this->assertEquals('1', $result['list'][0]['data']['backup_dbs']);
|
||||
$this->assertEquals('0', $result['list'][0]['data']['backup_dbs']);
|
||||
$this->assertEquals('0', $result['list'][0]['data']['backup_mail']);
|
||||
$this->assertEquals('1', $result['list'][0]['data']['backup_web']);
|
||||
$this->assertEquals('0', $result['list'][0]['data']['backup_web']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers ApiCommand
|
||||
* @covers ApiParameter
|
||||
* @covers Customers
|
||||
* @covers Admins
|
||||
*/
|
||||
class CustomersTest extends TestCase
|
||||
{
|
||||
@@ -83,6 +85,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testAdminCustomersList()
|
||||
@@ -95,6 +98,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testResellerCustomersList()
|
||||
@@ -112,6 +116,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testCustomerCustomersList()
|
||||
@@ -130,6 +135,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testCustomerCustomersGet()
|
||||
@@ -165,6 +171,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testCustomerCustomersGetForeign()
|
||||
@@ -185,6 +192,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testAdminCustomerUpdateDeactivate()
|
||||
@@ -209,6 +217,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testCustomerCustomersGetWhenDeactivated()
|
||||
@@ -230,6 +239,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testCustomerCustomersUpdate()
|
||||
@@ -266,6 +276,7 @@ class CustomersTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAdd
|
||||
*/
|
||||
public function testResellerCustomersAddAllocateMore()
|
||||
@@ -403,4 +414,134 @@ class CustomersTest extends TestCase
|
||||
|
||||
$this->assertEquals(2, $result['adminid']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersMove
|
||||
*/
|
||||
public function testAdminCustomersAddLoginnameIsSystemaccount()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'web1',
|
||||
'email' => 'team@froxlor.org',
|
||||
'firstname' => 'Test',
|
||||
'name' => 'Testman',
|
||||
'customernumber' => 1338,
|
||||
'diskspace' => - 1,
|
||||
'traffic' => - 1,
|
||||
'subdomains' => 15,
|
||||
'emails' => - 1,
|
||||
'email_accounts' => 15,
|
||||
'email_forwarders' => 15,
|
||||
'email_imap' => 1,
|
||||
'email_pop3' => 0,
|
||||
'ftps' => 15,
|
||||
'tickets' => 15,
|
||||
'mysqls' => 15,
|
||||
'createstdsubdomain' => 1,
|
||||
'new_customer_password' => 'h0lYmo1y',
|
||||
'sendpassword' => 1,
|
||||
'phpenabled' => 1,
|
||||
'store_defaultindex' => 1,
|
||||
'custom_notes' => 'secret',
|
||||
'custom_notes_show' => 0,
|
||||
'gender' => 5,
|
||||
'allowed_phpconfigs' => array(
|
||||
1
|
||||
)
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('You cannot create accounts which are similar to system accounts (as for example begin with "web"). Please enter another account name.');
|
||||
Customers::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAddLoginnameIsSystemaccount
|
||||
*/
|
||||
public function testAdminCustomersAddAutoLoginname()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('system.lastaccountnumber', 0, true);
|
||||
Settings::Set('ticket.enabled', 0, true);
|
||||
|
||||
$data = [
|
||||
'new_loginname' => '',
|
||||
'email' => 'team@froxlor.org',
|
||||
'firstname' => 'Test2',
|
||||
'name' => 'Testman2',
|
||||
'customernumber' => 1338,
|
||||
'sendpassword' => 0,
|
||||
'perlenabled' => 2,
|
||||
'dnsenabled' => 4
|
||||
];
|
||||
|
||||
$json_result = Customers::getLocal($admin_userdata, $data)->add();
|
||||
$result = json_decode($json_result, true)['data'];
|
||||
$this->assertEquals('web1', $result['loginname']);
|
||||
$this->assertEquals(1338, $result['customernumber']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAddAutoLoginname
|
||||
*/
|
||||
public function testAdminCustomersAddLoginnameExists()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'test1',
|
||||
'email' => 'team@froxlor.org',
|
||||
'firstname' => 'Test2',
|
||||
'name' => 'Testman2',
|
||||
'customernumber' => 1339
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Loginname test1 already exists');
|
||||
Customers::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAddLoginnameExists
|
||||
*/
|
||||
public function testAdminCustomersAddLoginnameInvalid()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'user-',
|
||||
'email' => 'team@froxlor.org',
|
||||
'firstname' => 'Test2',
|
||||
'name' => 'Testman2',
|
||||
'customernumber' => 1339
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Loginname "user-" contains illegal characters.');
|
||||
Customers::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testAdminCustomersAddLoginnameExists
|
||||
*/
|
||||
public function testAdminCustomersAddLoginnameInvalid2()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
$data = [
|
||||
'new_loginname' => 'useruseruseruseruseruserX',
|
||||
'email' => 'team@froxlor.org',
|
||||
'firstname' => 'Test2',
|
||||
'name' => 'Testman2',
|
||||
'customernumber' => 1339
|
||||
];
|
||||
|
||||
$this->expectExceptionMessage('Loginname contains too many characters. Only ' . (14 - strlen(Settings::Get('customer.mysqlprefix'))) . ' characters are allowed.');
|
||||
Customers::getLocal($admin_userdata, $data)->add();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ use PHPUnit\Framework\TestCase;
|
||||
* @covers Emails
|
||||
* @covers EmailForwarders
|
||||
* @covers EmailAccounts
|
||||
* @covers Customers
|
||||
* @covers Admins
|
||||
*/
|
||||
class MailsTest extends TestCase
|
||||
{
|
||||
@@ -97,10 +99,71 @@ class MailsTest extends TestCase
|
||||
$this->assertEquals('other@domain.tld', $result['destination']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCustomerEmailForwardersAdd
|
||||
*/
|
||||
public function testCustomerEmailForwardersAddNoMoreResources()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$customer_userdata['email_forwarders_used'] = $customer_userdata['email_forwarders'];
|
||||
$this->expectExceptionCode(406);
|
||||
$this->expectExceptionMessage("No more resources available");
|
||||
EmailForwarders::getLocal($customer_userdata)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCustomerEmailForwardersAddNoMoreResources
|
||||
*/
|
||||
public function testCustomerEmailForwardersAddEmailHidden()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', 'email', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$this->expectExceptionCode(405);
|
||||
$this->expectExceptionMessage("You cannot access this resource");
|
||||
EmailForwarders::getLocal($customer_userdata)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCustomerEmailForwardersAddEmailHidden
|
||||
*/
|
||||
public function testCustomerEmailForwardersDeleteEmailHidden()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', 'email', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
))->get();
|
||||
$customer_userdata = json_decode($json_result, true)['data'];
|
||||
$this->expectExceptionCode(405);
|
||||
$this->expectExceptionMessage("You cannot access this resource");
|
||||
EmailForwarders::getLocal($customer_userdata)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCustomerEmailForwardersDeleteEmailHidden
|
||||
*/
|
||||
public function testCustomerEmailForwardersAddAnother()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', '', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
@@ -245,6 +308,8 @@ class MailsTest extends TestCase
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Settings::Set('panel.customer_hide_options', '', true);
|
||||
|
||||
// get customer
|
||||
$json_result = Customers::getLocal($admin_userdata, array(
|
||||
'loginname' => 'test1'
|
||||
|
||||
@@ -5,6 +5,8 @@ use PHPUnit\Framework\TestCase;
|
||||
* @covers ApiCommand
|
||||
* @covers ApiParameter
|
||||
* @covers Ftps
|
||||
* @covers Customers
|
||||
* @covers Admins
|
||||
*/
|
||||
class FtpsTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ use PHPUnit\Framework\TestCase;
|
||||
* @covers ApiCommand
|
||||
* @covers ApiParameter
|
||||
* @covers Mysqls
|
||||
* @covers Customers
|
||||
* @covers Admins
|
||||
*/
|
||||
class MysqlsTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ use PHPUnit\Framework\TestCase;
|
||||
* @covers ApiParameter
|
||||
* @covers SubDomains
|
||||
* @covers Domains
|
||||
* @covers Customers
|
||||
* @covers Admins
|
||||
*/
|
||||
class SubDomainsTest extends TestCase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user