-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsanitize.test.ts
More file actions
42 lines (38 loc) · 1.62 KB
/
Copy pathsanitize.test.ts
File metadata and controls
42 lines (38 loc) · 1.62 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
31
32
33
34
35
36
37
38
39
40
41
42
import { test, expect, vi } from "vitest";
test("returns original URL when HOSTED is false", async () => {
vi.stubEnv("SOURCE_DATABASE_URL", "postgres://localhost/test");
vi.stubEnv("HOSTED", "false");
vi.resetModules();
const { sanitizePostgresUrl } = await import("./sanitize.ts");
const url = "postgres://user:pass@host:5432/db";
expect(sanitizePostgresUrl(url)).toBe(url);
});
test("returns hashed URL when HOSTED is true", async () => {
vi.stubEnv("SOURCE_DATABASE_URL", "postgres://localhost/test");
vi.stubEnv("HOSTED", "true");
vi.resetModules();
const { sanitizePostgresUrl } = await import("./sanitize.ts");
const url = "postgres://user:pass@host:5432/db";
const result = sanitizePostgresUrl(url);
expect(result).toMatch(/^omitted__[a-f0-9]{8}$/);
expect(result).not.toContain("user");
expect(result).not.toContain("pass");
expect(result).not.toContain("host");
});
test("same input produces same hash", async () => {
vi.stubEnv("SOURCE_DATABASE_URL", "postgres://localhost/test");
vi.stubEnv("HOSTED", "true");
vi.resetModules();
const { sanitizePostgresUrl } = await import("./sanitize.ts");
const url = "postgres://user:pass@host:5432/db";
expect(sanitizePostgresUrl(url)).toBe(sanitizePostgresUrl(url));
});
test("different inputs produce different hashes", async () => {
vi.stubEnv("SOURCE_DATABASE_URL", "postgres://localhost/test");
vi.stubEnv("HOSTED", "true");
vi.resetModules();
const { sanitizePostgresUrl } = await import("./sanitize.ts");
const a = sanitizePostgresUrl("postgres://a@host/db1");
const b = sanitizePostgresUrl("postgres://b@host/db2");
expect(a).not.toBe(b);
});