N°524 - password validity message can be superseded with conf

This commit is contained in:
bruno DA SILVA
2020-02-07 17:24:13 +01:00
parent e42aab30a5
commit 7e61917521
3 changed files with 95 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
<module_parameters>
<parameters id="authent-local" _delta="define">
<password_validation.pattern>^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$</password_validation.pattern>
<password_validation.classes></password_validation.classes>
<password_validation.message type="hash"></password_validation.message>
</parameters>
</module_parameters>
</itop_design>

View File

@@ -325,7 +325,24 @@ class UserPasswordPolicyRegex implements UserLocalPasswordValidator
return new UserLocalPasswordValidity(true);
}
$sUserLanguage = Dict::GetUserLanguage();
$customMessages = $config->GetModuleSetting('authent-local', 'password_validation.message', null);
if (is_string($customMessages) )
{
$sMessage = $customMessages;
}
elseif (isset($customMessages) && array_key_exists($sUserLanguage, $customMessages))
{
$sMessage = $customMessages[$sUserLanguage];
}
elseif (isset($customMessages) && array_key_exists('EN US', $customMessages))
{
$sMessage = $customMessages['EN US'];
}
else
{
$sMessage = Dict::S('Error:UserLocalPasswordValidator:UserPasswordPolicyRegex:ValidationFailed');
}
return new UserLocalPasswordValidity(
false,

View File

@@ -43,7 +43,7 @@ class UserLocalTest extends ItopTestCase
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
public function testValidatePassword($sPassword, $aValidatorNames, $aConfigValueMap, $bExpectedCheckStatus, $expectedCheckIssues = null)
public function testValidatePassword($sPassword, $aValidatorNames, $aConfigValueMap, $bExpectedCheckStatus, $expectedCheckIssues = null, $sUserLanguage = null)
{
$configMock = $this->createMock(\Config::class);
@@ -51,6 +51,11 @@ class UserLocalTest extends ItopTestCase
->method('GetModuleSetting')
->willReturnMap($aConfigValueMap);
if (isset($sUserLanguage))
{
\Dict::SetUserLanguage($sUserLanguage);
}
/** @var UserLocal $oUserLocal */
$oUserLocal = \MetaModel::NewObject('UserLocal', array('login' => 'john'));
/** @var \ormLinkSet $oProfileSet */
@@ -171,6 +176,76 @@ class UserLocalTest extends ItopTestCase
'expectedCheckIssues' => 'UserLocalPasswordPolicyMockNotValid',
),
'notValidPattern custom message FR' => array(
'password' => 'foo',
'aValidatorCollection' => array(
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('FR FR' => 'fr message', 'EN US' => 'en message')),
),
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'fr message',
'userLanguage' => 'FR FR',
),
'notValidPattern custom message EN' => array(
'password' => 'foo',
'aValidatorCollection' => array(
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('FR FR' => 'fr message', 'EN US' => 'en message')),
),
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'en message',
'userLanguage' => 'EN US',
),
'notValidPattern custom message Fallback' => array(
'password' => 'foo',
'aValidatorCollection' => array(
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('EN US' => 'en message')),
),
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'en message',
'userLanguage' => 'FR FR',
),
'notValidPattern custom message empty array' => array(
'password' => 'foo',
'aValidatorCollection' => array(
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array()),
),
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'Password must be at least 8 characters and include uppercase, lowercase, numeric and special characters.',
'userLanguage' => 'EN US',
),
'notValidPattern custom message string not array' => array(
'password' => 'foo',
'aValidatorCollection' => array(
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, 'not an array'),
),
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'not an array',
'userLanguage' => 'EN US',
),
);
}