From 91593ecba6f1efafebc94558d37c009173c2b707 Mon Sep 17 00:00:00 2001 From: odain Date: Tue, 7 Apr 2026 15:56:40 +0200 Subject: [PATCH 1/2] =?UTF-8?q?N=C2=B09482=20-=20Preserve=20login=5Fmode?= =?UTF-8?q?=20in=20the=20SESSION=20even=20when=20not=20passed=20by=20HTTP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/logindefault.class.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/logindefault.class.inc.php b/application/logindefault.class.inc.php index 24b0ec24ef..85f8e46090 100644 --- a/application/logindefault.class.inc.php +++ b/application/logindefault.class.inc.php @@ -35,7 +35,7 @@ protected function OnStart(&$iErrorCode) if ($index !== false) { // Force login mode Session::Set('login_mode', $sProposedLoginMode); - } else { + } elseif (!Session::IsSet('login_mode')) { Session::Unset('login_mode'); } return LoginWebPage::LOGIN_FSM_CONTINUE; From d0b5ecc75d3df8aec842a0650b5ce52341eb1118 Mon Sep 17 00:00:00 2001 From: odain Date: Tue, 7 Apr 2026 16:28:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?N=C2=B09482=20-=20add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/logindefault.class.inc.php | 2 - .../application/LoginDefaultBeforeTest.php | 69 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/application/LoginDefaultBeforeTest.php diff --git a/application/logindefault.class.inc.php b/application/logindefault.class.inc.php index 85f8e46090..508a2623e0 100644 --- a/application/logindefault.class.inc.php +++ b/application/logindefault.class.inc.php @@ -35,8 +35,6 @@ protected function OnStart(&$iErrorCode) if ($index !== false) { // Force login mode Session::Set('login_mode', $sProposedLoginMode); - } elseif (!Session::IsSet('login_mode')) { - Session::Unset('login_mode'); } return LoginWebPage::LOGIN_FSM_CONTINUE; } diff --git a/tests/php-unit-tests/unitary-tests/application/LoginDefaultBeforeTest.php b/tests/php-unit-tests/unitary-tests/application/LoginDefaultBeforeTest.php new file mode 100644 index 0000000000..96c05d46e5 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/application/LoginDefaultBeforeTest.php @@ -0,0 +1,69 @@ +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')); + } +}