chore: removes formbricks_encryption_key-environment-variable (#5426)

This commit is contained in:
Piyush Gupta
2025-04-21 11:25:48 +05:30
committed by GitHub
parent 18e597d8a3
commit 302c6a90c0
7 changed files with 11 additions and 55 deletions
-18
View File
@@ -13,7 +13,6 @@ vi.mock("@formbricks/lib/crypto", () => ({
// Mock constants
vi.mock("@formbricks/lib/constants", () => ({
ENCRYPTION_KEY: "test-encryption-key",
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
}));
// Mock cuid2
@@ -81,7 +80,6 @@ describe("generateSurveySingleUseId", () => {
// Temporarily mock ENCRYPTION_KEY as undefined
vi.doMock("@formbricks/lib/constants", () => ({
ENCRYPTION_KEY: undefined,
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
}));
// Re-import to get the new mock values
@@ -94,7 +92,6 @@ describe("generateSurveySingleUseId", () => {
// Temporarily mock ENCRYPTION_KEY as undefined
vi.doMock("@formbricks/lib/constants", () => ({
ENCRYPTION_KEY: undefined,
FORMBRICKS_ENCRYPTION_KEY: "test-formbricks-encryption-key",
}));
// Re-import to get the new mock values
@@ -102,19 +99,4 @@ describe("generateSurveySingleUseId", () => {
expect(() => validateSurveySingleUseIdNoKey(mockEncryptedCuid)).toThrow("ENCRYPTION_KEY is not set");
});
test("throws error when FORMBRICKS_ENCRYPTION_KEY is not set in validateSurveySingleUseId for AES128", async () => {
// Temporarily mock FORMBRICKS_ENCRYPTION_KEY as undefined
vi.doMock("@formbricks/lib/constants", () => ({
ENCRYPTION_KEY: "test-encryption-key",
FORMBRICKS_ENCRYPTION_KEY: undefined,
}));
// Re-import to get the new mock values
const { validateSurveySingleUseId: validateSurveySingleUseIdNoKey } = await import("./singleUseSurveys");
expect(() =>
validateSurveySingleUseIdNoKey("M(.Bob=dS1!wUSH2lb,E7hxO=He1cnnitmXrG|Su/DKYZrPy~zgS)u?dgI53sfs/")
).toThrow("FORMBRICKS_ENCRYPTION_KEY is not defined");
});
});
+9 -21
View File
@@ -1,6 +1,6 @@
import cuid2 from "@paralleldrive/cuid2";
import { ENCRYPTION_KEY, FORMBRICKS_ENCRYPTION_KEY } from "@formbricks/lib/constants";
import { decryptAES128, symmetricDecrypt, symmetricEncrypt } from "@formbricks/lib/crypto";
import { ENCRYPTION_KEY } from "@formbricks/lib/constants";
import { symmetricDecrypt, symmetricEncrypt } from "@formbricks/lib/crypto";
// generate encrypted single use id for the survey
export const generateSurveySingleUseId = (isEncrypted: boolean): string => {
@@ -21,25 +21,13 @@ export const generateSurveySingleUseId = (isEncrypted: boolean): string => {
export const validateSurveySingleUseId = (surveySingleUseId: string): string | undefined => {
let decryptedCuid: string | null = null;
if (surveySingleUseId.length === 64) {
if (!FORMBRICKS_ENCRYPTION_KEY) {
throw new Error("FORMBRICKS_ENCRYPTION_KEY is not defined");
}
try {
decryptedCuid = decryptAES128(FORMBRICKS_ENCRYPTION_KEY, surveySingleUseId);
} catch (error) {
return undefined;
}
} else {
if (!ENCRYPTION_KEY) {
throw new Error("ENCRYPTION_KEY is not set");
}
try {
decryptedCuid = symmetricDecrypt(surveySingleUseId, ENCRYPTION_KEY);
} catch (error) {
return undefined;
}
if (!ENCRYPTION_KEY) {
throw new Error("ENCRYPTION_KEY is not set");
}
try {
decryptedCuid = symmetricDecrypt(surveySingleUseId, ENCRYPTION_KEY);
} catch (error) {
return undefined;
}
if (cuid2.isCuid(decryptedCuid)) {
@@ -12,7 +12,6 @@ vi.mock("@formbricks/lib/constants", () => ({
FORMBRICKS_API_HOST: "http://localhost:3000",
FORMBRICKS_ENVIRONMENT_ID: "test-env-id",
ENCRYPTION_KEY: "test-encryption-key",
FORMBRICKS_ENCRYPTION_KEY: "test-fb-encryption-key",
WEBAPP_URL: "http://localhost:3000",
DEFAULT_BRAND_COLOR: "#64748b",
AVAILABLE_LOCALES: ["en-US", "de-DE", "pt-BR", "fr-FR", "zh-Hant-TW", "pt-PT"],
@@ -49,7 +48,6 @@ vi.mock("@formbricks/lib/env", () => ({
FORMBRICKS_API_HOST: "http://localhost:3000",
FORMBRICKS_ENVIRONMENT_ID: "test-env-id",
ENCRYPTION_KEY: "test-encryption-key",
FORMBRICKS_ENCRYPTION_KEY: "test-fb-encryption-key",
NODE_ENV: "test",
ENTERPRISE_LICENSE_KEY: "test-license-key",
},