Compare commits

...

9 Commits

Author SHA1 Message Date
odain
7aaf754d5e Merge branch 'support/3.3' into develop 2026-11-27 08:28:50 +01:00
odain
05e564f172 Merge branch 'support/3.2' into support/3.3 2026-11-27 08:28:13 +01:00
Eric Espié
7c8cf670c5 Delete .idea directory
problems with phpstorm
2026-11-25 14:51:29 +01:00
odain-cbd
d28ac820f1 N°9482 - Preserve login_mode in the SESSION even when not passed by HTTP (#874)
* N°9482 - Preserve login_mode in the SESSION even when not passed by HTTP

* N°9482 - add tests
2026-11-25 14:08:02 +01:00
Benjamin DALSASS
b496476ad2 Merge remote-tracking branch 'origin/support/3.3' into develop 2026-11-25 11:06:55 +01:00
Benjamin DALSASS
c1d0fe3640 N°9728 - improve config editor
- update unitary test for removed addons
2026-11-25 10:52:49 +01:00
Benjamin DALSASS
618cd19dfc Merge remote-tracking branch 'origin/support/3.3' into develop 2026-11-25 09:57:20 +01:00
Benjamin DALSASS
9059155a1a Merge remote-tracking branch 'origin/support/3.2' into support/3.3
# Conflicts:
#	core/config.class.inc.php
2026-11-25 09:35:43 +01:00
Benjamin Dalsass
f0206cf924 N°9728 - improve config editor (#1126) 2026-11-25 09:33:27 +01:00
5 changed files with 180 additions and 21 deletions

15
.idea/IntelliLang.xml generated
View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="LanguageInjectionConfiguration">
<injection language="InjectablePHP" injector-id="xml">
<display-name>iTop - Class method code</display-name>
<place><![CDATA[xmlTag().withLocalName(string().equalTo("code"))]]></place>
<xpath-condition>name(..) = 'method' and count(/itop_design) = 1</xpath-condition>
</injection>
<injection language="InjectablePHP" injector-id="xml">
<display-name>iTop - Snippet code</display-name>
<place><![CDATA[xmlTag().withLocalName(string().equalTo("snippet"))]]></place>
<xpath-condition>name(..) = 'snippets' and count(/itop_design) = 1</xpath-condition>
</injection>
</component>
</project>

View File

@@ -35,8 +35,6 @@ class LoginDefaultBefore extends AbstractLoginFSMExtension
if ($index !== false) {
// Force login mode
Session::Set('login_mode', $sProposedLoginMode);
} else {
Session::Unset('login_mode');
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}

View File

@@ -2619,9 +2619,11 @@ class Config
* Write the configuration to a file (php format) that can be reloaded later
* By default write to the same file that was specified when constructing the object
*
* @since 3.2.3-2 3.2.4 3.3.0 N°9728
*
* @param string $sFileName string Name of the file to write to (emtpy to write to the same file)
*
* @return boolean True otherwise throws an Exception
* @return bool True otherwise throws an Exception
*
* @throws \ConfigException
*/
@@ -2735,7 +2737,7 @@ class Config
$aParserValue = null;
}
$sSeenAs = self::PrettyVarExport($aParserValue, $aSettingInfo['value'], "\t");
fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
fwrite($hFile, "\t".var_export((string) $sPropCode, true)." => $sSeenAs,\n");
}
}
fwrite($hFile, ");\n");
@@ -2744,10 +2746,10 @@ class Config
fwrite($hFile, "/**\n *\n * Modules specific settings\n *\n */\n");
fwrite($hFile, "\$MyModuleSettings = array(\n");
foreach ($this->m_aModuleSettings as $sModule => $aProperties) {
fwrite($hFile, "\t'$sModule' => array (\n");
fwrite($hFile, "\t".var_export((string) $sModule, true)." => array (\n");
foreach ($aProperties as $sProperty => $value) {
$sNiceExport = self::PrettyVarExport($this->oItopConfigParser->GetVarValue('MyModuleSettings', $sProperty), $value, "\t\t");
fwrite($hFile, "\t\t'$sProperty' => $sNiceExport,\n");
fwrite($hFile, "\t\t".var_export((string) $sProperty, true)." => $sNiceExport,\n");
}
fwrite($hFile, "\t),\n");
}

View File

