minor fixes and first tests for Domains-ApiCommand

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p) 2018-03-01 16:46:47 +01:00
parent 2bf5e90a77
commit 02616d3080
4 changed files with 92 additions and 15 deletions

View File

@ -69,7 +69,6 @@ class ConfigServicesCmd extends CmdLineHandler
self::println("--daemon\t\tWhen running --apply you can specify a daemon. This will be the only service that gets configured");
self::println("\t\t\tExample: --apply=/path/to/my-config.json --daemon=apache24");
self::println("");
self::println("");
self::println("--import-settings\tImport settings from another froxlor installation. This should be done prior to running --apply or alternatively in the same command together.");
self::println("\t\t\tExample: --import-settings=/path/to/Froxlor_settings-[version]-[dbversion]-[date].json");
self::println("");

View File

@ -183,10 +183,6 @@ class Domains extends ApiCommand implements ResourceEntity
))->get();
$customer = json_decode($json_result, true)['data'];
if (empty($customer) || $customer['customerid'] != $customerid) {
standard_error('customerdoesntexist', '', true);
}
if ($this->getUserDetail('customers_see_all') == '1') {
$admin_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_ADMINS . "`
@ -194,10 +190,6 @@ class Domains extends ApiCommand implements ResourceEntity
$admin = Database::pexecute_first($admin_stmt, array(
'adminid' => $adminid
), true, true);
if (empty($admin) || $admin['adminid'] != $adminid) {
standard_error('admindoesntexist', '', true);
}
} else {
$adminid = $this->getUserDetail('adminid');
$admin = $this->getUserData();

View File

@ -26,13 +26,12 @@ function getIpPortCombinations($ssl = false) {
if ($userinfo['ip'] != '-1') {
$admin_ip_stmt = Database::prepare("
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = IN (:ipid)
");
$admin_ip = Database::pexecute_first($admin_ip_stmt, array('ipid' => $userinfo['ip']));
$additional_conditions_array[] = "`ip` = :adminip";
$additional_conditions_params['adminip'] = $admin_ip['ip'];
$admin_ip = null;
$myips = implode(",", json_decode($userinfo['ip'], true));
Database::pexecute($admin_ip_stmt, array('ipid' => $myips));
$additional_conditions_array[] = "`ip` IN (:adminips)";
$additional_conditions_params['adminips'] = $myips;
}
if ($ssl !== null) {

View File

@ -0,0 +1,87 @@
<?php
use PHPUnit\Framework\TestCase;
/**
* @covers ApiCommand
* @covers SubDomains
* @covers Domains
*/
class DomainsTest extends TestCase
{
public function testAdminDomainsAdd()
{
global $admin_userdata;
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'domain' => 'test.local',
'customerid' => $customer_userdata['customerid']
];
$json_result = Domains::getLocal($admin_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals($customer_userdata['documentroot'].'test.local/', $result['documentroot']);
}
/**
* @depends testAdminDomainsAdd
*/
public function testAdminDomainsList()
{
global $admin_userdata;
$json_result = Domains::getLocal($admin_userdata)->list();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(1, $result['count']);
$this->assertEquals('test.local', $result['list'][0]['domain']);
}
public function testAdminDomainsAddSysHostname()
{
global $admin_userdata;
$data = [
'domain' => 'dev.froxlor.org',
'customerid' => 1
];
$this->expectExceptionMessage('The server-hostname cannot be used as customer-domain.');
$json_result = Domains::getLocal($admin_userdata, $data)->add();
}
public function testAdminDomainsAddNoPunycode()
{
global $admin_userdata;
$data = [
'domain' => 'xn--asdasd.tld',
'customerid' => 1
];
$this->expectExceptionMessage('You must not specify punycode (IDNA). The domain will automatically be converted');
$json_result = Domains::getLocal($admin_userdata, $data)->add();
}
public function testAdminDomainsAddInvalidDomain()
{
global $admin_userdata;
$data = [
'domain' => 'dom?*ain.tld',
'customerid' => 1
];
$this->expectExceptionMessage("Wrong Input in Field 'Domain'");
$json_result = Domains::getLocal($admin_userdata, $data)->add();
}
/**
* @depends testAdminDomainsList
*/
public function testAdminDomainsDelete()
{
global $admin_userdata;
$data = [
'domainname' => 'test.local',
'delete_mainsubdomains' => 1
];
$json_result = Domains::getLocal($admin_userdata, $data)->delete();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test.local', $result['domain']);
}
}