Wizard: Add password validation in User step

This commit adds password validation to the User step:
- Moved password validation logic to a separate `checkPasswordValidity` function, returning detailed results (strength and validation state).
- Simplified validation in `PasswordValidatedInput` by using `checkPasswordValidity` results directly.
- Added dynamic password strength indicator showing success or error based on requirements.
- Integrated environment-specific validation messages (e.g., for Azure).
- Improved code separation between presentation and validation for better maintainability.
- Unit tests: Adds tests for invalid passwords, covering both default and Azure cases.
This commit is contained in:
Michal Gold 2025-02-04 15:58:54 +02:00 committed by Klara Simickova
parent ef9510327d
commit 265ba2ac78
7 changed files with 332 additions and 113 deletions

View file

@ -16,11 +16,9 @@ import {
setUserAdministratorByIndex,
removeUser,
} from '../../../../../store/wizardSlice';
import { PasswordValidatedInput } from '../../../utilities/PasswordValidatedInput';
import { useUsersValidation } from '../../../utilities/useValidation';
import {
HookPasswordValidatedInput,
ValidatedInputAndTextArea,
} from '../../../ValidatedInput';
import { ValidatedInputAndTextArea } from '../../../ValidatedInput';
const UserInfo = () => {
const dispatch = useAppDispatch();
const index = 0;
@ -41,7 +39,7 @@ const UserInfo = () => {
};
const handlePasswordChange = (
_event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>,
_event: React.FormEvent<HTMLInputElement>,
value: string
) => {
dispatch(setUserPasswordByIndex({ index: index, password: value }));
@ -81,16 +79,12 @@ const UserInfo = () => {
fieldName="userName"
/>
</FormGroup>
<FormGroup isRequired label="Password">
<HookPasswordValidatedInput
ariaLabel="blueprint user password"
value={userPassword || ''}
onChange={(_e, value) => handlePasswordChange(_e, value)}
placeholder="Enter password"
stepValidation={stepValidation}
fieldName="userPassword"
/>
</FormGroup>
<PasswordValidatedInput
value={userPassword || ''}
ariaLabel="blueprint user password"
placeholder="Enter password"
onChange={(_e, value) => handlePasswordChange(_e, value)}
/>
<FormGroup isRequired label="SSH key">
<ValidatedInputAndTextArea
inputType={'textArea'}