minor fixes in SubDomains.add; first Unit-Tests for SubDomains-ApiCommand
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* @since 0.10.0
|
* @since 0.10.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Subdomains extends ApiCommand implements ResourceEntity
|
class SubDomains extends ApiCommand implements ResourceEntity
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +31,7 @@ class Subdomains extends ApiCommand implements ResourceEntity
|
|||||||
* optional, destination path relative to the customers-homedir, default is customers-homedir
|
* optional, destination path relative to the customers-homedir, default is customers-homedir
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* optional, overwrites path value with an URL to generate a redirect, alternatively use the path parameter also for URLs
|
* optional, overwrites path value with an URL to generate a redirect, alternatively use the path parameter also for URLs
|
||||||
* @param string $openbasedir_path
|
* @param int $openbasedir_path
|
||||||
* optional, either 0 for customers-homedir or 1 for domains-docroot
|
* optional, either 0 for customers-homedir or 1 for domains-docroot
|
||||||
* @param int $phpsettingid
|
* @param int $phpsettingid
|
||||||
* optional, php-settings-id, if empty the $domain value is used
|
* optional, php-settings-id, if empty the $domain value is used
|
||||||
@@ -116,18 +116,25 @@ class Subdomains extends ApiCommand implements ResourceEntity
|
|||||||
if ($completedomain == Settings::Get('system.hostname')) {
|
if ($completedomain == Settings::Get('system.hostname')) {
|
||||||
standard_error('admin_domain_emailsystemhostname', '', true);
|
standard_error('admin_domain_emailsystemhostname', '', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether the domain already exists
|
// check whether the domain already exists
|
||||||
try {
|
$completedomain_stmt = Database::prepare("
|
||||||
$json_result = SubDomains::getLocal($this->getUserData(), array(
|
SELECT * FROM `" . TABLE_PANEL_DOMAINS . "`
|
||||||
'domainname' => $completedomain
|
WHERE `domain` = :domain
|
||||||
))->get();
|
AND `customerid` = :customerid
|
||||||
|
AND `email_only` = '0'
|
||||||
|
AND `caneditdomain` = '1'
|
||||||
|
");
|
||||||
|
$completedomain_check = Database::pexecute_first($completedomain_stmt, array(
|
||||||
|
"domain" => $completedomain,
|
||||||
|
"customerid" => $customer_id
|
||||||
|
), true, true);
|
||||||
|
|
||||||
|
if ($completedomain_check) {
|
||||||
// no exception so far - domain exists
|
// no exception so far - domain exists
|
||||||
standard_error('domainexistalready', $completedomain, true);
|
standard_error('domainexistalready', $completedomain, true);
|
||||||
} catch (Exception $e) {
|
|
||||||
// all good, domain does not exist
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// alias domain checked?
|
// alias domain checked?
|
||||||
if ($aliasdomain != 0) {
|
if ($aliasdomain != 0) {
|
||||||
// also check ip/port combination to be the same, #176
|
// also check ip/port combination to be the same, #176
|
||||||
@@ -381,7 +388,7 @@ class Subdomains extends ApiCommand implements ResourceEntity
|
|||||||
} else {
|
} else {
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_PANEL_DOMAINS . "`
|
SELECT * FROM `" . TABLE_PANEL_DOMAINS . "`
|
||||||
WHERE " . ($id > 0 ? "`id` = :iddn" : "`databasename` = :iddn"));
|
WHERE " . ($id > 0 ? "`id` = :iddn" : "`domainname` = :iddn"));
|
||||||
$params = array(
|
$params = array(
|
||||||
'iddn' => ($id <= 0 ? $domainname : $id)
|
'iddn' => ($id <= 0 ? $domainname : $id)
|
||||||
);
|
);
|
||||||
@@ -392,7 +399,7 @@ class Subdomains extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT `id`, `customerid`, `domain`, `documentroot`, `isemaildomain`, `parentdomainid`, `aliasdomain` FROM `" . TABLE_PANEL_DOMAINS . "`
|
SELECT `id`, `customerid`, `domain`, `documentroot`, `isemaildomain`, `parentdomainid`, `aliasdomain` FROM `" . TABLE_PANEL_DOMAINS . "`
|
||||||
WHERE `customerid`= :customerid AND " . ($id > 0 ? "`id` = :iddn" : "`databasename` = :iddn"));
|
WHERE `customerid`= :customerid AND " . ($id > 0 ? "`id` = :iddn" : "`domainname` = :iddn"));
|
||||||
$params = array(
|
$params = array(
|
||||||
'customerid' => $this->getUserDetail('customerid'),
|
'customerid' => $this->getUserDetail('customerid'),
|
||||||
'iddn' => ($id <= 0 ? $domainname : $id)
|
'iddn' => ($id <= 0 ? $domainname : $id)
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<directory>tests/Global</directory>
|
<directory>tests/Global</directory>
|
||||||
<directory>tests/Admins</directory>
|
<directory>tests/Admins</directory>
|
||||||
<directory>tests/Customers</directory>
|
<directory>tests/Customers</directory>
|
||||||
|
<directory>tests/SubDomains</directory>
|
||||||
<directory>tests/IpsAndPorts</directory>
|
<directory>tests/IpsAndPorts</directory>
|
||||||
<directory>tests/Ftps</directory>
|
<directory>tests/Ftps</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|||||||
64
tests/SubDomains/SubDomainsTest.php
Normal file
64
tests/SubDomains/SubDomainsTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ApiCommand
|
||||||
|
* @covers SubDomains
|
||||||
|
* @covers Domains
|
||||||
|
*/
|
||||||
|
class SubDomainsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCustomerSubDomainsAddNoPunycode()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'subdomain' => 'xn--asd',
|
||||||
|
'domain' => 'unknown.froxlor.org'
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage('You must not specify punycode (IDNA). The domain will automatically be converted');
|
||||||
|
SubDomains::getLocal($customer_userdata, $data)->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerSubDomainsAddMainDomainUnknown()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'subdomain' => 'wohoo',
|
||||||
|
'domain' => 'unknown.froxlor.org'
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage('The main-domain unknown.froxlor.org does not exist.');
|
||||||
|
SubDomains::getLocal($customer_userdata, $data)->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCustomerSubDomainsAddInvalidDomain()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'subdomain' => '#+?',
|
||||||
|
'domain' => 'unknown.froxlor.org'
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage("Wrong Input in Field 'Domain'");
|
||||||
|
SubDomains::getLocal($customer_userdata, $data)->add();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user