Add some test cases to the password strength service (#7483)

Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
This commit is contained in:
Oscar Hinton 2024-01-12 07:25:33 +01:00 committed by GitHub
parent 7908be9fa6
commit 93e9937e5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -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);
});
});