mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
Merge remote-tracking branch 'origin/support/3.0' into develop
This commit is contained in:
@@ -1936,7 +1936,7 @@ class UserRights
|
||||
// The bug has been fixed in PHP 7.2, but in case session_regenerate_id()
|
||||
// fails we just silently ignore the error and keep the same session id...
|
||||
$old_error_handler = set_error_handler(array(__CLASS__, 'VoidErrorHandler'));
|
||||
session_regenerate_id(true);
|
||||
Session::RegenerateId(true);
|
||||
if ($old_error_handler !== null) {
|
||||
set_error_handler($old_error_handler);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
namespace Combodo\iTop\Application\Helper;
|
||||
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Session management
|
||||
* Allow early session close to have multiple ajax calls in parallel
|
||||
@@ -22,17 +24,24 @@ class Session
|
||||
protected static $bIsInitialized = false;
|
||||
/** @var bool */
|
||||
protected static $bSessionStarted = false;
|
||||
/** @var bool */
|
||||
public static $bAllowCLI = false;
|
||||
|
||||
public static function Start()
|
||||
{
|
||||
if (self::IsModeCLI()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::$bIsInitialized) {
|
||||
session_name('itop-'.md5(APPROOT));
|
||||
}
|
||||
|
||||
self::$bIsInitialized = true;
|
||||
if (!self::$bSessionStarted) {
|
||||
if (!is_null(self::$iSessionId)) {
|
||||
if (session_id(self::$iSessionId) === false) {
|
||||
session_regenerate_id();
|
||||
session_regenerate_id(true);
|
||||
}
|
||||
}
|
||||
self::$bSessionStarted = session_start();
|
||||
@@ -40,8 +49,26 @@ class Session
|
||||
}
|
||||
}
|
||||
|
||||
public static function RegenerateId($bDeleteOldSession = false)
|
||||
{
|
||||
if (self::IsModeCLI()) {
|
||||
return;
|
||||
}
|
||||
|
||||
session_regenerate_id($bDeleteOldSession);
|
||||
if (self::$bSessionStarted) {
|
||||
self::WriteClose();
|
||||
}
|
||||
self::$bSessionStarted = session_start();
|
||||
self::$iSessionId = session_id();
|
||||
}
|
||||
|
||||
public static function WriteClose()
|
||||
{
|
||||
if (self::IsModeCLI()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::$bSessionStarted) {
|
||||
session_write_close();
|
||||
self::$bSessionStarted = false;
|
||||
@@ -177,4 +204,14 @@ class Session
|
||||
{
|
||||
return print_r($_SESSION, true);
|
||||
}
|
||||
|
||||
private static function IsModeCLI(): bool
|
||||
{
|
||||
if (self::$bAllowCLI) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return utils::IsModeCLI();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,18 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
*/
|
||||
class SessionTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Session::$bAllowCLI = true;
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
Session::$bAllowCLI = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Combodo\iTop\Application\Helper\Session::Start
|
||||
*/
|
||||
@@ -121,4 +133,12 @@ class SessionTest extends ItopTestCase
|
||||
$this->assertFalse(Session::IsSet(['test1', 'test2', 'test3']));
|
||||
}
|
||||
|
||||
public function testRegenerateId()
|
||||
{
|
||||
Session::Start();
|
||||
$iPrevSessionId = Session::$iSessionId;
|
||||
Session::RegenerateId();
|
||||
//$this->assertFalse(Session::IsSet('test'));
|
||||
$this->assertNotEquals($iPrevSessionId, Session::$iSessionId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user