59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveTenantSnapshotConfig, TenantSnapshotConfigError } from "./env.js";
|
|
|
|
describe("resolveTenantSnapshotConfig", () => {
|
|
it("defaults to encryption=none and no app storage bucket", () => {
|
|
const cfg = resolveTenantSnapshotConfig({});
|
|
expect(cfg.encryption.method).toBe("none");
|
|
expect(cfg.appStorageBucket).toBeNull();
|
|
expect(cfg.s3.region).toBe("us-east-1");
|
|
});
|
|
|
|
it("rejects an unknown BACKUP_ENCRYPTION value", () => {
|
|
expect(() => resolveTenantSnapshotConfig({ BACKUP_ENCRYPTION: "rot13" })).toThrow(
|
|
TenantSnapshotConfigError,
|
|
);
|
|
});
|
|
|
|
it("requires age key material when encryption=age", () => {
|
|
expect(() => resolveTenantSnapshotConfig({ BACKUP_ENCRYPTION: "age" })).toThrow(
|
|
/BACKUP_AGE_PUBLIC_KEY .* BACKUP_AGE_IDENTITY_FILE/u,
|
|
);
|
|
expect(() =>
|
|
resolveTenantSnapshotConfig({
|
|
BACKUP_ENCRYPTION: "age",
|
|
BACKUP_AGE_PUBLIC_KEY: "age1xyz",
|
|
}),
|
|
).not.toThrow();
|
|
expect(() =>
|
|
resolveTenantSnapshotConfig({
|
|
BACKUP_ENCRYPTION: "age",
|
|
BACKUP_AGE_IDENTITY_FILE: "/tmp/key.txt",
|
|
}),
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("threads STORAGE_BUCKET and optional prefix through", () => {
|
|
const cfg = resolveTenantSnapshotConfig({
|
|
STORAGE_BUCKET: "boilerplate-files",
|
|
TENANT_SNAPSHOT_STORAGE_PREFIX: "tenants/abc/",
|
|
});
|
|
expect(cfg.appStorageBucket).toBe("boilerplate-files");
|
|
expect(cfg.storagePrefix).toBe("tenants/abc/");
|
|
});
|
|
|
|
it("threads S3 credentials when both id and secret are set", () => {
|
|
const cfg = resolveTenantSnapshotConfig({
|
|
BACKUP_S3_ENDPOINT: "https://s3.example.com",
|
|
BACKUP_S3_REGION: "eu-central-1",
|
|
BACKUP_S3_FORCE_PATH_STYLE: "true",
|
|
BACKUP_S3_ACCESS_KEY_ID: "AKIA",
|
|
BACKUP_S3_SECRET_ACCESS_KEY: "secret",
|
|
});
|
|
expect(cfg.s3.endpoint).toBe("https://s3.example.com");
|
|
expect(cfg.s3.region).toBe("eu-central-1");
|
|
expect(cfg.s3.forcePathStyle).toBe(true);
|
|
expect(cfg.s3.credentials).toMatchObject({ accessKeyId: "AKIA", secretAccessKey: "secret" });
|
|
});
|
|
});
|