From 46982ad2dcdfe6f8f3acd9b7b4c0ebc21f01cc84 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Tue, 29 Oct 2019 07:52:00 +0100 Subject: [PATCH] validate that a customer gets the default ftp account created even if the admin/reseller has no more resource for ftp accounts; fixes #741 Signed-off-by: Michael Kaufmann --- lib/Froxlor/Api/Commands/Ftps.php | 7 +++-- tests/Customers/CustomersTest.php | 50 ++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/lib/Froxlor/Api/Commands/Ftps.php b/lib/Froxlor/Api/Commands/Ftps.php index 68f1acad1..876c0f939 100644 --- a/lib/Froxlor/Api/Commands/Ftps.php +++ b/lib/Froxlor/Api/Commands/Ftps.php @@ -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'); @@ -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); @@ -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', diff --git a/tests/Customers/CustomersTest.php b/tests/Customers/CustomersTest.php index 4f30d31a3..a321b0095 100644 --- a/tests/Customers/CustomersTest.php +++ b/tests/Customers/CustomersTest.php @@ -6,6 +6,7 @@ use Froxlor\Api\Commands\Admins; use Froxlor\Api\Commands\Customers; use Froxlor\Api\Commands\SubDomains; +use Froxlor\Api\Commands\Ftps; /** * @@ -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']); } @@ -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']); + } }