Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { getEnvVariableDefinition, loadRequiredWebConfig, loadWebConfig, WebConfigError } from "./index.js";
|
||||
|
||||
const GDPR_EXPORT_SSE_C_KEY_BASE64 = "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=";
|
||||
const REQUIRED_PRODUCTION_ENV = {
|
||||
APP_NAME: "Production App",
|
||||
DATABASE_URL: "postgres://example.invalid/app",
|
||||
@@ -8,15 +9,73 @@ const REQUIRED_PRODUCTION_ENV = {
|
||||
WEB_APP_HOST: "app.example.com",
|
||||
ADMIN_APP_HOST: "admin.example.com",
|
||||
API_HOST: "api.example.com",
|
||||
PORTAL_APP_HOST: "portal.example.com",
|
||||
WEB_RUNTIME_SURFACE: "core",
|
||||
APP_REVISION: "0123456789abcdef0123456789abcdef01234567",
|
||||
SESSION_SECRET: "session-secret-value-prod-0123456789",
|
||||
AUDIT_CHAIN_SECRET: "audit-chain-secret-value-prod-0123456789",
|
||||
CRYPTO_SECRET: "crypto-secret-value-prod-0123456789",
|
||||
ADMIN_CONNECTION_MASTER_KEY:
|
||||
"admin-connection-key-prod-0123456789",
|
||||
API_ACCESS_TOKEN: "api-access-token-value-prod-0123456789",
|
||||
JWT_SECRET: "jwt-secret-value-prod-0123456789abcd",
|
||||
MCP_RESOURCE_URL: "https://mcp.example.com",
|
||||
MCP_AUTHORIZATION_SERVER_URL: "https://app.example.com",
|
||||
WEB_PUSH_VAPID_PUBLIC_KEY: "web-push-public-key-prod",
|
||||
STORAGE_ENDPOINT: "https://storage.example.com",
|
||||
STORAGE_REGION: "eu-central-1",
|
||||
STORAGE_BUCKET: "private-exports",
|
||||
STORAGE_ACCESS_KEY_ID: "storage-access-key",
|
||||
STORAGE_SECRET_ACCESS_KEY: "storage-secret-key",
|
||||
GDPR_EXPORT_SSE_C_KEY_BASE64,
|
||||
REDIS_URL: "rediss://core-redis.example.test:6380/2",
|
||||
};
|
||||
|
||||
const PORTAL_PRODUCTION_ENV = {
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
WEB_RUNTIME_SURFACE: "portal",
|
||||
SESSION_SECRET: undefined,
|
||||
AUDIT_CHAIN_SECRET: undefined,
|
||||
WEB_APP_HOST: undefined,
|
||||
ADMIN_APP_HOST: undefined,
|
||||
API_HOST: undefined,
|
||||
CRYPTO_SECRET: undefined,
|
||||
API_ACCESS_TOKEN: undefined,
|
||||
JWT_SECRET: undefined,
|
||||
WEB_PUSH_VAPID_PUBLIC_KEY: undefined,
|
||||
PORTAL_SESSION_SECRET: "portal-session-secret-value-prod-0123456789",
|
||||
AUTH_MAGIC_LINK_ENABLED: "true",
|
||||
AUTH_MAGIC_LINK_TOKEN_TTL_MINUTES: "15",
|
||||
CAPTCHA_PROVIDER: "mcaptcha",
|
||||
MCAPTCHA_INSTANCE_URL: "https://captcha.example.test",
|
||||
MCAPTCHA_SITEKEY_LOGIN: "portal-login-sitekey",
|
||||
MCAPTCHA_ACCOUNT_SECRET: "portal-mcaptcha-account-secret",
|
||||
REDIS_URL: "rediss://portal-redis.example.test:6380/3",
|
||||
};
|
||||
|
||||
describe("loadRequiredWebConfig", () => {
|
||||
test("defaults enabled locales to de,en and gates catalog-ready review locales by environment", () => {
|
||||
expect(loadWebConfig({}, { nodeEnv: "development" }).config.i18n.enabledLocales).toEqual(["de", "en"]);
|
||||
expect(loadWebConfig({ I18N_ENABLED_LOCALES: "de,en,pl" }, { nodeEnv: "development" }).config.i18n.enabledLocales).toEqual(["de", "en", "pl"]);
|
||||
|
||||
const production = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, I18N_ENABLED_LOCALES: "de,en,pl" }, { nodeEnv: "production" });
|
||||
expect(production.ok).toBe(false);
|
||||
expect(production.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "I18N_ENABLED_LOCALES" }));
|
||||
|
||||
const staging = loadWebConfig(
|
||||
{ ...REQUIRED_PRODUCTION_ENV, SENTRY_ENVIRONMENT: "staging", I18N_ENABLED_LOCALES: "de,en,pl" },
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
expect(staging.ok).toBe(true);
|
||||
expect(staging.config.i18n.enabledLocales).toEqual(["de", "en", "pl"]);
|
||||
});
|
||||
|
||||
test.each(["de,en,en", "de,fr", "en", "de,,en"])('rejects invalid I18N_ENABLED_LOCALES value "%s"', (value) => {
|
||||
const result = loadWebConfig({ I18N_ENABLED_LOCALES: value }, { nodeEnv: "development" });
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "I18N_ENABLED_LOCALES" }));
|
||||
});
|
||||
|
||||
test("returns production config when required values are valid", () => {
|
||||
const config = loadRequiredWebConfig(
|
||||
{
|
||||
@@ -29,6 +88,8 @@ describe("loadRequiredWebConfig", () => {
|
||||
expect(config).toMatchObject({
|
||||
appName: "Production App",
|
||||
nodeEnv: "production",
|
||||
runtimeSurface: "core",
|
||||
releaseRevision: "0123456789abcdef0123456789abcdef01234567",
|
||||
sessionSecret: "session-secret-value-prod-0123456789",
|
||||
listen: {
|
||||
port: 8080,
|
||||
@@ -40,6 +101,18 @@ describe("loadRequiredWebConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("requires a valid distributed Redis connection for core GDPR export download gates", () => {
|
||||
const missing = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, REDIS_URL: undefined }, { nodeEnv: "production" });
|
||||
const invalid = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, REDIS_URL: "https://redis-secret-sentinel.example.test" }, { nodeEnv: "production" });
|
||||
|
||||
expect(missing.ok).toBe(false);
|
||||
expect(invalid.ok).toBe(false);
|
||||
if (missing.ok || invalid.ok) throw new Error("invalid production Redis fixtures unexpectedly passed");
|
||||
expect(missing.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "REDIS_URL" }));
|
||||
expect(invalid.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-url", name: "REDIS_URL" }));
|
||||
expect(JSON.stringify([missing.diagnostics, invalid.diagnostics])).not.toContain("redis-secret-sentinel");
|
||||
});
|
||||
|
||||
test("throws redacted WebConfigError for missing production SESSION_SECRET", () => {
|
||||
const secretValues = ["crypto-secret-value", "api-access-token-value", "jwt-secret-value"];
|
||||
|
||||
@@ -105,6 +178,200 @@ describe("loadRequiredWebConfig", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("requires the browser VAPID public key in production", () => {
|
||||
const result = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, WEB_PUSH_VAPID_PUBLIC_KEY: undefined }, { nodeEnv: "production" });
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "WEB_PUSH_VAPID_PUBLIC_KEY" }));
|
||||
});
|
||||
|
||||
test("requires an explicit valid runtime surface in production", () => {
|
||||
const missing = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, WEB_RUNTIME_SURFACE: undefined }, { nodeEnv: "production" });
|
||||
const invalid = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, WEB_RUNTIME_SURFACE: "customer" }, { nodeEnv: "production" });
|
||||
|
||||
expect(missing.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "WEB_RUNTIME_SURFACE" }));
|
||||
expect(invalid.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "WEB_RUNTIME_SURFACE" }));
|
||||
expect(JSON.stringify(invalid.diagnostics)).not.toContain("customer");
|
||||
});
|
||||
|
||||
test("loads a portal production surface with only its own session secret", () => {
|
||||
const result = loadWebConfig(PORTAL_PRODUCTION_ENV, { nodeEnv: "production" });
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.config).toMatchObject({
|
||||
runtimeSurface: "portal",
|
||||
portalSessionSecret: "portal-session-secret-value-prod-0123456789",
|
||||
routing: { portalAppHost: "portal.example.com" },
|
||||
});
|
||||
expect(result.config.sessionSecret).toBeUndefined();
|
||||
});
|
||||
|
||||
test("loads the isolated admin runtime with the core session authority", () => {
|
||||
const result = loadWebConfig(
|
||||
{
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
WEB_RUNTIME_SURFACE: "admin",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.config).toMatchObject({
|
||||
runtimeSurface: "admin",
|
||||
sessionSecret: "session-secret-value-prod-0123456789",
|
||||
routing: { adminAppHost: "admin.example.com" },
|
||||
});
|
||||
expect(result.config.portalSessionSecret).toBeUndefined();
|
||||
});
|
||||
|
||||
test("requires HTTPS for a public production portal while allowing the loopback runtime smoke", () => {
|
||||
const publicHttp = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, APP_PROTOCOL: "http" }, { nodeEnv: "production" });
|
||||
const lookalikeHttp = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, APP_PROTOCOL: "http", PORTAL_APP_HOST: "127.evil.com" }, { nodeEnv: "production" });
|
||||
const loopbackHttp = loadWebConfig(
|
||||
{
|
||||
...PORTAL_PRODUCTION_ENV,
|
||||
APP_BASE_DOMAIN: "localhost",
|
||||
PORTAL_APP_HOST: "portal.localhost",
|
||||
APP_PROTOCOL: "http",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(publicHttp.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "APP_PROTOCOL" }));
|
||||
expect(lookalikeHttp.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "APP_PROTOCOL" }));
|
||||
expect(loopbackHttp.ok).toBe(true);
|
||||
});
|
||||
|
||||
test("requires the selected login CAPTCHA contract for the production portal only", () => {
|
||||
const missingProvider = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, CAPTCHA_PROVIDER: undefined }, { nodeEnv: "production" });
|
||||
const invalidProvider = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, CAPTCHA_PROVIDER: "other" }, { nodeEnv: "production" });
|
||||
const incompleteMcaptcha = loadWebConfig(
|
||||
{
|
||||
...PORTAL_PRODUCTION_ENV,
|
||||
MCAPTCHA_INSTANCE_URL: undefined,
|
||||
MCAPTCHA_SITEKEY_LOGIN: undefined,
|
||||
MCAPTCHA_ACCOUNT_SECRET: undefined,
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(missingProvider.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "CAPTCHA_PROVIDER" }));
|
||||
expect(invalidProvider.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-enum", name: "CAPTCHA_PROVIDER" }));
|
||||
expect(incompleteMcaptcha.diagnostics).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ code: "missing-required", name: "MCAPTCHA_INSTANCE_URL" }),
|
||||
expect.objectContaining({ code: "missing-required", name: "MCAPTCHA_SITEKEY_LOGIN" }),
|
||||
expect.objectContaining({ code: "missing-required", name: "MCAPTCHA_ACCOUNT_SECRET" }),
|
||||
])
|
||||
);
|
||||
expect(loadWebConfig(REQUIRED_PRODUCTION_ENV, { nodeEnv: "production" }).diagnostics).not.toEqual(
|
||||
expect.arrayContaining([expect.objectContaining({ name: expect.stringMatching(/^(?:CAPTCHA_PROVIDER|MCAPTCHA_|CAP_|REDIS_URL|BULLMQ_REDIS_URL)/u) })])
|
||||
);
|
||||
});
|
||||
|
||||
test("accepts Cap portal login verification with either its login secret or the shared fallback", () => {
|
||||
const capEnv = {
|
||||
...PORTAL_PRODUCTION_ENV,
|
||||
CAPTCHA_PROVIDER: "cap",
|
||||
MCAPTCHA_INSTANCE_URL: undefined,
|
||||
MCAPTCHA_SITEKEY_LOGIN: undefined,
|
||||
MCAPTCHA_ACCOUNT_SECRET: undefined,
|
||||
CAP_INSTANCE_URL: "https://cap.example.test",
|
||||
CAP_SITEKEY_LOGIN: "portal-cap-login-sitekey",
|
||||
};
|
||||
|
||||
const loginSecret = loadWebConfig({ ...capEnv, CAP_SITE_SECRET_LOGIN: "cap-login-secret" }, { nodeEnv: "production" });
|
||||
const sharedSecret = loadWebConfig({ ...capEnv, CAP_SITE_SECRET: "cap-shared-secret" }, { nodeEnv: "production" });
|
||||
|
||||
expect(loginSecret.ok).toBe(true);
|
||||
expect(sharedSecret.ok).toBe(true);
|
||||
});
|
||||
|
||||
test("rejects incomplete Cap login verification without leaking provider values", () => {
|
||||
const result = loadWebConfig(
|
||||
{
|
||||
...PORTAL_PRODUCTION_ENV,
|
||||
CAPTCHA_PROVIDER: "cap",
|
||||
CAP_INSTANCE_URL: "http://captcha-secret-sentinel.example.test",
|
||||
CAP_SITEKEY_LOGIN: undefined,
|
||||
CAP_SITE_SECRET_LOGIN: undefined,
|
||||
CAP_SITE_SECRET: undefined,
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(result.diagnostics).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ code: "invalid-url", name: "CAP_INSTANCE_URL" }),
|
||||
expect.objectContaining({ code: "missing-required", name: "CAP_SITEKEY_LOGIN" }),
|
||||
expect.objectContaining({ code: "missing-required", name: "CAP_SITE_SECRET_LOGIN" }),
|
||||
])
|
||||
);
|
||||
expect(JSON.stringify(result.diagnostics)).not.toContain("captcha-secret-sentinel");
|
||||
});
|
||||
|
||||
test("requires a valid shared Redis connection and validates a preferred BullMQ override", () => {
|
||||
const missing = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, REDIS_URL: undefined }, { nodeEnv: "production" });
|
||||
const invalidShared = loadWebConfig({ ...PORTAL_PRODUCTION_ENV, REDIS_URL: "https://redis-secret-sentinel.example.test" }, { nodeEnv: "production" });
|
||||
const invalidBullmq = loadWebConfig(
|
||||
{ ...PORTAL_PRODUCTION_ENV, BULLMQ_REDIS_URL: "redis://portal-redis.example.test/not-a-database" },
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(missing.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "REDIS_URL" }));
|
||||
expect(invalidShared.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-url", name: "REDIS_URL" }));
|
||||
expect(invalidBullmq.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-url", name: "BULLMQ_REDIS_URL" }));
|
||||
expect(JSON.stringify(invalidShared.diagnostics)).not.toContain("redis-secret-sentinel");
|
||||
});
|
||||
|
||||
test("requires the dedicated session secret for an explicitly selected portal surface", () => {
|
||||
const result = loadWebConfig({ WEB_RUNTIME_SURFACE: "portal" }, { nodeEnv: "development" });
|
||||
|
||||
expect(result.diagnostics).toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: "missing-required",
|
||||
name: "PORTAL_SESSION_SECRET",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test("forbids crossing core and portal session-secret boundaries", () => {
|
||||
const core = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, PORTAL_SESSION_SECRET: "portal-secret-value-prod-0123456789" }, { nodeEnv: "production" });
|
||||
const portal = loadWebConfig(
|
||||
{
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
WEB_RUNTIME_SURFACE: "portal",
|
||||
PORTAL_SESSION_SECRET: "portal-secret-value-prod-0123456789",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(core.diagnostics).toContainEqual(expect.objectContaining({ code: "forbidden", name: "PORTAL_SESSION_SECRET" }));
|
||||
expect(portal.diagnostics).toContainEqual(expect.objectContaining({ code: "forbidden", name: "SESSION_SECRET" }));
|
||||
});
|
||||
|
||||
test("requires a baked full Git SHA and the portal host in production", () => {
|
||||
const result = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, APP_REVISION: "main", PORTAL_APP_HOST: undefined }, { nodeEnv: "production" });
|
||||
|
||||
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-revision", name: "APP_REVISION" }));
|
||||
expect(result.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "PORTAL_APP_HOST" }));
|
||||
});
|
||||
|
||||
test("rejects malformed or shared portal hosts", () => {
|
||||
const malformed = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, PORTAL_APP_HOST: "[invalid-host" }, { nodeEnv: "production" });
|
||||
const shared = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, PORTAL_APP_HOST: "app.example.com" }, { nodeEnv: "production" });
|
||||
const defaultPortAlias = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, PORTAL_APP_HOST: "app.example.com:443" }, { nodeEnv: "production" });
|
||||
const derivedCoreHost = loadWebConfig(
|
||||
{ ...REQUIRED_PRODUCTION_ENV, WEB_APP_HOST: undefined, PORTAL_APP_HOST: "app.example.com" },
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(malformed.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-host", name: "PORTAL_APP_HOST" }));
|
||||
expect(shared.diagnostics).toContainEqual(expect.objectContaining({ code: "host-conflict", name: "PORTAL_APP_HOST" }));
|
||||
expect(defaultPortAlias.diagnostics).toContainEqual(expect.objectContaining({ code: "host-conflict", name: "PORTAL_APP_HOST" }));
|
||||
expect(derivedCoreHost.diagnostics).toContainEqual(expect.objectContaining({ code: "host-conflict", name: "PORTAL_APP_HOST" }));
|
||||
});
|
||||
|
||||
test("preserves default development behavior by throwing diagnostics instead of silently succeeding", () => {
|
||||
expect(() => loadRequiredWebConfig({})).toThrow(WebConfigError);
|
||||
});
|
||||
@@ -129,6 +396,34 @@ describe("secret strength (production)", () => {
|
||||
expect(JSON.stringify(result.diagnostics)).not.toContain("short-jwt-secret");
|
||||
});
|
||||
|
||||
test("fails production web closed for missing or malformed GDPR export encryption", () => {
|
||||
const missing = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, GDPR_EXPORT_SSE_C_KEY_BASE64: undefined }, { nodeEnv: "production" });
|
||||
const whitespace = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, GDPR_EXPORT_SSE_C_KEY_BASE64: " " }, { nodeEnv: "production" });
|
||||
const malformed = "malformed-customer-key";
|
||||
const invalid = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, GDPR_EXPORT_SSE_C_KEY_BASE64: malformed }, { nodeEnv: "production" });
|
||||
const insecureEndpoint = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, STORAGE_ENDPOINT: "http://storage.example.com" }, { nodeEnv: "production" });
|
||||
|
||||
expect(missing.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "GDPR_EXPORT_SSE_C_KEY_BASE64" }));
|
||||
expect(whitespace.diagnostics).toContainEqual(expect.objectContaining({ code: "missing-required", name: "GDPR_EXPORT_SSE_C_KEY_BASE64" }));
|
||||
expect(invalid.diagnostics).toContainEqual(expect.objectContaining({ code: "weak-secret", name: "GDPR_EXPORT_SSE_C_KEY_BASE64" }));
|
||||
expect(insecureEndpoint.diagnostics).toContainEqual(expect.objectContaining({ code: "invalid-url", name: "STORAGE_ENDPOINT" }));
|
||||
expect(JSON.stringify(invalid.diagnostics)).not.toContain(malformed);
|
||||
});
|
||||
|
||||
test("enforces the production METRICS_TOKEN byte range", () => {
|
||||
const short = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, METRICS_TOKEN: "short" }, { nodeEnv: "production" });
|
||||
const long = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, METRICS_TOKEN: "x".repeat(513) }, { nodeEnv: "production" });
|
||||
expect(short.diagnostics).toContainEqual(expect.objectContaining({ code: "weak-secret", name: "METRICS_TOKEN" }));
|
||||
expect(long.diagnostics).toContainEqual(expect.objectContaining({ code: "weak-secret", name: "METRICS_TOKEN" }));
|
||||
});
|
||||
|
||||
test("rejects weak API-key and MCP token hash secrets in production", () => {
|
||||
const apiKeyHash = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, API_KEY_HASH_SECRET: "short" }, { nodeEnv: "production" });
|
||||
const mcpHash = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, MCP_OAUTH_TOKEN_HASH_SECRET: "short" }, { nodeEnv: "production" });
|
||||
expect(apiKeyHash.diagnostics).toContainEqual(expect.objectContaining({ code: "weak-secret", name: "API_KEY_HASH_SECRET" }));
|
||||
expect(mcpHash.diagnostics).toContainEqual(expect.objectContaining({ code: "weak-secret", name: "MCP_OAUTH_TOKEN_HASH_SECRET" }));
|
||||
});
|
||||
|
||||
test("does not enforce secret length outside production (placeholders allowed)", () => {
|
||||
const result = loadWebConfig({ ...REQUIRED_PRODUCTION_ENV, NODE_ENV: "test", SESSION_SECRET: "short" }, { nodeEnv: "test" });
|
||||
expect(result.diagnostics).not.toContainEqual(expect.objectContaining({ code: "weak-secret" }));
|
||||
@@ -143,6 +438,8 @@ describe("loadWebConfig", () => {
|
||||
expect(result.config).toMatchObject({
|
||||
appName: "HiveGrid",
|
||||
nodeEnv: "development",
|
||||
runtimeSurface: "core",
|
||||
releaseRevision: "unknown",
|
||||
listen: {
|
||||
host: "0.0.0.0",
|
||||
port: 3000,
|
||||
@@ -152,6 +449,7 @@ describe("loadWebConfig", () => {
|
||||
webAppHost: "app.localhost",
|
||||
adminAppHost: "admin.localhost",
|
||||
apiHost: "api.localhost",
|
||||
portalAppHost: "portal.localhost",
|
||||
protocol: "http",
|
||||
},
|
||||
});
|
||||
@@ -169,14 +467,13 @@ describe("loadWebConfig", () => {
|
||||
MCAPTCHA_SITEKEY_LOGIN: "login-key",
|
||||
ANALYTICS_TOKEN: "analytics-token-value",
|
||||
NOTIFICATIONS_NOVU_API_KEY: "novu-secret-value",
|
||||
WEB_PUSH_VAPID_PUBLIC_KEY: "web-push-public-key",
|
||||
MAILJET_API_KEY: "mailjet-public-value",
|
||||
MAILJET_SECRET_KEY: "mailjet-secret-value",
|
||||
MAILJET_FROM_EMAIL: "sender@example.com",
|
||||
MAILJET_FROM_NAME: "Example Support",
|
||||
IPSTACK_API_KEY: "ipstack-api-key",
|
||||
IPAPIIS_API_KEY: "ipapiis-api-key",
|
||||
PORTAL_SERVER_URL: "https://portals.example.com",
|
||||
PORTAL_SERVER_FLY_TOKEN: "portal-fly-token-value",
|
||||
LAGO_API_URL: "https://lago.example.test",
|
||||
LAGO_API_KEY: "lago-secret-value",
|
||||
LAGO_WEBHOOK_SECRET: "lago-webhook-secret-value",
|
||||
@@ -190,6 +487,7 @@ describe("loadWebConfig", () => {
|
||||
STORAGE_BUCKET: "uploads",
|
||||
STORAGE_ACCESS_KEY_ID: "storage-access-key",
|
||||
STORAGE_SECRET_ACCESS_KEY: "storage-secret-key",
|
||||
GDPR_EXPORT_SSE_C_KEY_BASE64,
|
||||
STORAGE_SESSION_TOKEN: "storage-session-token",
|
||||
STORAGE_PUBLIC_BASE_URL: "https://cdn.example.com",
|
||||
STORAGE_FORCE_PATH_STYLE: "true",
|
||||
@@ -230,6 +528,9 @@ describe("loadWebConfig", () => {
|
||||
novu: {
|
||||
apiKey: "novu-secret-value",
|
||||
},
|
||||
webPush: {
|
||||
vapidPublicKey: "web-push-public-key",
|
||||
},
|
||||
mailjet: {
|
||||
apiKey: "mailjet-public-value",
|
||||
secretKey: "mailjet-secret-value",
|
||||
@@ -240,10 +541,6 @@ describe("loadWebConfig", () => {
|
||||
ipstackApiKey: "ipstack-api-key",
|
||||
ipapiIsApiKey: "ipapiis-api-key",
|
||||
},
|
||||
portalServer: {
|
||||
url: "https://portals.example.com",
|
||||
flyToken: "portal-fly-token-value",
|
||||
},
|
||||
lago: {
|
||||
apiUrl: "https://lago.example.test",
|
||||
apiKey: "lago-secret-value",
|
||||
@@ -262,6 +559,7 @@ describe("loadWebConfig", () => {
|
||||
bucket: "uploads",
|
||||
accessKeyId: "storage-access-key",
|
||||
secretAccessKey: "storage-secret-key",
|
||||
gdprExportSseCKey: GDPR_EXPORT_SSE_C_KEY_BASE64,
|
||||
sessionToken: "storage-session-token",
|
||||
publicBaseUrl: "https://cdn.example.com",
|
||||
forcePathStyle: "true",
|
||||
@@ -275,6 +573,75 @@ describe("loadWebConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("exposes Aircall provider configuration without making it a core runtime requirement", () => {
|
||||
const result = loadWebConfig(
|
||||
{
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
AIRCALL_CLIENT_ID: "aircall-client",
|
||||
AIRCALL_CLIENT_SECRET: "aircall-secret",
|
||||
AIRCALL_REDIRECT_URI: "https://app.example.com/integrations/aircall/oauth/callback",
|
||||
AIRCALL_WEBHOOK_URL: "https://api.example.com/v1/webhooks/telephony/aircall",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.config.aircall).toEqual({
|
||||
clientId: "aircall-client",
|
||||
clientSecret: "aircall-secret",
|
||||
redirectUri: "https://app.example.com/integrations/aircall/oauth/callback",
|
||||
webhookUrl: "https://api.example.com/v1/webhooks/telephony/aircall",
|
||||
});
|
||||
expect(getEnvVariableDefinition("AIRCALL_CLIENT_SECRET")?.requiredInProduction).not.toBe(true);
|
||||
});
|
||||
|
||||
test("exposes the optional HalloPetra webhook URL", () => {
|
||||
const result = loadWebConfig(
|
||||
{
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
HALLOPETRA_WEBHOOK_URL: "https://api.example.com/v1/webhooks/telephony/hallopetra",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.config.hallopetra).toEqual({
|
||||
webhookUrl: "https://api.example.com/v1/webhooks/telephony/hallopetra",
|
||||
});
|
||||
expect(getEnvVariableDefinition("HALLOPETRA_WEBHOOK_URL")?.requiredInProduction).not.toBe(true);
|
||||
});
|
||||
|
||||
test("exposes KWP OAuth provider configuration without a redirect override or core runtime requirement", () => {
|
||||
const result = loadWebConfig(
|
||||
{
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
KWP_OAUTH_CLIENT_ID: " kwp-client ",
|
||||
KWP_OAUTH_CLIENT_SECRET: " kwp-secret ",
|
||||
KWP_OAUTH_SCOPES: " openid offline_access ",
|
||||
KWP_CUSTOMER_CODE: " customer-code ",
|
||||
KWP_OIDC_ISSUER: " https://id.example.test/realms/example ",
|
||||
KWP_HIVEGRID_TENANT_ID: " tenant-geerkens ",
|
||||
KWP_MANDANT: " mandant-code ",
|
||||
},
|
||||
{ nodeEnv: "production" }
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.config.kwp).toEqual({
|
||||
clientId: "kwp-client",
|
||||
clientSecret: "kwp-secret",
|
||||
scopes: "openid offline_access",
|
||||
customerCode: "customer-code",
|
||||
oidcIssuer: "https://id.example.test/realms/example",
|
||||
hiveGridTenantId: "tenant-geerkens",
|
||||
mandant: "mandant-code",
|
||||
});
|
||||
for (const key of ["KWP_OAUTH_CLIENT_ID", "KWP_OAUTH_CLIENT_SECRET", "KWP_OAUTH_SCOPES", "KWP_CUSTOMER_CODE", "KWP_OIDC_ISSUER", "KWP_HIVEGRID_TENANT_ID", "KWP_MANDANT"]) {
|
||||
expect(getEnvVariableDefinition(key)?.requiredInProduction, `${key} must remain optional in production`).not.toBe(true);
|
||||
}
|
||||
expect(getEnvVariableDefinition("KWP_OAUTH_REDIRECT_URI")).toBeUndefined();
|
||||
});
|
||||
|
||||
test("normalizes Cap captcha provider values", () => {
|
||||
const result = loadWebConfig({
|
||||
...REQUIRED_PRODUCTION_ENV,
|
||||
@@ -291,7 +658,6 @@ describe("loadWebConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test("exposes demo login hints only for development config", () => {
|
||||
expect(loadWebConfig({ NODE_ENV: "development", DEMO_USER: "demo@example.com:password" }).config.demoUser).toBe("demo@example.com:password");
|
||||
expect(loadWebConfig({ NODE_ENV: "test", DEMO_USER: "demo@example.com:password" }).config.demoUser).toBeUndefined();
|
||||
|
||||
Reference in new issue
Block a user