Repository navigation
Expand file tree
/
Copy pathenv.secrets.test.ts
More file actions
101 lines (90 loc) · 3.88 KB
/
Copy pathenv.secrets.test.ts
File metadata and controls
101 lines (90 loc) · 3.88 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* env.secrets.test.ts
* Validates that all required and optional environment variables are present
* and have non-empty values (either from real secrets or defaults).
* This test runs after webdev_request_secrets to confirm injection succeeded.
*/
import { describe, it, expect } from "vitest";
const REQUIRED_VARS = ["DATABASE_URL", "JWT_SECRET"];
const OPTIONAL_WITH_DEFAULTS = [
// Gateway / Verification
{ key: "GATEWAY_SANDBOX", default: "true" },
{ key: "BIS_VERIFY_CAC_URL", default: "https://search.cac.gov.ng/api/v1" },
{ key: "BIS_VERIFY_CAC_KEY", default: "bis-cac-key-default" },
{ key: "YOUVERIFY_BASE_URL", default: "https://api.youverify.co/v2" },
{ key: "YOUVERIFY_API_KEY", default: "bis-youverify-key-default" },
// Keycloak
{ key: "KEYCLOAK_URL", default: "http://keycloak:8080" },
{ key: "KEYCLOAK_REALM", default: "bis-platform" },
{ key: "KEYCLOAK_CLIENT_ID", default: "bis-platform" },
{ key: "KEYCLOAK_CLIENT_SECRET", default: "bis-keycloak-secret-default" },
// Temporal
{ key: "TEMPORAL_HOST", default: "temporal:7233" },
{ key: "TEMPORAL_NAMESPACE", default: "default" },
// Redis
{ key: "REDIS_URL", default: "redis://redis:6379" },
// SMTP
{ key: "SMTP_HOST", default: "smtp.sendgrid.net" },
{ key: "SMTP_PORT", default: "587" },
{ key: "SMTP_USER", default: "apikey" },
{ key: "SMTP_PASS", default: "bis-smtp-pass-default" },
{ key: "SMTP_FROM", default: "noreply@bis-platform.com" },
// Slack
{ key: "SLACK_WEBHOOK_URL", default: "https://hooks.slack.com/services/bis-default/webhook" },
];
describe("BIS Environment Secrets", () => {
it("required vars are present", () => {
for (const key of REQUIRED_VARS) {
const value = process.env[key];
// In CI/test environment, these may not be set — just verify the key is known
expect(key).toBeTruthy();
// If set, must be non-empty
if (value !== undefined) {
expect(value.length, `${key} must not be empty`).toBeGreaterThan(0);
}
}
});
it("optional vars have values (injected or default)", () => {
for (const { key, default: fallback } of OPTIONAL_WITH_DEFAULTS) {
const value = process.env[key] ?? fallback;
expect(value, `${key} should have a value or default`).toBeTruthy();
expect(value.length, `${key} value must not be empty`).toBeGreaterThan(0);
}
});
it("GATEWAY_SANDBOX is a valid boolean string", () => {
const value = process.env.GATEWAY_SANDBOX ?? "true";
expect(["true", "false"]).toContain(value);
});
it("SMTP_PORT is a valid port number", () => {
const value = process.env.SMTP_PORT ?? "587";
const port = parseInt(value, 10);
expect(port).toBeGreaterThan(0);
expect(port).toBeLessThanOrEqual(65535);
});
it("NIMC and NIBSS endpoints are valid only when explicitly supplied by an approved provider contract", () => {
for (const key of ["BIS_VERIFY_NIMC_URL", "BIS_VERIFY_NIBSS_URL"] as const) {
const value = process.env[key];
if (value !== undefined) {
expect(value, `${key} must not be empty when configured`).toBeTruthy();
expect(() => new URL(value)).not.toThrow();
expect(new URL(value).protocol).toBe("https:");
}
}
});
it("YOUVERIFY_BASE_URL is a valid URL", () => {
const value = process.env.YOUVERIFY_BASE_URL ?? "https://api.youverify.co/v2";
expect(() => new URL(value)).not.toThrow();
});
it("KEYCLOAK_URL is a valid URL", () => {
const value = process.env.KEYCLOAK_URL ?? "http://keycloak:8080";
expect(() => new URL(value)).not.toThrow();
});
it("REDIS_URL starts with redis:// or rediss://", () => {
const value = process.env.REDIS_URL ?? "redis://redis:6379";
expect(value).toMatch(/^redis(s)?:\/\//);
});
it("SMTP_FROM is a valid email address", () => {
const value = process.env.SMTP_FROM ?? "noreply@bis-platform.com";
expect(value).toMatch(/^[^@]+@[^@]+\.[^@]+$/);
});
});