feat: Prefix api keys

This commit is contained in:
Tom Moor
2022-12-03 18:21:33 -05:00
parent 0f31d5b45f
commit d6d1eb4485
4 changed files with 36 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
import randomstring from "randomstring";
import { buildApiKey } from "@server/test/factories";
import ApiKey from "./ApiKey";
describe("#ApiKey", () => {
describe("match", () => {
test("should match an API secret", async () => {
const apiKey = await buildApiKey({
name: "Dev",
});
expect(ApiKey.match(apiKey?.secret)).toBe(true);
expect(ApiKey.match(`${randomstring.generate(38)}`)).toBe(true);
});
test("should not match non secrets", async () => {
expect(ApiKey.match("123")).toBe(false);
expect(ApiKey.match("1234567890")).toBe(false);
});
});
});