mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-25 09:37:33 +01:00
test(IT): Test Config General use cases
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -62,7 +62,6 @@ final class SaveController extends SimpleControllerBase
|
||||
|
||||
|
||||
/**
|
||||
* @return ActionResponse
|
||||
* @throws SPException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
@@ -92,15 +91,10 @@ final class SaveController extends SimpleControllerBase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigDataInterface $configData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function handleGeneralConfig(ConfigDataInterface $configData): void
|
||||
{
|
||||
$siteLang = $this->request->analyzeString('sitelang');
|
||||
$siteTheme = $this->request->analyzeString('sitetheme', 'material-blue');
|
||||
$siteLang = $this->request->analyzeString('site_lang');
|
||||
$siteTheme = $this->request->analyzeString('site_theme', 'material-blue');
|
||||
$sessionTimeout = $this->request->analyzeInt('session_timeout', 300);
|
||||
$applicationUrl = $this->request->analyzeString('app_url');
|
||||
$httpsEnabled = $this->request->analyzeBool('https_enabled', false);
|
||||
@@ -123,19 +117,15 @@ final class SaveController extends SimpleControllerBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigDataInterface $configData
|
||||
* @param EventMessage $eventMessage
|
||||
*
|
||||
* @return void
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function handleEventsConfig(ConfigDataInterface $configData, EventMessage $eventMessage): void
|
||||
{
|
||||
$logEnabled = $this->request->analyzeBool('log_enabled', false);
|
||||
$syslogEnabled = $this->request->analyzeBool('syslog_enabled', false);
|
||||
$remoteSyslogEnabled = $this->request->analyzeBool('remotesyslog_enabled', false);
|
||||
$syslogServer = $this->request->analyzeString('remotesyslog_server');
|
||||
$syslogPort = $this->request->analyzeInt('remotesyslog_port', 0);
|
||||
$remoteSyslogEnabled = $this->request->analyzeBool('syslog_remote_enabled', false);
|
||||
$syslogServer = $this->request->analyzeString('syslog_remote_server');
|
||||
$syslogPort = $this->request->analyzeInt('syslog_remote_port', 0);
|
||||
|
||||
$configData->setLogEnabled($logEnabled);
|
||||
$configData->setLogEvents(
|
||||
@@ -168,10 +158,6 @@ final class SaveController extends SimpleControllerBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigDataInterface $configData
|
||||
* @param EventMessage $eventMessage
|
||||
*
|
||||
* @return void
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function handleProxyConfig(ConfigDataInterface $configData, EventMessage $eventMessage): void
|
||||
@@ -206,19 +192,13 @@ final class SaveController extends SimpleControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigDataInterface $configData
|
||||
* @param EventMessage $eventMessage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function handleAuthConfig(ConfigDataInterface $configData, EventMessage $eventMessage): void
|
||||
{
|
||||
$authBasicEnabled = $this->request->analyzeBool('authbasic_enabled', false);
|
||||
$authBasicAutologinEnabled = $this->request->analyzeBool('authbasicautologin_enabled', false);
|
||||
$authBasicAutologinEnabled = $this->request->analyzeBool('authbasic_autologin_enabled', false);
|
||||
$authBasicDomain = $this->request->analyzeString('authbasic_domain');
|
||||
$authSsoDefaultGroup = $this->request->analyzeInt('sso_defaultgroup');
|
||||
$authSsoDefaultProfile = $this->request->analyzeInt('sso_defaultprofile');
|
||||
$authSsoDefaultGroup = $this->request->analyzeInt('sso_default_group');
|
||||
$authSsoDefaultProfile = $this->request->analyzeInt('sso_default_profile');
|
||||
|
||||
if ($authBasicEnabled) {
|
||||
$configData->setAuthBasicEnabled(true);
|
||||
|
||||
@@ -65,7 +65,7 @@ trait ConfigTrait
|
||||
} catch (Exception $e) {
|
||||
processException($e);
|
||||
|
||||
return ActionResponse::error(__u('Error while saving the configuration'));
|
||||
return ActionResponse::error(__u('Error while saving the configuration'), $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SP\Core;
|
||||
|
||||
use RuntimeException;
|
||||
use SP\Domain\Common\Adapters\Serde;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\Core\Ports\AppLockHandler;
|
||||
@@ -55,7 +56,7 @@ final readonly class AppLock implements AppLockHandler
|
||||
$file = new FileHandler($this->lockFile);
|
||||
|
||||
return (int)Serde::deserializeJson($file->readToString())->userId;
|
||||
} catch (FileException) {
|
||||
} catch (FileException|RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ final class FileHandler extends SplFileObject implements FileHandlerInterface
|
||||
public const CHUNK_FACTOR = 3;
|
||||
|
||||
/**
|
||||
* FileHandler constructor.
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(private readonly string $file, string $mode = 'r')
|
||||
{
|
||||
|
||||
@@ -76,4 +76,58 @@ class ConfigGeneralTest extends IntegrationTestCase
|
||||
|
||||
IntegrationTestCase::runApp($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Test]
|
||||
public function save()
|
||||
{
|
||||
$container = $this->buildContainer(
|
||||
IntegrationTestCase::buildRequest(
|
||||
'post',
|
||||
'index.php',
|
||||
['r' => 'configGeneral/save'],
|
||||
$this->getConfigParams()
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectOutputString('{"status":"OK","description":"Configuration updated","data":null}');
|
||||
|
||||
IntegrationTestCase::runApp($container);
|
||||
}
|
||||
|
||||
private function getConfigParams(): array
|
||||
{
|
||||
return [
|
||||
'site_lang' => self::$faker->languageCode(),
|
||||
'site_theme' => self::$faker->colorName(),
|
||||
'session_timeout' => self::$faker->randomNumber(3),
|
||||
'app_url' => self::$faker->url(),
|
||||
'https_enabled' => self::$faker->boolean(),
|
||||
'debug_enabled' => self::$faker->boolean(),
|
||||
'maintenance_enabled' => self::$faker->boolean(),
|
||||
'check_updates_enabled' => self::$faker->boolean(),
|
||||
'check_notices_enabled' => self::$faker->boolean(),
|
||||
'encrypt_session_enabled' => self::$faker->boolean(),
|
||||
'log_enabled' => true,
|
||||
'syslog_enabled' => true,
|
||||
'syslog_remote_enabled' => true,
|
||||
'syslog_remote_server' => self::$faker->domainName(),
|
||||
'syslog_remote_port' => self::$faker->randomNumber(3),
|
||||
'log_events' => ['test.eventA', 'test.eventB'],
|
||||
'proxy_enabled' => true,
|
||||
'proxy_server' => self::$faker->domainName(),
|
||||
'proxy_port' => self::$faker->randomNumber(3),
|
||||
'proxy_user' => self::$faker->userName(),
|
||||
'proxy_pass' => self::$faker->password(),
|
||||
'authbasic_enabled' => true,
|
||||
'authbasic_autologin_enabled' => true,
|
||||
'authbasic_domain' => self::$faker->domainName(),
|
||||
'sso_default_group' => self::$faker->randomNumber(3),
|
||||
'sso_default_profile' => self::$faker->randomNumber(3),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user