Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Revert the e2e license fakes
Calvin5accb60619ae
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex c1a5bc9182..558029097a 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -54,10 +54,7 @@ E2E tests live in `e2e-test/routes/`. The custom Vitest environment (`e2e-test/v`isTestMode` branches. Replace the module instead, from `test.alias` in`vitest.e2e.config.mts`, with a double under `e2e-test/fakes/`. Production code stays unawarea fake exists. `e2e-test/fakes/aws-parameter-store-sync-fns.ts` and its connection counterpart-are the worked examples. `e2e-test/fakes/license-service.ts` does the same for the plan: a spec-calls `fakeLicense.setFeatures(orgId, { ... })` to turn plan features on over HTTP for an org it-created (the seeded org is refused, since every spec shares it), and-`e2e-test/setup/reset-fakes.ts` clears the overrides at the start of every file.+are the worked examples, and the pre-existing `./license-fns` alias is the precedent.Four things decide whether this works:diff --git a/backend/e2e-test/fakes/license-service.ts b/backend/e2e-test/fakes/license-service.tsdeleted file mode 100644index 1b8a93ccf1..0000000000--- a/backend/e2e-test/fakes/license-service.ts+++ /dev/null@@ -1,66 +0,0 @@-import { seedData1 } from "@app/db/seed-data";-import { TFeatureSet } from "@app/ee/services/license/license-types";--import * as RealLicenseService from "../../src/ee/services/license/license-service";--// Plans belong to an organization, so the fake keys them by org: a spec turns features on for an-// org it created, and no other org's plan moves. Specs stay isolated whatever order they run in.-// Wired up by test.alias in vitest.e2e.config.mts. Nothing under src/ references this file.-//-// The e2e server runs on-prem, where the real getPlan ignores the org and answers with one-// instance-wide plan, so the override sits here rather than in license-fns. Only getPlan is-// replaced; the rest of the service, including the instance-wide onPremFeatures, stays real.-//-// The relative path to the real module is deliberate: the alias keys on the specifier-// "@app/ee/services/license/license-service", so this path is not itself aliased and does not-// resolve back to this file.-export type { TLicenseServiceFactory } from "../../src/ee/services/license/license-service";--// TFeatureSet types several flags as the literal `false` (the unlicensed default), so a plain-// Partial<TFeatureSet> would refuse `true`. Widen those literals to boolean.-type TFeatureOverrides = {- [K in keyof TFeatureSet]?: TFeatureSet[K] extends boolean ? boolean : TFeatureSet[K];-};--// Shared through globalThis for the same reason as the AWS fakes: the alias makes this module-// reachable by more than one specifier, so it can be instantiated twice, and a spec would then-// configure a copy the server never reads.-const globalScope = globalThis as typeof globalThis & {- infisicalFakeLicenseOverrides?: Map<string, TFeatureOverrides>;-};--globalScope.infisicalFakeLicenseOverrides ??= new Map();--const overridesByOrg = globalScope.infisicalFakeLicenseOverrides;--export const licenseServiceFactory: typeof RealLicenseService.licenseServiceFactory = (deps) => {- const service = RealLicenseService.licenseServiceFactory(deps);- const realGetPlan = service.getPlan;-- // Assigned onto the real service rather than spread into a copy, because the service exposes- // onPremFeatures as a getter and a spread would freeze it at its boot value.- service.getPlan = async (orgId, projectId) => {- const plan = await realGetPlan(orgId, projectId);- const overrides = overridesByOrg.get(orgId);- return overrides ? ({ ...plan, ...overrides } as TFeatureSet) : plan;- };-- return service;-};--export const fakeLicense = {- reset: () => {- overridesByOrg.clear();- },-- // Turns plan features on (or off) for one org until the next reset. The seeded org is shared by- // every spec that logs in as the seeded user, so a spec must create its own org to change a plan.- setFeatures: (orgId: string, overrides: TFeatureOverrides) => {- if (orgId === seedData1.organization.id) {- throw new Error(- "fakeLicense.setFeatures: the seeded org is shared across specs. Create an org for this spec (eg createIsolatedOrgAndProject) and change its plan instead."- );- }- overridesByOrg.set(orgId, { ...overridesByOrg.get(orgId), ...overrides });- }-};diff --git a/backend/e2e-test/routes/v1/insights.spec.ts b/backend/e2e-test/routes/v1/insights.spec.tsindex f9a7ac27a2..44da570723 100644--- a/backend/e2e-test/routes/v1/insights.spec.ts+++ b/backend/e2e-test/routes/v1/insights.spec.ts@@ -35,7 +35,7 @@ describe("Insights V1 Router (org-scoped)", async () => {});// Value search sits behind the same plan gate. What the index finds is covered in- // routes/v3/secrets-management.spec.ts, which turns the plan on with fakeLicense.+ // routes/v3/secrets-management.spec.ts, through the service.test("POST secrets search-by-value is registered and refuses on plan restriction", async () => {const res = await testServer.inject({method: "POST",diff --git a/backend/e2e-test/routes/v3/secrets-management.spec.ts b/backend/e2e-test/routes/v3/secrets-management.spec.tsindex 3a54db18ae..cfff104517 100644--- a/backend/e2e-test/routes/v3/secrets-management.spec.ts+++ b/backend/e2e-test/routes/v3/secrets-management.spec.ts@@ -1,10 +1,34 @@-import { fakeLicense } from "e2e-test/fakes/license-service";+import { createMongoAbility } from "@casl/ability";import { createFakeWebhookServer, TFakeWebhookServer } from "e2e-test/fakes/webhook-destination";import { createIsolatedOrgAndProject, createProject } from "e2e-test/testUtils/fixtures";import { createFolder } from "e2e-test/testUtils/folders";+import { projectScopedInsightsDepStubs, usageInsightsDepStubs } from "e2e-test/testUtils/insights";import { createSecretV2, deleteSecretV2, updateSecretV2 } from "e2e-test/testUtils/secrets";import { createWebhook, waitForWebhookRun } from "e2e-test/testUtils/webhooks";+import { isHsmActiveAndEnabled } from "@app/ee/services/hsm/hsm-fns";+import { insightsServiceFactory, TInsightsServiceFactoryDep } from "@app/ee/services/insights/insights-service";+import { TFeatureSet } from "@app/ee/services/license/license-types";+import {+ OrgPermissionSecretsManagementInsightsActions,+ OrgPermissionSet,+ OrgPermissionSubjects+} from "@app/ee/services/permission/org-permission";+import { getConfig, initEnvConfig } from "@app/lib/config/env";+import { initLogger, logger } from "@app/lib/logger";+import { ActorType, AuthMethod } from "@app/services/auth/auth-type";+import { internalKmsDALFactory } from "@app/services/kms/internal-kms-dal";+import { internalKmsKeyVersionDALFactory } from "@app/services/kms/internal-kms-key-version-dal";+import { kmsKekHistoryDALFactory } from "@app/services/kms/kms-kek-history-dal";+import { kmskeyDALFactory } from "@app/services/kms/kms-key-dal";+import { kmsLegacyEncryptionKeyDALFactory } from "@app/services/kms/kms-legacy-encryption-key-dal";+import { kmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";+import { kmsServiceFactory } from "@app/services/kms/kms-service";+import { orgDALFactory } from "@app/services/org/org-dal";+import { projectDALFactory } from "@app/services/project/project-dal";+import { secretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";+import { secretV2BridgeDALFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-dal";+const ENV = "dev";const PROD_ENV = "prod";@@ -16,15 +40,70 @@ type TFoundSecret = {secretPath: string;};-const searchByValue = async (secretValue: string, authToken: string) => {- const res = await testServer.inject({- method: "POST",- url: "/api/v1/insights/secrets/search-by-value",- headers: { authorization: `Bearer ${authToken}` },- body: { secretValue }+// The e2e instance runs unlicensed, and value search sits behind the insights plan, so the route+// refuses every request here (insights.spec.ts asserts that). These tests are about what the index+// written by the secret routes finds, so they search through the service on the same database and+// KMS, with the plan and permission let through.+const buildValueSearch = async () => {+ // Spec files run in a separate module graph from the test server, so the env config and the+ // cryptography module must be initialized here as well (same process env, same result).+ initLogger();+ await initEnvConfig(testHsmService, testKmsRootConfigDAL, testSuperAdminDAL, logger);++ const kmsRootConfigDAL = kmsRootConfigDALFactory(testDb);+ const kmsService = kmsServiceFactory({+ kmsRootConfigDAL,+ kmsLegacyEncryptionKeyDAL: kmsLegacyEncryptionKeyDALFactory(testDb),+ kmsKekHistoryDAL: kmsKekHistoryDALFactory(testDb),+ kmsDAL: kmskeyDALFactory(testDb),+ internalKmsDAL: internalKmsDALFactory(testDb),+ internalKmsKeyVersionDAL: internalKmsKeyVersionDALFactory(testDb),+ orgDAL: orgDALFactory(testDb),+ projectDAL: projectDALFactory(testDb),+ hsmService: testHsmService,+ // startService never touches the key store; only the factory's dependency type requires it.+ keyStore: {+ getItem: async () => null,+ setItemWithExpiry: async () => "OK" as const,+ deleteItem: async () => 0+ },+ envConfig: getConfig()});- expect(res.statusCode).toBe(200);- return res.json().secrets as TFoundSecret[];+ await kmsService.startService(await isHsmActiveAndEnabled({ hsmService: testHsmService, kmsRootConfigDAL }));++ const insightsService = insightsServiceFactory({+ ...projectScopedInsightsDepStubs,+ ...usageInsightsDepStubs,+ orgDAL: orgDALFactory(testDb),+ secretV2BridgeDAL: secretV2BridgeDALFactory({ db: testDb, keyStore: testKeyStore }),+ folderDAL: secretFolderDALFactory(testDb),+ kmsService,+ permissionService: {+ getOrgPermission: async () => ({+ permission: createMongoAbility<OrgPermissionSet>([+ {+ action: OrgPermissionSecretsManagementInsightsActions.SearchAllSecretValues,+ subject: OrgPermissionSubjects.SecretsManagementInsights+ }+ ]),+ memberships: [],+ hasRole: () => false+ })+ } as unknown as TInsightsServiceFactoryDep["permissionService"],+ licenseService: {+ getPlan: async () => ({ secretAccessInsights: true }) as unknown as TFeatureSet+ } as TInsightsServiceFactoryDep["licenseService"]+ } as unknown as TInsightsServiceFactoryDep);++ return async (secretValue: string, orgId: string): Promise<TFoundSecret[]> =>+ insightsService.searchOrgSecretsByValue({+ secretValue,+ orgId,+ actor: ActorType.USER,+ actorId: "value-search-e2e",+ actorAuthMethod: AuthMethod.EMAIL,+ actorOrgId: orgId+ });};const at = (secrets: TFoundSecret[]) => secrets.map((s) => `${s.environment.slug}${s.secretPath}${s.key}`).sort();@@ -98,9 +177,10 @@ describe("Secrets management", () => {});describe("Finding a secret by its value", () => {- // Value search sits behind the insights plan, and the e2e instance runs unlicensed.- beforeAll(() => {- fakeLicense.setFeatures(orgId, { secretAccessInsights: true });+ let searchByValue: Awaited<ReturnType<typeof buildValueSearch>>;++ beforeAll(async () => {+ searchByValue = await buildValueSearch();});test("a rotated value stops being found and the new one starts", async () => {@@ -112,7 +192,7 @@ describe("Secrets management", () => {value: "the-old-value",authToken});- expect(await searchByValue("the-old-value", authToken)).toHaveLength(1);+ expect(await searchByValue("the-old-value", orgId)).toHaveLength(1);await updateSecretV2({workspaceId: projectId,@@ -123,8 +203,8 @@ describe("Secrets management", () => {authToken});- expect(await searchByValue("the-old-value", authToken)).toEqual([]);- expect(await searchByValue("the-new-value", authToken)).toHaveLength(1);+ expect(await searchByValue("the-old-value", orgId)).toEqual([]);+ expect(await searchByValue("the-new-value", orgId)).toHaveLength(1);});// A rename carries no value, so the secret must still be findable by the value it still holds.@@ -147,7 +227,7 @@ describe("Secrets management", () => {authToken});- const found = await searchByValue("survives-a-rename", authToken);+ const found = await searchByValue("survives-a-rename", orgId);expect(found).toHaveLength(1);expect(found[0].key).toBe("AFTER_RENAME");});@@ -161,7 +241,7 @@ describe("Secrets management", () => {value: "here-then-gone",authToken});- expect(await searchByValue("here-then-gone", authToken)).toHaveLength(1);+ expect(await searchByValue("here-then-gone", orgId)).toHaveLength(1);await deleteSecretV2({workspaceId: projectId,@@ -171,7 +251,7 @@ describe("Secrets management", () => {authToken});- expect(await searchByValue("here-then-gone", authToken)).toEqual([]);+ expect(await searchByValue("here-then-gone", orgId)).toEqual([]);});// This is the test the org-scoped index exists for. The project-scoped digest cannot match across@@ -193,7 +273,7 @@ describe("Secrets management", () => {await createSecretV2({ ...copy, value: shared, authToken });}- const found = await searchByValue(shared, authToken);+ const found = await searchByValue(shared, orgId);expect(at(found)).toEqual([`${ENV}/IN_FIRST_ROOT`,`${ENV}/IN_SECOND_PROJECT`,@@ -206,7 +286,6 @@ describe("Secrets management", () => {// The org digest is keyed by the org data key, so one org's values must never match another's.test("a value held in another organization is not found", async () => {const other = await createIsolatedOrgAndProject("secrets-management-e2e-other");- fakeLicense.setFeatures(other.orgId, { secretAccessInsights: true });try {const value = "value-in-a-different-org";await createSecretV2({@@ -218,8 +297,8 @@ describe("Secrets management", () => {authToken: other.authToken});- expect(await searchByValue(value, other.authToken)).toHaveLength(1);- expect(await searchByValue(value, authToken)).toEqual([]);+ expect(await searchByValue(value, other.orgId)).toHaveLength(1);+ expect(await searchByValue(value, orgId)).toEqual([]);expect(other.orgId).not.toBe(orgId);} finally {await other.cleanup();diff --git a/backend/e2e-test/setup/reset-fakes.ts b/backend/e2e-test/setup/reset-fakes.tsindex 305c5f26fc..d05c5951f2 100644--- a/backend/e2e-test/setup/reset-fakes.ts+++ b/backend/e2e-test/setup/reset-fakes.ts@@ -1,7 +1,6 @@import { fakeAwsConnection } from "e2e-test/fakes/aws-connection-fns";import { fakeIamUserSecret } from "e2e-test/fakes/aws-iam-user-secret-rotation-fns";import { fakeParameterStore } from "e2e-test/fakes/aws-parameter-store-sync-fns";-import { fakeLicense } from "e2e-test/fakes/license-service";import { fakeS3Bucket } from "e2e-test/fakes/s3";// The fakes are module singletons shared with the server booted in this same process, and the@@ -19,5 +18,4 @@ beforeAll(() => {fakeAwsConnection.reset();fakeS3Bucket.reset();fakeIamUserSecret.reset();- fakeLicense.reset();});diff --git a/backend/vitest.e2e.config.mts b/backend/vitest.e2e.config.mtsindex 8020922ddb..aaa3ad1a9b 100644--- a/backend/vitest.e2e.config.mts+++ b/backend/vitest.e2e.config.mts@@ -52,9 +52,7 @@ export default defineConfig({// AWS Parameter Store, the AWS IAM user secret rotation provider and the AWS app connection// are replaced by fakes for the whole e2e run, so the secret sync and secret rotation specs// can assert what Infisical hands a destination or a rotation provider without reaching AWS.- // Nothing under src/ knows the fakes exist (see e2e-test/fakes/). The license service is- // replaced the same way, so a spec can turn plan features on for its own org with- // fakeLicense.setFeatures.+ // Nothing under src/ knows the fakes exist (see e2e-test/fakes/).//// Entries match the *import specifier*, which is what keeps this surgical rather than// sweeping: "./aws-parameter-store-sync-fns" is imported only by its own barrel,@@ -71,10 +69,6 @@ export default defineConfig({find: "./license-fns",replacement: path.resolve(__dirname, "./src/ee/services/license/__mocks__/license-fns")},- {- find: /^@app\/ee\/services\/license\/license-service$/,- replacement: path.resolve(__dirname, "./e2e-test/fakes/license-service")- },{find: "./aws-parameter-store-sync-fns",replacement: path.resolve(__dirname, "./e2e-test/fakes/aws-parameter-store-sync-fns")