forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-decrypt.test.ts
More file actions
30 lines (24 loc) · 1.1 KB
/
client-decrypt.test.ts
File metadata and controls
30 lines (24 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// src/lib/__tests__/client-decrypt.test.ts
import { describe, expect, it, vi } from "vitest"
vi.mock("@/lib/crypto", () => ({
decrypt: vi.fn((val: string) => `decrypted:${val}`),
}))
import { decrypt } from "@/lib/crypto"
const { decryptClientCredentials } = await import("@/lib/client-decrypt")
describe("decryptClientCredentials", () => {
it("returns decrypted username and password", () => {
const client = { name: "Test", encryptedUsername: "enc-user", encryptedPassword: "enc-pass" }
const key = Buffer.from("a".repeat(64), "hex")
const result = decryptClientCredentials(client, key)
expect(result).toEqual({ username: "decrypted:enc-user", password: "decrypted:enc-pass" })
})
it("throws descriptive error when decrypt fails", () => {
;(decrypt as ReturnType<typeof vi.fn>).mockImplementation(() => {
throw new Error("bad key")
})
const client = { name: "MyClient", encryptedUsername: "x", encryptedPassword: "y" }
expect(() => decryptClientCredentials(client, Buffer.alloc(32))).toThrow(
'Credentials are missing or invalid for client "MyClient"'
)
})
})