Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions application/logindefault.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ protected function OnStart(&$iErrorCode)
if ($index !== false) {
// Force login mode
Session::Set('login_mode', $sProposedLoginMode);
} else {
Session::Unset('login_mode');
}
return LoginWebPage::LOGIN_FSM_CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'));
}
}
Loading