Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Change|Reset)Password components apply length validation #4668

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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