Apply suggestion from code review

This commit is contained in:
Stephen Abello
2026-04-08 09:28:53 +02:00
parent 050e269921
commit 94a8ef53dd
2 changed files with 7 additions and 16 deletions

View File

@@ -1975,11 +1975,6 @@ class Config
*/
protected $m_sAllowedLoginTypes;
/**
* @var string Name of the PHP variable in which external authentication information is passed by the web server
*/
protected $m_sExtAuthVariable;
/**
* @var string Encryption key used for all attributes of type "encrypted string". Can be set to a random value
* unless you want to import a database from another iTop instance, in which case you must use
@@ -2052,7 +2047,6 @@ class Config
$this->m_bSecureConnectionRequired = DEFAULT_SECURE_CONNECTION_REQUIRED;
$this->m_sDefaultLanguage = 'EN US';
$this->m_sAllowedLoginTypes = DEFAULT_ALLOWED_LOGIN_TYPES;
$this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
$this->m_aCharsets = [];
$this->m_bQueryCacheEnabled = DEFAULT_QUERY_CACHE_ENABLED;
$this->m_iPasswordHashAlgo = DEFAULT_HASH_ALGO;
@@ -2206,7 +2200,6 @@ class Config
$this->m_sDefaultLanguage = isset($MySettings['default_language']) ? trim($MySettings['default_language']) : 'EN US';
$this->m_sAllowedLoginTypes = isset($MySettings['allowed_login_types']) ? trim($MySettings['allowed_login_types']) : DEFAULT_ALLOWED_LOGIN_TYPES;
$this->m_sExtAuthVariable = isset($MySettings['ext_auth_variable']) ? trim($MySettings['ext_auth_variable']) : DEFAULT_EXT_AUTH_VARIABLE;
$this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : $this->m_sEncryptionKey;
$this->m_sEncryptionLibrary = isset($MySettings['encryption_library']) ? trim($MySettings['encryption_library']) : $this->m_sEncryptionLibrary;
$this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : [];
@@ -2521,7 +2514,7 @@ class Config
public function SetExternalAuthenticationVariable($sExtAuthVariable)
{
$this->m_sExtAuthVariable = $sExtAuthVariable;
$this->Set('ext_auth_variable', $sExtAuthVariable);
}
public function SetEncryptionKey($sKey)
@@ -2576,7 +2569,6 @@ class Config
$aSettings['secure_connection_required'] = $this->m_bSecureConnectionRequired;
$aSettings['default_language'] = $this->m_sDefaultLanguage;
$aSettings['allowed_login_types'] = $this->m_sAllowedLoginTypes;
$aSettings['ext_auth_variable'] = $this->m_sExtAuthVariable;
$aSettings['encryption_key'] = $this->m_sEncryptionKey;
$aSettings['encryption_library'] = $this->m_sEncryptionLibrary;
$aSettings['csv_import_charsets'] = $this->m_aCharsets;
@@ -2681,7 +2673,6 @@ class Config
$aOtherValues = [
'default_language' => $this->m_sDefaultLanguage,
'allowed_login_types' => $this->m_sAllowedLoginTypes,
'ext_auth_variable' => $this->m_sExtAuthVariable,
'encryption_key' => $this->m_sEncryptionKey,
'encryption_library' => $this->m_sEncryptionLibrary,
'csv_import_charsets' => $this->m_aCharsets,

View File

@@ -39,7 +39,7 @@ class LoginExternalTest extends ItopDataTestCase
protected function tearDown(): void
{
$this->oConfig->Set('ext_auth_variable', $this->sOriginalExtAuthVariable, 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable($this->sOriginalExtAuthVariable);
parent::tearDown();
}
@@ -54,7 +54,7 @@ class LoginExternalTest extends ItopDataTestCase
public function testGetAuthUserFromServerVariable()
{
$_SERVER['REMOTE_USER'] = 'alice';
$this->oConfig->Set('ext_auth_variable', '$_SERVER[\'REMOTE_USER\']', 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable('$_SERVER[\'REMOTE_USER\']');
$this->assertSame('alice', $this->CallGetAuthUser());
}
@@ -62,7 +62,7 @@ class LoginExternalTest extends ItopDataTestCase
public function testGetAuthUserFromCookie()
{
$_COOKIE['auth_user'] = 'bob';
$this->oConfig->Set('ext_auth_variable', '$_COOKIE[\'auth_user\']', 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable('$_COOKIE[\'auth_user\']');
$this->assertSame('bob', $this->CallGetAuthUser());
}
@@ -70,14 +70,14 @@ class LoginExternalTest extends ItopDataTestCase
public function testGetAuthUserFromRequest()
{
$_REQUEST['auth_user'] = 'carol';
$this->oConfig->Set('ext_auth_variable', '$_REQUEST[\'auth_user\']', 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable('$_REQUEST[\'auth_user\']');
$this->assertSame('carol', $this->CallGetAuthUser());
}
public function testInvalidExpressionReturnsFalse()
{
$this->oConfig->Set('ext_auth_variable', '$_SERVER[\'HTTP_X_CMD\']) ? print(\'x\') : false; //', 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable('$_SERVER[\'HTTP_X_CMD\']) ? print(\'x\') : false; //');
$this->assertFalse($this->CallGetAuthUser());
}
@@ -88,7 +88,7 @@ class LoginExternalTest extends ItopDataTestCase
$this->markTestSkipped('getallheaders() not available');
}
$_SERVER['HTTP_X_REMOTE_USER'] = 'CN=header-test';
$this->oConfig->Set('ext_auth_variable', 'getallheaders()[\'X-Remote-User\']', 'unit_test');
$this->oConfig->SetExternalAuthenticationVariable('getallheaders()[\'X-Remote-User\']');
$this->assertSame('CN=header-test', $this->CallGetAuthUser());
}