From dee1686401a9ca5c5d626a2eeea6d74fc3ece6c7 Mon Sep 17 00:00:00 2001 From: Luis Deschamps Rudge Date: Wed, 22 May 2019 20:03:25 -0300 Subject: [PATCH] Prevent form submit when password is empty --- src/__tests__/field/password.test.js | 4 ++++ src/field/password.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/__tests__/field/password.test.js b/src/__tests__/field/password.test.js index 56d95dc14..32aff9709 100644 --- a/src/__tests__/field/password.test.js +++ b/src/__tests__/field/password.test.js @@ -8,6 +8,10 @@ describe('field/password', () => { passwordField = require('field/password'); }); describe('validatePassword()', () => { + it(`returns false when there is no password`, () => { + const value = passwordField.validatePassword(''); + expect(value).toBe(false); + }); it(`returns true when there is no policy`, () => { const value = passwordField.validatePassword('the-password'); expect(value).toBe(true); diff --git a/src/field/password.js b/src/field/password.js index eba939918..52587854e 100644 --- a/src/field/password.js +++ b/src/field/password.js @@ -2,6 +2,9 @@ import PasswordPolicy from 'password-sheriff/lib/policy'; import { setField } from './index'; export function validatePassword(password, policy) { + if (!password) { + return false; + } if (!policy) { return true; }