Skip to content

Commit 9d31de4

Browse files
committed
Handle missing password input in password validator
1 parent 925f6b0 commit 9d31de4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Sprint-3/4-stretch/password-validator.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// A small list of previous passwords that must not be reused.
1+
// A list of previously used passwords that cannot be reused.
22
const previousPasswords = ["Password1!", "Welcome2#", "Strong3$"];
33

44
function passwordValidator(password) {
5+
// Ensure a password value is provided and that it is a string.
6+
if (typeof password !== "string") {
7+
return false;
8+
}
9+
510
// Password must be at least 5 characters long.
611
if (password.length < 5) {
712
return false;

Sprint-3/4-stretch/password-validator.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ test("password is invalid when it has been used before", () => {
6868

6969
expect(result).toEqual(false);
7070
});
71+
72+
test("password is invalid when no password is provided", () => {
73+
const result = isValidPassword();
74+
75+
expect(result).toEqual(false);
76+
});
77+
78+
test("password is invalid when the value is not a string", () => {
79+
const result = isValidPassword(12345);
80+
81+
expect(result).toEqual(false);
82+
});

0 commit comments

Comments
 (0)