add first unit tests for DomainZones ApiCommand
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -42,8 +42,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
|||||||
$content = $this->getParam('content', true, null);
|
$content = $this->getParam('content', true, null);
|
||||||
$ttl = $this->getParam('ttl', true, 18000);
|
$ttl = $this->getParam('ttl', true, 18000);
|
||||||
|
|
||||||
// validation
|
if ($result['parentdomainid'] != '0') {
|
||||||
if ($result['isbinddomain'] != '1') {
|
throw new Exception("DNS zones can only be generated for the main domain, not for subdomains", 406);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result['subisbinddomain'] != '1') {
|
||||||
standard_error('dns_domain_nodns', '', true);
|
standard_error('dns_domain_nodns', '', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +294,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
|||||||
));
|
));
|
||||||
$id = $result['id'];
|
$id = $result['id'];
|
||||||
|
|
||||||
if ($result['isbinddomain'] != '1') {
|
if ($result['parentdomainid'] != '0') {
|
||||||
|
throw new Exception("DNS zones can only be generated for the main domain, not for subdomains", 406);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result['subisbinddomain'] != '1') {
|
||||||
standard_error('dns_domain_nodns', '', true);
|
standard_error('dns_domain_nodns', '', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,8 +342,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
|||||||
'id' => $entry_id,
|
'id' => $entry_id,
|
||||||
'did' => $id
|
'did' => $id
|
||||||
), true, true);
|
), true, true);
|
||||||
// re-generate bind configs
|
if ($del_stmt->rowCount() > 0) {
|
||||||
inserttask('4');
|
// re-generate bind configs
|
||||||
return $this->response(200, "successfull", true);
|
inserttask('4');
|
||||||
|
return $this->response(200, "successfull", true);
|
||||||
|
}
|
||||||
|
return $this->response(304, "successfull", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
if (count($customer_ids) > 0) {
|
if (count($customer_ids) > 0) {
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT d.*, pd.`subcanemaildomain`
|
SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain
|
||||||
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
||||||
WHERE " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . " AND d.`customerid` IN (:customerids)
|
WHERE " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . " AND d.`customerid` IN (:customerids)
|
||||||
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
||||||
@@ -361,7 +361,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT d.*, pd.`subcanemaildomain`
|
SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain
|
||||||
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
||||||
WHERE " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . "
|
WHERE " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . "
|
||||||
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
||||||
@@ -375,7 +375,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
|||||||
throw new Exception("You cannot access this resource", 405);
|
throw new Exception("You cannot access this resource", 405);
|
||||||
}
|
}
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT d.*, pd.`subcanemaildomain`
|
SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain
|
||||||
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
FROM `" . TABLE_PANEL_DOMAINS . "` d, `" . TABLE_PANEL_DOMAINS . "` pd
|
||||||
WHERE d.`customerid`= :customerid AND " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . "
|
WHERE d.`customerid`= :customerid AND " . ($id > 0 ? "d.`id` = :iddn" : "d.`domain` = :iddn") . "
|
||||||
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
AND ((d.`parentdomainid`!='0' AND pd.`id` = d.`parentdomainid`) OR (d.`parentdomainid`='0' AND pd.`id` = d.`id`))
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<directory>tests/Emails</directory>
|
<directory>tests/Emails</directory>
|
||||||
<directory>tests/Extras</directory>
|
<directory>tests/Extras</directory>
|
||||||
<directory>tests/Backup</directory>
|
<directory>tests/Backup</directory>
|
||||||
|
<directory>tests/DomainZones</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
|
|||||||
68
tests/DomainZones/DomainZonesTest.php
Normal file
68
tests/DomainZones/DomainZonesTest.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @covers ApiCommand
|
||||||
|
* @covers ApiParameter
|
||||||
|
* @covers SubDomains
|
||||||
|
* @covers DomainZones
|
||||||
|
*/
|
||||||
|
class DomainZonesTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testCustomerDomainZonesGet()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
Settings::Set('system.dnsenabled', 1, true);
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'domainname' => 'test2.local'
|
||||||
|
];
|
||||||
|
$json_result = DomainZones::getLocal($customer_userdata, $data)->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertTrue(count($result) > 1);
|
||||||
|
$this->assertEquals('$ORIGIN test2.local.', $result[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerDomainZonesGetNoSubdomains()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
Settings::Set('system.dnsenabled', 1, true);
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'domainname' => 'mysub2.test2.local'
|
||||||
|
];
|
||||||
|
$this->expectExceptionCode(406);
|
||||||
|
$this->expectExceptionMessage("DNS zones can only be generated for the main domain, not for subdomains");
|
||||||
|
DomainZones::getLocal($customer_userdata, $data)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminDomainZonesListing()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$this->expectExceptionCode(303);
|
||||||
|
DomainZones::getLocal($admin_userdata)->listing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdminDomainZonesUpdate()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$this->expectExceptionCode(303);
|
||||||
|
DomainZones::getLocal($admin_userdata)->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,7 +68,8 @@ class DomainsTest extends TestCase
|
|||||||
$reseller_userdata['caneditphpsettings'] = 1;
|
$reseller_userdata['caneditphpsettings'] = 1;
|
||||||
$data = [
|
$data = [
|
||||||
'domain' => 'test2.local',
|
'domain' => 'test2.local',
|
||||||
'customerid' => 1
|
'customerid' => 1,
|
||||||
|
'isbinddomain' => 1
|
||||||
];
|
];
|
||||||
// the reseller is not allowed to use the default ip/port
|
// the reseller is not allowed to use the default ip/port
|
||||||
$this->expectExceptionMessage("The ip/port combination you have chosen doesn't exist.");
|
$this->expectExceptionMessage("The ip/port combination you have chosen doesn't exist.");
|
||||||
|
|||||||
Reference in New Issue
Block a user