From 93e9937e5cf9cb7092368a3a499eaca87bc7f82f Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 12 Jan 2024 07:25:33 +0100 Subject: [PATCH] Add some test cases to the password strength service (#7483) Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> --- .../password-strength.service.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 libs/common/src/tools/password-strength/password-strength.service.spec.ts diff --git a/libs/common/src/tools/password-strength/password-strength.service.spec.ts b/libs/common/src/tools/password-strength/password-strength.service.spec.ts new file mode 100644 index 00000000000..852ba8c7218 --- /dev/null +++ b/libs/common/src/tools/password-strength/password-strength.service.spec.ts @@ -0,0 +1,27 @@ +import { PasswordStrengthService } from "./password-strength.service"; + +describe("PasswordStrengthService", () => { + test.each([ + ["password", "random@bitwarden.com", 0], + ["password11", "random@bitwarden.com", 1], + ["Weakpass2", "random@bitwarden.com", 2], + ["GoodPass3!", "random@bitwarden.com", 3], + ["VeryStrong123@#", "random@bitwarden.com", 4], + ])("getPasswordStrength(%s, %s) should return %i", (password, email, expected) => { + const service = new PasswordStrengthService(); + + const result = service.getPasswordStrength(password, email); + + expect(result.score).toBe(expected); + }); + + it("getPasswordStrength should penalize passwords that contain the email address", () => { + const service = new PasswordStrengthService(); + + const resultWithoutEmail = service.getPasswordStrength("asdfjkhkjwer!", "random@bitwarden.com"); + expect(resultWithoutEmail.score).toBe(4); + + const result = service.getPasswordStrength("asdfjkhkjwer!", "asdfjkhkjwer@bitwarden.com"); + expect(result.score).toBe(1); + }); +});