@@ -0,0 +1,69 @@
<?php
use Combodo\iTop\Application\Helper\Session;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
/**
* @runClassInSeparateProcess Required because PHPUnit outputs something earlier, thus causing the headers to be sent
*/
class LoginDefaultBeforeTest extends ItopDataTestCase
{
protected function setUp(): void
{
parent::setUp();
Session::$bAllowCLI = true;
Session::Start();
$_REQUEST = [];
$this->RequireOnceItopFile('application/logindefault.class.inc.php');
}
protected function tearDown(): void
{
parent::tearDown();
Session::$bAllowCLI = false;
}
public function testOnStart_NoLoginModeRequiredNorStoredInSession()
{
$this->CallStartAndCheckLoginModeStored(null, null);
}
public function testOnStart_StoreLoginModeRequiredWhenConfigured()
{
MetaModel::GetConfig()->SetAllowedLoginTypes(["SAML"]);
$_REQUEST['login_mode'] = "SAML";
$this->CallStartAndCheckLoginModeStored("SAML", null);
}
public function testOnStart_SwitchLoginModeWhenNewOneRequiredIsConfigured()
{
MetaModel::GetConfig()->SetAllowedLoginTypes(["SAML"]);
$_REQUEST['login_mode'] = "SAML";
$this->CallStartAndCheckLoginModeStored("SAML");
}
public function testOnStart_PreserveCurrentLoginModeInSessionWhenNewOneRequiredIsNotConfigured()
{
$_REQUEST['login_mode'] = "SAML";
$this->CallStartAndCheckLoginModeStored("previous_mode");
}
public function testOnStart_PreserveCurrentLoginModeInSessionWhenNoOtherRequired()
{
$this->CallStartAndCheckLoginModeStored('previous_mode');
}
private function CallStartAndCheckLoginModeStored($expected, ?string $sPreviousLoginMode = 'previous_mode')
{
Session::Set('login_mode', $sPreviousLoginMode);
$iErrorCode = 666;
$res = $this->InvokeNonPublicMethod(LoginDefaultBefore::class, 'OnStart', new LoginDefaultBefore(), [&$iErrorCode]);
$this->assertEquals(LoginWebPage::EXIT_CODE_OK, $iErrorCode);
$this->assertEquals(LoginWebPage::LOGIN_FSM_CONTINUE, $res);
$this->assertEquals($expected, Session::Get('login_mode'));
}
}

View File

@@ -24,6 +24,10 @@ namespace Combodo\iTop\Test\UnitTest\Module\iTopConfig;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use PhpParser\ConstExprEvaluator;
use PhpParser\Node;
use PhpParser\ParserFactory;
use utils;
class ConfigTest extends ItopTestCase
{
@@ -91,4 +95,105 @@ class ConfigTest extends ItopTestCase
],
];
}
/**
* @since 3.2.3
* @dataProvider ProviderArrayKeys
*/
public function testWriteToFilePreservesModuleKeys(int|string $key): void
{
$oConfig = new Config();
$oConfig->SetModuleSetting('existing-module', 'existing.property', true);
$oConfig->SetModuleSetting($key, 'sample.property', 'value');
$this->AssertWriteToFilePreservesSettings($oConfig, [
'existing-module' => ['existing.property' => true],
$key => ['sample.property' => 'value'],
]);
}
/**
* @since 3.2.3
* @dataProvider ProviderArrayKeys
*/
public function testWriteToFilePreservesPropertyKeys(int|string $key): void
{
$oConfig = new Config();
$oConfig->SetModuleSetting('sample-module', 'existing.property', true);
$oConfig->SetModuleSetting('sample-module', $key, [$key => 'value']);
$this->AssertWriteToFilePreservesSettings($oConfig, [
'sample-module' => [
'existing.property' => true,
$key => [$key => 'value'],
],
]);
}
/**
* @since 3.2.3
* @return array<string, array{int|string}>
*/
public static function ProviderArrayKeys(): array
{
return [
'module and property separators' => ['sample-module.setting_1'],
'apostrophe' => ["O'Reilly"],
'double quote' => ['a"b'],
'backslash' => ['a\\b'],
'repeated backslashes' => ['a\\\\b'],
'trailing backslash' => ['trailing\\'],
'backslash before apostrophe' => ["a\\'b"],
'unicode' => ["caf\u{00E9}-\u{65E5}\u{672C}"],
'line breaks' => ["first\nsecond\rthird"],
'dollar sign' => ['$value'],
'empty string' => [''],
'zero' => [0],
'integer' => [7],
'negative integer' => [-7],
'numeric string' => ['7'],
'leading zero' => ['07'],
];
}
/**
* @since 3.2.3
* @param array<int|string, array<int|string, mixed>> $aModuleSettings
*/
private function AssertWriteToFilePreservesSettings(Config $oConfig, array $aModuleSettings): void
{
$oOriginalConfig = utils::GetConfig();
$oParser = (new ParserFactory())->createForNewestSupportedVersion();
$oEvaluator = new ConstExprEvaluator();
try {
for ($i = 0; $i < 2; $i++) {
$sTargetFile = tempnam(sys_get_temp_dir(), 'config-target');
$this->aFileToClean[] = $sTargetFile;
$this->assertTrue($oConfig->WriteToFile($sTargetFile));
$aNodes = $oParser->parse(file_get_contents($sTargetFile));
$this->assertCount(3, $aNodes);
$aValues = [];
foreach ($aNodes as $oNode) {
$this->assertInstanceOf(Node\Stmt\Expression::class, $oNode);
$this->assertInstanceOf(Node\Expr\Assign::class, $oNode->expr);
$this->assertInstanceOf(Node\Expr\Variable::class, $oNode->expr->var);
$aValues[$oNode->expr->var->name] = $oEvaluator->evaluateDirectly($oNode->expr->expr);
}
$this->assertSame(['MySettings', 'MyModuleSettings', 'MyModules'], array_keys($aValues));
$this->assertSame($aModuleSettings, $aValues['MyModuleSettings']);
$this->assertSame([], $aValues['MyModules']);
$oConfig = new Config($sTargetFile);
foreach ($aModuleSettings as $sModule => $aProperties) {
foreach ($aProperties as $sProperty => $value) {
$this->assertSame($value, $oConfig->GetModuleSetting($sModule, $sProperty));
}
}
}
} finally {
utils::SetConfig($oOriginalConfig);
}
}
}