Skip to content

Commit

Permalink
validate that a customer gets the default ftp account created even if…
Browse files Browse the repository at this point in the history
… the admin/reseller has no more resource for ftp accounts; fixes #741

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
  • Loading branch information
d00p committed Oct 29, 2019
1 parent c0e07fd commit 46982ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/Froxlor/Api/Commands/Ftps.php
Expand Up @@ -56,7 +56,9 @@ public function add()
throw new \Exception("You cannot access this resource", 405);
}

if ($this->getUserDetail('ftps_used') < $this->getUserDetail('ftps') || $this->getUserDetail('ftps') == '-1') {
$is_defaultuser = $this->getBoolParam('is_defaultuser', true, 0);

if (($this->getUserDetail('ftps_used') < $this->getUserDetail('ftps') || $this->getUserDetail('ftps') == '-1') || $this->isAdmin() && $is_defaultuser == 1) {

// required paramters
$path = $this->getParam('path');
Expand All @@ -71,7 +73,6 @@ public function add()
$ftpdomain = $this->getParam('ftp_domain', true, '');

$additional_members = $this->getParam('additional_members', true, array());
$is_defaultuser = $this->getBoolParam('is_defaultuser', true, 0);

// validation
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
Expand Down Expand Up @@ -105,7 +106,7 @@ public function add()
$sendinfomail = 0;
}

if (Settings::Get('customer.ftpatdomain') == '1' && !$is_defaultuser) {
if (Settings::Get('customer.ftpatdomain') == '1' && ! $is_defaultuser) {
if ($ftpusername == '') {
\Froxlor\UI\Response::standard_error(array(
'stringisempty',
Expand Down
50 changes: 49 additions & 1 deletion tests/Customers/CustomersTest.php
Expand Up @@ -6,6 +6,7 @@
use Froxlor\Api\Commands\Admins;
use Froxlor\Api\Commands\Customers;
use Froxlor\Api\Commands\SubDomains;
use Froxlor\Api\Commands\Ftps;

/**
*
Expand Down Expand Up @@ -61,7 +62,9 @@ public function testAdminCustomersAdd()
$this->assertEquals('secret', $result['custom_notes']);

// validate that the std-subdomain has been added
$json_result = SubDomains::getLocal($admin_userdata, array('id' => $result['standardsubdomain']))->get();
$json_result = SubDomains::getLocal($admin_userdata, array(
'id' => $result['standardsubdomain']
))->get();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test1.dev.froxlor.org', $result['domain']);
}
Expand Down Expand Up @@ -555,4 +558,49 @@ public function testAdminCustomersAddLoginnameInvalid2()
$this->expectExceptionMessage('Loginname contains too many characters. Only ' . (\Froxlor\Database\Database::getSqlUsernameLength() - strlen(Settings::Get('customer.mysqlprefix'))) . ' characters are allowed.');
Customers::getLocal($admin_userdata, $data)->add();
}

/**
*
* @depends testAdminCustomersAddAutoLoginname
*/
public function testResellerCustomersAddNoFtpValidateDefaultUserExists()
{
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;

// set available ftp resources to 0 to validate that when the customer
// is added the default ftp user for the customer is created too regardless of
// available resource of the reseller/admin
$reseller_userdata['ftps'] = 0;

// add new customer
$data = [
'new_loginname' => 'testftpx',
'email' => 'testftp@froxlor.org',
'firstname' => 'Test',
'name' => 'Ftpman',
'customernumber' => 1339,
'new_customer_password' => 'h0lYmo1y'
];
Customers::getLocal($reseller_userdata, $data)->add();

// get FTP user
$json_result = Ftps::getLocal($reseller_userdata, [
'username' => 'testftpx'
])->get();
$ftp_data = json_decode($json_result, true)['data'];
$this->assertEquals("testftpx", $ftp_data['username']);

// now get rid of the customer again
$json_result = Customers::getLocal($reseller_userdata, array(
'loginname' => 'testftpx'
))->delete();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('testftpx', $result['loginname']);
}
}

0 comments on commit 46982ad

Please sign in to comment.