minor fixes in Domains.add; added more tests

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-01 19:41:57 +01:00
parent 02616d3080
commit 601d16b17c
2 changed files with 65 additions and 2 deletions

View File

@@ -114,7 +114,7 @@ class Domains extends ApiCommand implements ResourceEntity
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) { if ($this->isAdmin()) {
if ($this->getUserDetail('domains_used') < $this->getUserDetail('domains') || $this->getUserDetail('domains') == '-1') { if ($this->getUserDetail('domains_used') < $this->getUserDetail('domains') || $this->getUserDetail('domains') == '-1') {
// parameters // parameters
@@ -325,7 +325,10 @@ class Domains extends ApiCommand implements ResourceEntity
} }
$ipandports = array(); $ipandports = array();
if (! empty($p_ipandport) && ! is_array($p_ipandports)) { if (! empty($p_ipandports) && is_numeric($p_ipandports)) {
$p_ipandports = array($p_ipandports);
}
if (! empty($p_ipandports) && ! is_array($p_ipandports)) {
$p_ipandports = unserialize($p_ipandports); $p_ipandports = unserialize($p_ipandports);
} }

View File

@@ -37,6 +37,66 @@ class DomainsTest extends TestCase
$this->assertEquals('test.local', $result['list'][0]['domain']); $this->assertEquals('test.local', $result['list'][0]['domain']);
} }
/**
* @depends testAdminDomainsAdd
*/
public function testResellerDomainsList()
{
global $admin_userdata;
// get reseller
$json_result = Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller'
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$json_result = Domains::getLocal($reseller_userdata)->list();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(0, $result['count']);
}
public function testResellerDomainsAddWithCanEditPhpSettingsDefaultIp()
{
global $admin_userdata;
// get reseller
$json_result = Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller'
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$reseller_userdata['caneditphpsettings'] = 1;
$data = [
'domain' => 'test2.local',
'customerid' => 1
];
// the reseller is not allowed to use the default ip/port
$this->expectExceptionMessage("The ip/port combination you have chosen doesn't exist.");
Domains::getLocal($reseller_userdata, $data)->add();
}
public function testResellerDomainsAddWithCanEditPhpSettingsAllowedIp()
{
global $admin_userdata;
// first, allow reseller access to ip #3
Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller',
'ipaddress' => 3
))->update();
// get reseller
$json_result = Admins::getLocal($admin_userdata, array(
'loginname' => 'reseller'
))->get();
$reseller_userdata = json_decode($json_result, true)['data'];
$reseller_userdata['adminsession'] = 1;
$data = [
'domain' => 'test2.local',
'customerid' => 1,
'ipandport' => 3
];
$json_result = Domains::getLocal($reseller_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test2.local', $result['domain']);
}
public function testAdminDomainsAddSysHostname() public function testAdminDomainsAddSysHostname()
{ {
global $admin_userdata; global $admin_userdata;