Skip to content

Commit

Permalink
Merge pull request #4668 from nucleogenesis/validate-password-length-…
Browse files Browse the repository at this point in the history
…everywhere

(Change|Reset)Password components apply length validation
  • Loading branch information
marcellamaki authored Aug 27, 2024
2 parents 9370553 + 8408593 commit bb7a8a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ describe('resetPassword', () => {
});
it('should call setPassword on submit if password data is valid', () => {
wrapper.setData({ new_password1: 'pass', new_password2: 'pass' });
wrapper.find({ ref: 'form' }).trigger('submit');
expect(setPassword).toHaveBeenCalled();
wrapper.vm.$nextTick(() => {
wrapper.find({ ref: 'form' }).trigger('submit');
expect(setPassword).toHaveBeenCalled();
});
});
it('should retain data from query params so reset credentials are preserved', () => {
router.replace({
Expand All @@ -50,7 +52,9 @@ describe('resetPassword', () => {
},
});
wrapper.setData({ new_password1: 'pass', new_password2: 'pass' });
wrapper.find({ ref: 'form' }).trigger('submit');
expect(setPassword.mock.calls[0][0].test).toBe('testing');
wrapper.vm.$nextTick(() => {
wrapper.find({ ref: 'form' }).trigger('submit');
expect(setPassword.mock.calls[0][0].test).toBe('testing');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PasswordField
v-model="new_password1"
:label="$tr('passwordLabel')"
:additionalRules="passwordValidationRules"
autofocus
/>
<PasswordField
Expand Down Expand Up @@ -52,6 +53,9 @@
passwordConfirmRules() {
return [value => (this.new_password1 === value ? true : this.$tr('passwordMatchMessage'))];
},
passwordValidationRules() {
return [value => (value.length >= 8 ? true : this.$tr('passwordValidationMessage'))];
},
},
methods: {
...mapActions('account', ['setPassword']),
Expand Down Expand Up @@ -80,6 +84,7 @@
resetPasswordPrompt: 'Enter and confirm your new password',
passwordLabel: 'New password',
passwordConfirmLabel: 'Confirm password',
passwordValidationMessage: 'Password should be at least 8 characters long',
passwordMatchMessage: "Passwords don't match",
submitButton: 'Submit',
resetPasswordFailed: 'Failed to reset password. Please try again.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
@submit="submitPassword"
@cancel="dialog = false"
>
<VForm ref="form">
<!-- inline style here avoids scrollbar on validations -->
<VForm ref="form" style="height: 196px">
<PasswordField
v-model="password"
:additionalRules="passwordValidationRules"
:label="$tr('newPasswordLabel')"
/>
<PasswordField
Expand Down Expand Up @@ -52,6 +54,9 @@
this.$emit('input', value);
},
},
passwordValidationRules() {
return [value => (value.length >= 8 ? true : this.$tr('passwordValidationMessage'))];
},
passwordConfirmRules() {
return [value => (this.password === value ? true : this.$tr('formInvalidText'))];
},
Expand Down Expand Up @@ -86,6 +91,7 @@
newPasswordLabel: 'New password',
confirmNewPasswordLabel: 'Confirm new password',
formInvalidText: "Passwords don't match",
passwordValidationMessage: 'Password should be at least 8 characters long',
cancelAction: 'Cancel',
saveChangesAction: 'Save changes',
paswordChangeSuccess: 'Password updated',
Expand Down

0 comments on commit bb7a8a8

Please sign in to comment.