diff --git a/lib/classes/api/commands/class.Mysqls.php b/lib/classes/api/commands/class.Mysqls.php index 733b977a..37091ccc 100644 --- a/lib/classes/api/commands/class.Mysqls.php +++ b/lib/classes/api/commands/class.Mysqls.php @@ -348,7 +348,10 @@ class Mysqls extends ApiCommand implements ResourceEntity Database::pexecute($stmt, $params, true, true); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] updated mysql-database '" . $result['databasename'] . "'"); - return $this->response(200, "successfull", $params); + $result = $this->apiCall('Mysqls.get', array( + 'dbname' => $result['databasename'] + )); + return $this->response(200, "successfull", $result); } /** diff --git a/tests/Mysqls/MysqlsTest.php b/tests/Mysqls/MysqlsTest.php index b4f78134..bd2a15f9 100644 --- a/tests/Mysqls/MysqlsTest.php +++ b/tests/Mysqls/MysqlsTest.php @@ -30,4 +30,121 @@ class MysqlsTest extends TestCase $this->assertEquals('testdb', $result['description']); $this->assertEquals(0, $result['dbserver']); } + + /** + * @depends testCustomerMysqlsAdd + */ + public function testAdminMysqlsGet() + { + global $admin_userdata; + + $json_result = Mysqls::getLocal($admin_userdata, array( + 'dbname' => 'test1sql1' + ))->get(); + $result = json_decode($json_result, true)['data']; + + $this->assertEquals('test1sql1', $result['databasename']); + $this->assertEquals('testdb', $result['description']); + } + + /** + * @depends testCustomerMysqlsAdd + */ + public function testResellerMysqlsGet() + { + 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 = Mysqls::getLocal($reseller_userdata, array( + 'dbname' => 'test1sql1' + ))->get(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('test1sql1', $result['databasename']); + $this->assertEquals('testdb', $result['description']); + } + + public function testCustomerMysqlsGetUnknown() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'dbname' => 'test1sql5' + ]; + $this->expectExceptionCode(404); + $this->expectExceptionMessage("MySQL database with dbname 'test1sql5' could not be found"); + Mysqls::getLocal($customer_userdata, $data)->get(); + } + + /** + * @depends testCustomerMysqlsAdd + */ + public function testAdminMysqlsUpdate() + { + global $admin_userdata; + + $json_result = Mysqls::getLocal($admin_userdata, array( + 'dbname' => 'test1sql1' + ))->get(); + $old_db = json_decode($json_result, true)['data']; + + $data = [ + 'dbname' => 'test1sql1', + 'mysql_password' => generatePassword(), + 'description' => 'testdb-upd', + 'loginname' => 'test1' + ]; + $json_result = Mysqls::getLocal($admin_userdata, $data)->update(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('testdb-upd', $result['description']); + } + + /** + * @depends testCustomerMysqlsAdd + */ + public function testCustomerMysqlsList() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $json_result = Mysqls::getLocal($customer_userdata)->listing(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals(1, $result['count']); + $this->assertEquals('test1sql1', $result['list'][0]['databasename']); + } + + /** + * @depends testCustomerMysqlsList + */ + public function testCustomerMysqlsDelete() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'dbname' => 'test1sql1' + ]; + $json_result = Mysqls::getLocal($customer_userdata, $data)->delete(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('test1sql1', $result['databasename']); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1016c4f5..3d94f45e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -54,6 +54,7 @@ Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DOMAINREDIRECTS . "`;"); Database::query("TRUNCATE TABLE `" . TABLE_PANEL_ADMINS . "`;"); Database::query("TRUNCATE TABLE `" . TABLE_PANEL_IPSANDPORTS . "`;"); Database::query("TRUNCATE TABLE `" . TABLE_API_KEYS . "`;"); +Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DATABASES . "`;"); // add superadmin Database::query("INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET