mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Merge branch 'support/3.0' into develop
This commit is contained in:
@@ -8,7 +8,13 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\AuthentLocal;
|
||||
|
||||
|
||||
use AttributeDate;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Config;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use ormLinkSet;
|
||||
use URP_UserProfile;
|
||||
use UserLocal;
|
||||
|
||||
/**
|
||||
@@ -34,23 +40,23 @@ class UserLocalTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testValidatePassword($sPassword, $aValidatorNames, $aConfigValueMap, $bExpectedCheckStatus, $expectedCheckIssues = null, $sUserLanguage = null)
|
||||
{
|
||||
$configMock = $this->createMock(\Config::class);
|
||||
$configMock = $this->createMock(Config::class);
|
||||
$configMock
|
||||
->method('GetModuleSetting')
|
||||
->willReturnMap($aConfigValueMap);
|
||||
restore_error_handler();
|
||||
|
||||
if (isset($sUserLanguage)) {
|
||||
\Dict::SetUserLanguage($sUserLanguage);
|
||||
Dict::SetUserLanguage($sUserLanguage);
|
||||
}
|
||||
|
||||
/** @var UserLocal $oUserLocal */
|
||||
$oUserLocal = \MetaModel::NewObject('UserLocal', array('login' => 'john'));
|
||||
/** @var \ormLinkSet $oProfileSet */
|
||||
$oUserLocal = MetaModel::NewObject(UserLocal::class, array('login' => 'john'));
|
||||
/** @var ormLinkSet $oProfileSet */
|
||||
$oProfileSet = $oUserLocal->Get('profile_list');
|
||||
|
||||
$oProfileSet->AddItem(
|
||||
\MetaModel::NewObject('URP_UserProfile', array('profileid' => 1))
|
||||
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
|
||||
);
|
||||
|
||||
$aValidatorCollection = array();
|
||||
@@ -242,9 +248,10 @@ class UserLocalTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testPasswordRenewal($sBefore, $sExpectedAfter)
|
||||
{
|
||||
$oBefore = is_null($sBefore) ? null : date(\AttributeDate::GetInternalFormat(), strtotime($sBefore));
|
||||
$oNow = date(\AttributeDate::GetInternalFormat());
|
||||
$oExpectedAfter = is_null($sExpectedAfter) ? null : date(\AttributeDate::GetInternalFormat(), strtotime($sExpectedAfter));
|
||||
$sDateFormat = AttributeDate::GetInternalFormat();
|
||||
$oBefore = is_null($sBefore) ? null : date($sDateFormat, strtotime($sBefore));
|
||||
$oNow = date($sDateFormat);
|
||||
$oExpectedAfter = is_null($sExpectedAfter) ? null : date($sDateFormat, strtotime($sExpectedAfter));
|
||||
|
||||
$aUserLocalValues = array('login' => 'john');
|
||||
if (!is_null($oBefore))
|
||||
@@ -253,15 +260,14 @@ class UserLocalTest extends ItopDataTestCase
|
||||
}
|
||||
|
||||
/** @var UserLocal $oUserLocal */
|
||||
$oUserLocal = \MetaModel::NewObject('UserLocal', $aUserLocalValues);
|
||||
/** @var \ormLinkSet $oProfileSet */
|
||||
$oUserLocal = MetaModel::NewObject(UserLocal::class, $aUserLocalValues);
|
||||
/** @var ormLinkSet $oProfileSet */
|
||||
$oProfileSet = $oUserLocal->Get('profile_list');
|
||||
|
||||
$oProfileSet->AddItem(
|
||||
\MetaModel::NewObject('URP_UserProfile', array('profileid' => 1))
|
||||
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'));
|
||||
|
||||
//INSERT
|
||||
@@ -270,17 +276,19 @@ class UserLocalTest extends ItopDataTestCase
|
||||
$this->assertEquals($oNow, $oUserLocal->Get('password_renewed_date'), 'INSERT sets the "password_renewed_date" to the current date');
|
||||
|
||||
//UPDATE password_renewed_date
|
||||
$oUserLocal = MetaModel::GetObject(UserLocal::class, $oUserLocal->GetKey());
|
||||
$oUserLocal->Set('password_renewed_date', $oBefore);
|
||||
$oUserLocal->DBWrite();
|
||||
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'), 'UPDATE can target and change the "password_renewed_date"');
|
||||
|
||||
//UPDATE password
|
||||
$oUserLocal = MetaModel::GetObject(UserLocal::class, $oUserLocal->GetKey());
|
||||
$oUserLocal->Set('password', 'fooBar1???1');
|
||||
$oUserLocal->DBWrite();
|
||||
$this->assertEquals($oExpectedAfter, $oUserLocal->Get('password_renewed_date'), 'UPDATE "password" fields trigger automatic change of the "password_renewed_date" field');
|
||||
|
||||
|
||||
//UPDATE both password & password_renewed_date
|
||||
$oUserLocal = MetaModel::GetObject(UserLocal::class, $oUserLocal->GetKey());
|
||||
$oUserLocal->Set('password', 'fooBar1???2');
|
||||
$oUserLocal->Set('password_renewed_date', $oBefore);
|
||||
$oUserLocal->DBWrite();
|
||||
@@ -304,5 +312,85 @@ class UserLocalTest extends ItopDataTestCase
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CanExpireFixProvider
|
||||
*
|
||||
*/
|
||||
public function testCanExpireFix($sExpirationMode, $sBefore, bool $bRenewedDateTouched)
|
||||
{
|
||||
$oBefore = is_null($sBefore) ? null : date(AttributeDate::GetInternalFormat(), strtotime($sBefore));
|
||||
$oNow = date(AttributeDate::GetInternalFormat());
|
||||
$oExpectedAfter = $bRenewedDateTouched ? $oNow : $oBefore;
|
||||
|
||||
$aUserLocalValues = array('login' => 'john');
|
||||
if (!is_null($oBefore))
|
||||
{
|
||||
$aUserLocalValues['password_renewed_date'] = $oBefore;
|
||||
}
|
||||
|
||||
/** @var UserLocal $oUserLocal */
|
||||
$oUserLocal = MetaModel::NewObject(UserLocal::class, $aUserLocalValues);
|
||||
/** @var ormLinkSet $oProfileSet */
|
||||
$oProfileSet = $oUserLocal->Get('profile_list');
|
||||
|
||||
$oProfileSet->AddItem(
|
||||
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
|
||||
);
|
||||
|
||||
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'));
|
||||
|
||||
//INSERT
|
||||
$oUserLocal->Set('password', 'fooBar1???');
|
||||
$oUserLocal->DBWrite();
|
||||
$this->assertEquals($oNow, $oUserLocal->Get('password_renewed_date'), 'INSERT sets the "password_renewed_date" to the current date');
|
||||
|
||||
$oUserLocal = MetaModel::GetObject(UserLocal::class, $oUserLocal->GetKey());
|
||||
$oUserLocal->Set('password_renewed_date', $oBefore);
|
||||
$oUserLocal->DBWrite();
|
||||
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'), 'UPDATE can target and change the "password_renewed_date"');
|
||||
|
||||
//UPDATE password
|
||||
$oUserLocal = MetaModel::GetObject(UserLocal::class, $oUserLocal->GetKey());
|
||||
$oUserLocal->Set('expiration', $sExpirationMode);
|
||||
$oUserLocal->DBWrite();
|
||||
$this->assertEquals($oExpectedAfter, $oUserLocal->Get('password_renewed_date'), 'UPDATE "password" fields trigger automatic change of the "password_renewed_date" field');
|
||||
}
|
||||
|
||||
public function CanExpireFixProvider()
|
||||
{
|
||||
return array(
|
||||
'EXPIRE_CAN: nominal case' => array(
|
||||
'sExpirationMode' => 'can_expire',
|
||||
'oExpectedBefore' => null,
|
||||
'bRenewedDateTouched' => true,
|
||||
),
|
||||
'EXPIRE_NEVER (default mode): nothing changed on UserLocal' => array(
|
||||
'sExpirationMode' => 'never_expire',
|
||||
'oExpectedBefore' => null,
|
||||
'bRenewedDateTouched' => false,
|
||||
),
|
||||
'EXPIRE_FORCE: nominal case' => array(
|
||||
'sExpirationMode' => 'force_expire',
|
||||
'oExpectedBefore' => null,
|
||||
'bRenewedDateTouched' => true,
|
||||
),
|
||||
'EXPIRE_ONE_TIME_PWD: nominal case' => array(
|
||||
'sExpirationMode' => 'otp_expire',
|
||||
'oExpectedBefore' => null,
|
||||
'bRenewedDateTouched' => true,
|
||||
),
|
||||
'date initiated' => array(
|
||||
'sExpirationMode' => 'can_expire',
|
||||
'oBefore' => '-1 day',
|
||||
'bRenewedDateTouched' => false,
|
||||
),
|
||||
'date initiated in the future' => array(
|
||||
'sExpirationMode' => 'can_expire',
|
||||
'oBefore' => '+1 day',
|
||||
'bRenewedDateTouched' => false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user