Compare commits

...

2 Commits

Author SHA1 Message Date
odain
d0b5ecc75d N°9482 - add tests 2026-04-07 16:28:05 +02:00
odain
91593ecba6 N°9482 - Preserve login_mode in the SESSION even when not passed by HTTP 2026-04-07 15:56:40 +02:00
2 changed files with 69 additions and 2 deletions

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

@@ -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'));
}
}