unit-test FpmDaemons-ApiCommand
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -72,7 +72,8 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
/**
|
/**
|
||||||
* return a fpm-daemon entry by id
|
* return a fpm-daemon entry by id
|
||||||
*
|
*
|
||||||
* @param int $id fpm-daemon-id
|
* @param int $id
|
||||||
|
* fpm-daemon-id
|
||||||
*
|
*
|
||||||
* @access admin
|
* @access admin
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -121,7 +122,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
$max_spare_servers = $this->getParam('max_spare_servers', true, 0);
|
$max_spare_servers = $this->getParam('max_spare_servers', true, 0);
|
||||||
$max_requests = $this->getParam('max_requests', true, 0);
|
$max_requests = $this->getParam('max_requests', true, 0);
|
||||||
$idle_timeout = $this->getParam('idle_timeout', true, 0);
|
$idle_timeout = $this->getParam('idle_timeout', true, 0);
|
||||||
$limit_extensions = $this->getParam('limit_extensions', true, '');
|
$limit_extensions = $this->getParam('limit_extensions', true, '.php');
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
$description = validate($description, 'description', '', '', array(), true);
|
$description = validate($description, 'description', '', '', array(), true);
|
||||||
@@ -134,6 +135,9 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
))) {
|
))) {
|
||||||
throw new ErrorException("Unknown process manager", 406);
|
throw new ErrorException("Unknown process manager", 406);
|
||||||
}
|
}
|
||||||
|
if (empty($limit_extensions)) {
|
||||||
|
$limit_extensions = '.php';
|
||||||
|
}
|
||||||
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
|
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
|
||||||
|
|
||||||
if (strlen($description) == 0 || strlen($description) > 50) {
|
if (strlen($description) == 0 || strlen($description) > 50) {
|
||||||
@@ -168,11 +172,14 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
'limit_extensions' => $limit_extensions
|
'limit_extensions' => $limit_extensions
|
||||||
);
|
);
|
||||||
Database::pexecute($ins_stmt, $ins_data);
|
Database::pexecute($ins_stmt, $ins_data);
|
||||||
$ins_data['id'] = Database::lastInsertId();
|
$id = Database::lastInsertId();
|
||||||
|
|
||||||
inserttask('1');
|
inserttask('1');
|
||||||
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon with description '" . $description . "' has been created by '" . $this->getUserDetail('loginname') . "'");
|
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon with description '" . $description . "' has been created by '" . $this->getUserDetail('loginname') . "'");
|
||||||
return $this->response(200, "successfull", $ins_data);
|
$result = $this->apiCall('FpmDaemons.get', array(
|
||||||
|
'id' => $id
|
||||||
|
));
|
||||||
|
return $this->response(200, "successfull", $result);
|
||||||
}
|
}
|
||||||
throw new Exception("Not allowed to execute given command.", 403);
|
throw new Exception("Not allowed to execute given command.", 403);
|
||||||
}
|
}
|
||||||
@@ -193,7 +200,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
// required parameter
|
// required parameter
|
||||||
$id = $this->getParam('id');
|
$id = $this->getParam('id');
|
||||||
|
|
||||||
$result = $this->apiCall('PhpSettings.get', array(
|
$result = $this->apiCall('FpmDaemons.get', array(
|
||||||
'id' => $id
|
'id' => $id
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -221,6 +228,9 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
))) {
|
))) {
|
||||||
throw new ErrorException("Unknown process manager", 406);
|
throw new ErrorException("Unknown process manager", 406);
|
||||||
}
|
}
|
||||||
|
if (empty($limit_extensions)) {
|
||||||
|
$limit_extensions = '.php';
|
||||||
|
}
|
||||||
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
|
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
|
||||||
|
|
||||||
if (strlen($description) == 0 || strlen($description) > 50) {
|
if (strlen($description) == 0 || strlen($description) > 50) {
|
||||||
@@ -268,7 +278,8 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
/**
|
/**
|
||||||
* delete a fpm-daemon entry by id
|
* delete a fpm-daemon entry by id
|
||||||
*
|
*
|
||||||
* @param int $id fpm-daemon-id
|
* @param int $id
|
||||||
|
* fpm-daemon-id
|
||||||
*
|
*
|
||||||
* @access admin
|
* @access admin
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
92
tests/PhpAndFpm/FpmDaemonsTest.php
Normal file
92
tests/PhpAndFpm/FpmDaemonsTest.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @covers ApiCommand
|
||||||
|
* @covers ApiParameter
|
||||||
|
* @covers FpmDaemons
|
||||||
|
*/
|
||||||
|
class FpmDaemonsTest extends TestCase
|
||||||
|
{
|
||||||
|
private static $id = 0;
|
||||||
|
|
||||||
|
public function testAdminFpmDaemonsAdd()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$data = [
|
||||||
|
'description' => 'test2 fpm',
|
||||||
|
'reload_cmd' => 'service php7.1-fpm reload',
|
||||||
|
'config_dir' => '/etc/php/7.1/fpm/pool.d'
|
||||||
|
];
|
||||||
|
$json_result = FpmDaemons::getLocal($admin_userdata, $data)->add();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals('/etc/php/7.1/fpm/pool.d/', $result['config_dir']);
|
||||||
|
$this->assertEquals(0, $result['max_children']);
|
||||||
|
$this->assertEquals('.php', $result['limit_extensions']);
|
||||||
|
self::$id = $result['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminFpmDaemonsAdd
|
||||||
|
*/
|
||||||
|
public function testAdminFpmDaemonsUpdate()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$data = [
|
||||||
|
'id' => self::$id,
|
||||||
|
'description' => 'test2 fpm edit',
|
||||||
|
'pm' => 'dynamic',
|
||||||
|
'max_children' => '10',
|
||||||
|
'start_servers' => '4',
|
||||||
|
'limit_extensions' => '.php .php.xml',
|
||||||
|
];
|
||||||
|
$json_result = FpmDaemons::getLocal($admin_userdata, $data)->update();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals('/etc/php/7.1/fpm/pool.d/', $result['config_dir']);
|
||||||
|
$this->assertEquals(10, $result['max_children']);
|
||||||
|
$this->assertEquals('.php .php.xml', $result['limit_extensions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminFpmDaemonsUpdate
|
||||||
|
*/
|
||||||
|
public function testAdminFpmDaemonsList()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$json_result = FpmDaemons::getLocal($admin_userdata)->listing();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals(2, $result['count']);
|
||||||
|
$this->assertEquals('test fpm', $result['list'][0]['description']);
|
||||||
|
$this->assertEquals('test2 fpm edit', $result['list'][1]['description']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminFpmDaemonsList
|
||||||
|
*/
|
||||||
|
public function testAdminFpmDaemonsDelete()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$data = [
|
||||||
|
'id' => self::$id
|
||||||
|
];
|
||||||
|
$json_result = FpmDaemons::getLocal($admin_userdata, $data)->delete();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals('/etc/php/7.1/fpm/pool.d/', $result['config_dir']);
|
||||||
|
$this->assertEquals(10, $result['max_children']);
|
||||||
|
$this->assertEquals('.php .php.xml', $result['limit_extensions']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminFpmDaemonsDelete
|
||||||
|
*/
|
||||||
|
public function testAdminFpmDaemonsDeleteDefaultConfig()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
$data = [
|
||||||
|
'id' => 1
|
||||||
|
];
|
||||||
|
$this->expectExceptionMessage("This PHP-configuration is set as default and cannot be deleted.");
|
||||||
|
FpmDaemons::getLocal($admin_userdata, $data)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,7 @@ Database::query("TRUNCATE TABLE `" . TABLE_PANEL_ADMINS . "`;");
|
|||||||
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_IPSANDPORTS . "`;");
|
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_IPSANDPORTS . "`;");
|
||||||
Database::query("TRUNCATE TABLE `" . TABLE_API_KEYS . "`;");
|
Database::query("TRUNCATE TABLE `" . TABLE_API_KEYS . "`;");
|
||||||
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DATABASES . "`;");
|
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DATABASES . "`;");
|
||||||
|
Database::query("ALTER TABLE `" . TABLE_PANEL_FPMDAEMONS . "` AUTO_INCREMENT=2;");
|
||||||
|
|
||||||
// add superadmin
|
// add superadmin
|
||||||
Database::query("INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET
|
Database::query("INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET
|
||||||
|
|||||||
Reference in New Issue
Block a user