style(auth): satisfy Biome in password digest helpers
Unescape dollar signs inside character classes and use template literals instead of string concatenation in the salted digest tests.
This commit is contained in:
1 parent
d131124515
commit
4acafcfef6
2 files changed
+11
-11
No files matched your search
@@ -169,36 +169,36 @@ describe("isCombinedDigestOf", () => {
|
||||
describe("isSaltedDigestOf", () => {
|
||||
it("verifies md5(salt+password) with hash:salt layout", async () => {
|
||||
const salt = "pepper123";
|
||||
const stored = `${await md5Hex(salt + "oldpass")}:${salt}`;
|
||||
const stored = `${await md5Hex(`${salt}oldpass`)}:${salt}`;
|
||||
expect(await isSaltedDigestOf("oldpass", stored)).toBe(true);
|
||||
expect(await isSaltedDigestOf("wrong", stored)).toBe(false);
|
||||
});
|
||||
|
||||
it("verifies md5(password+salt) with hash:salt layout", async () => {
|
||||
const salt = "pepper123";
|
||||
const stored = `${await md5Hex("oldpass" + salt)}:${salt}`;
|
||||
const stored = `${await md5Hex(`oldpass${salt}`)}:${salt}`;
|
||||
expect(await isSaltedDigestOf("oldpass", stored)).toBe(true);
|
||||
});
|
||||
|
||||
it("verifies the salt:hash layout", async () => {
|
||||
const salt = "abc123";
|
||||
const stored = `${salt}:${await md5Hex(salt + "oldpass")}`;
|
||||
const stored = `${salt}:${await md5Hex(`${salt}oldpass`)}`;
|
||||
expect(await isSaltedDigestOf("oldpass", stored)).toBe(true);
|
||||
expect(await isSaltedDigestOf("wrong", stored)).toBe(false);
|
||||
});
|
||||
|
||||
it("verifies the hash$salt layout", async () => {
|
||||
const salt = "s0lt_9";
|
||||
const stored = `${await md5Hex("oldpass" + salt)}$s0lt_9`;
|
||||
const stored = `${await md5Hex(`oldpass${salt}`)}$s0lt_9`;
|
||||
expect(await isSaltedDigestOf("oldpass", stored)).toBe(true);
|
||||
});
|
||||
|
||||
it("verifies salted sha1 and sha256 digests", async () => {
|
||||
const salt = "pepper123";
|
||||
const sha1Stored = `${await sha1Hex(salt + "oldpass")}:${salt}`;
|
||||
const sha1Stored = `${await sha1Hex(`${salt}oldpass`)}:${salt}`;
|
||||
expect(await isSaltedDigestOf("oldpass", sha1Stored)).toBe(true);
|
||||
|
||||
const sha256Stored = `${await sha256Hex("oldpass" + salt)}:${salt}`;
|
||||
const sha256Stored = `${await sha256Hex(`oldpass${salt}`)}:${salt}`;
|
||||
expect(await isSaltedDigestOf("oldpass", sha256Stored)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -268,7 +268,7 @@ describe("checkLogin", () => {
|
||||
|
||||
it("migrates a salted md5 hash to bcrypt (md5(salt+password))", async () => {
|
||||
const salt = "pepper123";
|
||||
const stored = `${await md5Hex(salt + "oldpass")}:${salt}`;
|
||||
const stored = `${await md5Hex(`${salt}oldpass`)}:${salt}`;
|
||||
const res = await checkLogin("oldpass", stored);
|
||||
expect(res.valid).toBe(true);
|
||||
expect(res.upgradedHash).toMatch(/^\$2[aby]\$/);
|
||||
@@ -279,7 +279,7 @@ describe("checkLogin", () => {
|
||||
|
||||
it("migrates a salted sha256 hash to bcrypt (sha256(salt+password))", async () => {
|
||||
const salt = "abc123";
|
||||
const stored = `${salt}:${await sha256Hex(salt + "oldpass")}`;
|
||||
const stored = `${salt}:${await sha256Hex(`${salt}oldpass`)}`;
|
||||
const res = await checkLogin("oldpass", stored);
|
||||
expect(res.valid).toBe(true);
|
||||
expect(res.upgradedHash).toMatch(/^\$2[aby]\$/);
|
||||
|
||||
Reference in new issue
Block a user