Skip to content

Commit bb7a8a8

Browse files
authored
Merge pull request #4668 from nucleogenesis/validate-password-length-everywhere
(Change|Reset)Password components apply length validation
2 parents 9370553 + 8408593 commit bb7a8a8

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

contentcuration/contentcuration/frontend/accounts/pages/__tests__/resetPassword.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ describe('resetPassword', () => {
3939
});
4040
it('should call setPassword on submit if password data is valid', () => {
4141
wrapper.setData({ new_password1: 'pass', new_password2: 'pass' });
42-
wrapper.find({ ref: 'form' }).trigger('submit');
43-
expect(setPassword).toHaveBeenCalled();
42+
wrapper.vm.$nextTick(() => {
43+
wrapper.find({ ref: 'form' }).trigger('submit');
44+
expect(setPassword).toHaveBeenCalled();
45+
});
4446
});
4547
it('should retain data from query params so reset credentials are preserved', () => {
4648
router.replace({
@@ -50,7 +52,9 @@ describe('resetPassword', () => {
5052
},
5153
});
5254
wrapper.setData({ new_password1: 'pass', new_password2: 'pass' });
53-
wrapper.find({ ref: 'form' }).trigger('submit');
54-
expect(setPassword.mock.calls[0][0].test).toBe('testing');
55+
wrapper.vm.$nextTick(() => {
56+
wrapper.find({ ref: 'form' }).trigger('submit');
57+
expect(setPassword.mock.calls[0][0].test).toBe('testing');
58+
});
5559
});
5660
});

contentcuration/contentcuration/frontend/accounts/pages/resetPassword/ResetPassword.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<PasswordField
1010
v-model="new_password1"
1111
:label="$tr('passwordLabel')"
12+
:additionalRules="passwordValidationRules"
1213
autofocus
1314
/>
1415
<PasswordField
@@ -52,6 +53,9 @@
5253
passwordConfirmRules() {
5354
return [value => (this.new_password1 === value ? true : this.$tr('passwordMatchMessage'))];
5455
},
56+
passwordValidationRules() {
57+
return [value => (value.length >= 8 ? true : this.$tr('passwordValidationMessage'))];
58+
},
5559
},
5660
methods: {
5761
...mapActions('account', ['setPassword']),
@@ -80,6 +84,7 @@
8084
resetPasswordPrompt: 'Enter and confirm your new password',
8185
passwordLabel: 'New password',
8286
passwordConfirmLabel: 'Confirm password',
87+
passwordValidationMessage: 'Password should be at least 8 characters long',
8388
passwordMatchMessage: "Passwords don't match",
8489
submitButton: 'Submit',
8590
resetPasswordFailed: 'Failed to reset password. Please try again.',

contentcuration/contentcuration/frontend/settings/pages/Account/ChangePasswordForm.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
@submit="submitPassword"
99
@cancel="dialog = false"
1010
>
11-
<VForm ref="form">
11+
<!-- inline style here avoids scrollbar on validations -->
12+
<VForm ref="form" style="height: 196px">
1213
<PasswordField
1314
v-model="password"
15+
:additionalRules="passwordValidationRules"
1416
:label="$tr('newPasswordLabel')"
1517
/>
1618
<PasswordField
@@ -52,6 +54,9 @@
5254
this.$emit('input', value);
5355
},
5456
},
57+
passwordValidationRules() {
58+
return [value => (value.length >= 8 ? true : this.$tr('passwordValidationMessage'))];
59+
},
5560
passwordConfirmRules() {
5661
return [value => (this.password === value ? true : this.$tr('formInvalidText'))];
5762
},
@@ -86,6 +91,7 @@
8691
newPasswordLabel: 'New password',
8792
confirmNewPasswordLabel: 'Confirm new password',
8893
formInvalidText: "Passwords don't match",
94+
passwordValidationMessage: 'Password should be at least 8 characters long',
8995
cancelAction: 'Cancel',
9096
saveChangesAction: 'Save changes',
9197
paswordChangeSuccess: 'Password updated',

0 commit comments

Comments
 (0)