add first unit tests for DomainZones ApiCommand

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-22 14:56:18 +01:00
parent bd7f2c2654
commit 48d7110779
5 changed files with 90 additions and 10 deletions

View File

@@ -42,8 +42,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
$content = $this->getParam('content', true, null);
$ttl = $this->getParam('ttl', true, 18000);
// validation
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);
}
@@ -291,7 +294,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
));
$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);
}
@@ -335,8 +342,11 @@ class DomainZones extends ApiCommand implements ResourceEntity
'id' => $entry_id,
'did' => $id
), true, true);
// re-generate bind configs
inserttask('4');
return $this->response(200, "successfull", true);
if ($del_stmt->rowCount() > 0) {
// re-generate bind configs
inserttask('4');
return $this->response(200, "successfull", true);
}
return $this->response(304, "successfull", true);
}
}

View File

@@ -347,7 +347,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
}
if (count($customer_ids) > 0) {
$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
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`))
@@ -361,7 +361,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
}
} else {
$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
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`))
@@ -375,7 +375,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
throw new Exception("You cannot access this resource", 405);
}
$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
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`))