Skip to content

Commit

Permalink
remove user validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mgold1234 committed Dec 13, 2024
1 parent bd11b66 commit ab65765
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 89 deletions.
10 changes: 1 addition & 9 deletions src/Components/CreateImageWizard/CreateImageWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
useDetailsValidation,
useRegistrationValidation,
useHostnameValidation,
useUserValidation,
} from './utilities/useValidation';
import {
isAwsAccountIdValid,
Expand Down Expand Up @@ -224,9 +223,6 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
const firstBootValidation = useFirstBootValidation();
// Details
const detailsValidation = useDetailsValidation();
// Users
const userValidation = useUserValidation();

let startIndex = 1; // default index
if (isEdit) {
startIndex = 19;
Expand Down Expand Up @@ -456,13 +452,9 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
name="Users"
id="wizard-users"
key="wizard-users"
status={userValidation.disabledNext ? 'error' : 'default'}
isHidden={!isUsersEnabled}
footer={
<CustomWizardFooter
disableNext={userValidation.disabledNext}
optional={true}
/>
<CustomWizardFooter disableNext={false} optional={true} />
}
>
<UsersStep />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
setUserSshKedByIndex,
setUserAdministratorByIndex,
} from '../../../../../store/wizardSlice';
import { useUserValidation } from '../../../utilities/useValidation';
import {
HookValidatedInput,
HookValidatedInputWithPasswordVisibilityButton,
Expand Down Expand Up @@ -90,7 +89,11 @@ const UserInfo = () => {
};
const toggleConfirmPasswordVisibility = () =>
setIsConfirmPasswordVisible(!isConfirmPasswordVisible);
const stepValidation = useUserValidation();
// TODO implement validation hooks
const stepValidation = {
errors: {},
disabledNext: false,
};

return (
<Form>
Expand Down
77 changes: 1 addition & 76 deletions src/Components/CreateImageWizard/utilities/useValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import {
selectActivationKey,
selectRegistrationType,
selectHostname,
selectUserName,
selectUserPassword,
selectConfirmUserPassword,
selectUserSshKey,
selectUsers,
} from '../../../store/wizardSlice';
import {
getDuplicateMountPoints,
Expand All @@ -32,10 +27,6 @@ import {
isMountpointMinSizeValid,
isSnapshotValid,
isHostnameValid,
isPasswordValid,
isUserNameValid,
isConfirmPasswordValid,
isSshKeyValid,
} from '../validators';

export type StepValidation = {
Expand All @@ -52,15 +43,13 @@ export function useIsBlueprintValid(): boolean {
const hostname = useHostnameValidation();
const firstBoot = useFirstBootValidation();
const details = useDetailsValidation();
const users = useUserValidation();
return (
!registration.disabledNext &&
!filesystem.disabledNext &&
!snapshot.disabledNext &&
!hostname.disabledNext &&
!firstBoot.disabledNext &&
!details.disabledNext &&
!users.disabledNext
!details.disabledNext
);
}

Expand Down Expand Up @@ -166,70 +155,6 @@ export function useHostnameValidation(): StepValidation {
return { errors: {}, disabledNext: false };
}

export function useUserValidation(): StepValidation {
const userNameSelector = selectUserName(0);
const users = useAppSelector(selectUsers);
const userName = useAppSelector(userNameSelector);
const userPasswordSelector = selectUserPassword(0);
const userPassword = useAppSelector(userPasswordSelector);
const userConfirmPasswordSelector = selectConfirmUserPassword(0);
const userConfirmPassword = useAppSelector(userConfirmPasswordSelector);
const userSshKeySelector = selectUserSshKey(0);
const userSshKey = useAppSelector(userSshKeySelector);
const userNameValid = isUserNameValid(userName || '');
const passwordValid = isPasswordValid(userPassword || '');

const passwordConfirmMatchValid = isConfirmPasswordValid(
userPassword || '',
userConfirmPassword || ''
);
const sshKeyValid = isSshKeyValid(userSshKey || '');
const isPasswordAndConfirmValid = passwordValid && passwordConfirmMatchValid;
const canProceed =
// Case 1: there is no users
users.length === 0 ||
// Case 2: All fields are empty
(userName === '' &&
userPassword === '' &&
userConfirmPassword === '' &&
userSshKey === '') ||
// Case 3: Name and password are valid
(userName && userNameValid && userPassword && isPasswordAndConfirmValid) ||
// Case 4: Name and SSH Key are valid
(userName && userNameValid && userSshKey && sshKeyValid);

return {
errors: {
userName: !userNameValid
? 'Invalid user name. Usernames may contain only lower and upper case letters, digits,\n' +
' underscores, or dashes. They can end with a dollar sign. Dashes are not\n' +
' allowed at the beginning of the username. Fully numeric usernames and\n' +
' usernames . or .. are also disallowed. It is not recommended to use\n' +
' usernames beginning with . character as their home directories will be\n' +
' hidden in the ls output.\n' +
'\n' +
' Usernames may only be up to 32 characters long.'
: '',
userPassword: !userPassword
? ''
: !passwordValid
? 'Invalid user password'
: '',
userConfirmPassword: !userPassword
? ''
: !passwordConfirmMatchValid
? 'password and confirm password should be the same'
: '',
userSshKey: !userSshKey
? ''
: !sshKeyValid
? "Value does not match pattern: /^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521)) \\\\S+/.'"
: '',
},
disabledNext: !canProceed,
};
}

export function useDetailsValidation(): StepValidation {
const name = useAppSelector(selectBlueprintName);
const description = useAppSelector(selectBlueprintDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Step Users', () => {
await waitFor(() => user.type(enterUserName, 'b'));
await waitFor(() => expect(enterUserName).toHaveValue('b'));
const nextButton = await getNextButton();
await waitFor(() => expect(nextButton).toBeDisabled());
await waitFor(() => expect(nextButton).toBeEnabled());
});

test('clicking Back loads Additional packages', async () => {
Expand Down Expand Up @@ -95,7 +95,6 @@ describe('Step Users', () => {
const nextButton = await getNextButton();
await waitFor(() => user.type(enterUserName, 'best'));
await waitFor(() => expect(enterUserName).toHaveValue('best'));
await waitFor(() => expect(nextButton).toBeDisabled());
const enterUserPassword = screen.getByPlaceholderText(/enter password/i);
await waitFor(() => user.type(enterUserPassword, 'bestPASSWORD11'));
const enterUserConfirmPassword =
Expand Down

0 comments on commit ab65765

Please sign in to comment.