mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Merge remote-tracking branch 'origin/support/3.0' into support/3.1
# Conflicts: # tests/php-unit-tests/ItopDataTestCase.php
This commit is contained in:
@@ -487,6 +487,35 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
return $oUser;
|
return $oUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sLogin
|
||||||
|
* @param int $iProfileId
|
||||||
|
*
|
||||||
|
* @return \UserLocal
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected function CreateContactlessUser($sLogin, $iProfileId, $sPassword = null)
|
||||||
|
{
|
||||||
|
if (empty($sPassword)) {
|
||||||
|
$sPassword = $sLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oUserProfile = new URP_UserProfile();
|
||||||
|
$oUserProfile->Set('profileid', $iProfileId);
|
||||||
|
$oUserProfile->Set('reason', 'UNIT Tests');
|
||||||
|
$oSet = DBObjectSet::FromObject($oUserProfile);
|
||||||
|
/** @var \UserLocal $oUser */
|
||||||
|
$oUser = $this->createObject('UserLocal', array(
|
||||||
|
'login' => $sLogin,
|
||||||
|
'password' => $sPassword,
|
||||||
|
'language' => 'EN US',
|
||||||
|
'profile_list' => $oSet,
|
||||||
|
));
|
||||||
|
$this->debug("Created {$oUser->GetName()} ({$oUser->GetKey()})");
|
||||||
|
|
||||||
|
return $oUser;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \DBObject $oUser
|
* @param \DBObject $oUser
|
||||||
* @param int $iProfileId
|
* @param int $iProfileId
|
||||||
|
|||||||
@@ -11,11 +11,16 @@ namespace Combodo\iTop\Test\UnitTest\Module\AuthentLocal;
|
|||||||
use AttributeDate;
|
use AttributeDate;
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
use Config;
|
use Config;
|
||||||
|
use DBObjectSearch;
|
||||||
|
use DBObjectSet;
|
||||||
use Dict;
|
use Dict;
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
use ormLinkSet;
|
use ormLinkSet;
|
||||||
use URP_UserProfile;
|
use URP_UserProfile;
|
||||||
|
use User;
|
||||||
use UserLocal;
|
use UserLocal;
|
||||||
|
use UserRights;
|
||||||
|
use utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test class for UserLocal class
|
* test class for UserLocal class
|
||||||
@@ -392,5 +397,62 @@ class UserLocalTest extends ItopDataTestCase
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetUserProfileList()
|
||||||
|
{
|
||||||
|
utils::GetConfig()->SetModuleSetting('authent-local', 'password_validation.pattern', '');
|
||||||
|
$sAdminLogin = 'admin';
|
||||||
|
$oExistingAdminUser = MetaModel::GetObjectByColumn(User::class, 'login', $sAdminLogin, false);
|
||||||
|
if (\is_null($oExistingAdminUser)) {
|
||||||
|
$sAdministratorProfileId = 1;
|
||||||
|
$this->CreateContactlessUser($sAdminLogin, $sAdministratorProfileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// By default should see all profiles
|
||||||
|
$oProfilesSet = $this->GetAdminUserProfileList();
|
||||||
|
$this->assertIsObject($oProfilesSet);
|
||||||
|
$this->assertInstanceOf(ormLinkSet::class, $oProfilesSet);
|
||||||
|
$this->assertGreaterThan(0, $oProfilesSet->Count());
|
||||||
|
|
||||||
|
// non admin user : seeing profiles depends on the security.hide_administrators config param value
|
||||||
|
$sSupportAgentProfileId = 5;
|
||||||
|
$sSupportAgentLogin = 'support_agent';
|
||||||
|
$this->CreateContactlessUser($sSupportAgentLogin, $sSupportAgentProfileId);
|
||||||
|
UserRights::Login($sSupportAgentLogin);
|
||||||
|
MetaModel::GetConfig()->Set('security.hide_administrators', true);
|
||||||
|
$oProfilesSet = $this->GetAdminUserProfileList();
|
||||||
|
$this->assertIsObject($oProfilesSet);
|
||||||
|
$this->assertInstanceOf(ormLinkSet::class, $oProfilesSet);
|
||||||
|
$this->assertEquals(0, $oProfilesSet->Count());
|
||||||
|
MetaModel::GetConfig()->Set('security.hide_administrators', false);
|
||||||
|
$oProfilesSet = $this->GetAdminUserProfileList();
|
||||||
|
$this->assertIsObject($oProfilesSet);
|
||||||
|
$this->assertInstanceOf(ormLinkSet::class, $oProfilesSet);
|
||||||
|
$this->assertGreaterThan(0, $oProfilesSet->Count());
|
||||||
|
|
||||||
|
// admin user : will always see profiles whatever the security.hide_administrators config param value is
|
||||||
|
UserRights::Login($sAdminLogin);
|
||||||
|
MetaModel::GetConfig()->Set('security.hide_administrators', true);
|
||||||
|
$oProfilesSet = $this->GetAdminUserProfileList();
|
||||||
|
$this->assertIsObject($oProfilesSet);
|
||||||
|
$this->assertInstanceOf(ormLinkSet::class, $oProfilesSet);
|
||||||
|
$this->assertGreaterThan(0, $oProfilesSet->Count());
|
||||||
|
MetaModel::GetConfig()->Set('security.hide_administrators', false);
|
||||||
|
$oProfilesSet = $this->GetAdminUserProfileList();
|
||||||
|
$this->assertIsObject($oProfilesSet);
|
||||||
|
$this->assertInstanceOf(ormLinkSet::class, $oProfilesSet);
|
||||||
|
$this->assertGreaterThan(0, $oProfilesSet->Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetAdminUserProfileList(): ormLinkSet
|
||||||
|
{
|
||||||
|
$oSearch = new DBObjectSearch(UserLocal::class);
|
||||||
|
$oSearch->AllowAllData();
|
||||||
|
$oSearch->AddCondition('login', 'admin', '=');
|
||||||
|
$oObjectSet = new DBObjectSet($oSearch);
|
||||||
|
/** @noinspection OneTimeUseVariablesInspection */
|
||||||
|
$oUser = $oObjectSet->Fetch();
|
||||||
|
return $oUser->Get('profile_list');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user