Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test(e2e): include insights in the license mock

Calvind271da04dedb
diff --git a/backend/e2e-test/routes/v1/insights.spec.ts b/backend/e2e-test/routes/v1/insights.spec.ts
index 44da570723..8ffed2d6fd 100644
--- a/backend/e2e-test/routes/v1/insights.spec.ts
+++ b/backend/e2e-test/routes/v1/insights.spec.ts
@@ -3,51 +3,55 @@ import { describe, expect, test } from "vitest";
const PROJECTS_URL = "/api/v1/insights/secrets/projects";
// Every org-scoped insight, by the URL the router registers it at. The aggregation behind each one is
-// covered against a real database (or a faked ClickHouse) in the e2e-test/insights-*.spec.ts files.
-// This file only asserts the wiring, because the e2e instance runs unlicensed and the plan gate
-// therefore rejects every request before any aggregate is computed.
-const ORG_SCOPED_URLS = {
+// covered against a real database (or a faked ClickHouse) in the e2e-test/insights-*.spec.ts files,
+// including the plan gate. This file only asserts the wiring. The e2e license mock includes insights,
+// so the seeded admin clears both the permission and the plan check.
+const DATABASE_BACKED_URLS = {
summary: "/api/v1/insights/secrets/summary",
projects: PROJECTS_URL,
- accessVolume: "/api/v1/insights/secrets/access-volume",
- authMethods: "/api/v1/insights/secrets/usage/auth-methods",
staticSecrets: "/api/v1/insights/secrets/usage/static-secrets"
};
+// These read audit logs from ClickHouse, which the e2e instance does not run.
+const CLICKHOUSE_BACKED_URLS = {
+ accessVolume: "/api/v1/insights/secrets/access-volume",
+ authMethods: "/api/v1/insights/secrets/usage/auth-methods"
+};
+
+const ORG_SCOPED_URLS = { ...DATABASE_BACKED_URLS, ...CLICKHOUSE_BACKED_URLS };
+
describe("Insights V1 Router (org-scoped)", async () => {
- test.each(Object.entries(ORG_SCOPED_URLS))("GET %s is registered and refuses on plan restriction", async (_, url) => {
+ test.each(Object.entries(DATABASE_BACKED_URLS))("GET %s is registered and answers", async (_, url) => {
const res = await testServer.inject({
method: "GET",
url,
headers: { authorization: `Bearer ${jwtAuthToken}` }
});
- // 400, not 403: the seeded user is an org admin, so it clears the Secrets Management Insights
- // permission check and falls through to the licence gate.
- expect(res.statusCode).toBe(400);
- expect(res.json().message).toContain("Upgrade your plan");
+ expect(res.statusCode).toBe(200);
});
+ test.each(Object.entries(CLICKHOUSE_BACKED_URLS))(
+ "GET %s is registered and says ClickHouse is required",
+ async (_, url) => {
+ const res = await testServer.inject({
+ method: "GET",
+ url,
+ headers: { authorization: `Bearer ${jwtAuthToken}` }
+ });
+
+ expect(res.statusCode).toBe(400);
+ expect(res.json().message).toContain("ClickHouse");
+ }
+ );
+
test.each(Object.entries(ORG_SCOPED_URLS))("GET %s requires authentication", async (_, url) => {
const res = await testServer.inject({ method: "GET", url });
expect(res.statusCode).toBe(401);
});
- // Value search sits behind the same plan gate. What the index finds is covered in
- // 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",
- url: "/api/v1/insights/secrets/search-by-value",
- headers: { authorization: `Bearer ${jwtAuthToken}` },
- body: { secretValue: "any-value" }
- });
-
- expect(res.statusCode).toBe(400);
- expect(res.json().message).toContain("Upgrade your plan");
- });
-
+ // What value search finds is covered in routes/v3/secrets-management.spec.ts.
test("POST secrets search-by-value rejects an empty value", 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.ts
index cfff104517..bad31c5221 100644
--- a/backend/e2e-test/routes/v3/secrets-management.spec.ts
+++ b/backend/e2e-test/routes/v3/secrets-management.spec.ts
@@ -1,34 +1,9 @@
-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";
@@ -40,70 +15,15 @@ type TFoundSecret = {
secretPath: string;
};
-// 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()
+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 }
});
- 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
- });
+ expect(res.statusCode).toBe(200);
+ return res.json().secrets as TFoundSecret[];
};
const at = (secrets: TFoundSecret[]) => secrets.map((s) => `${s.environment.slug}${s.secretPath}${s.key}`).sort();
@@ -177,12 +97,6 @@ describe("Secrets management", () => {
});
describe("Finding a secret by its value", () => {
- let searchByValue: Awaited<ReturnType<typeof buildValueSearch>>;
-
- beforeAll(async () => {
- searchByValue = await buildValueSearch();
- });
-
test("a rotated value stops being found and the new one starts", async () => {
await createSecretV2({
workspaceId: projectId,
@@ -192,7 +106,7 @@ describe("Secrets management", () => {
value: "the-old-value",
authToken
});
- expect(await searchByValue("the-old-value", orgId)).toHaveLength(1);
+ expect(await searchByValue("the-old-value", authToken)).toHaveLength(1);
await updateSecretV2({
workspaceId: projectId,
@@ -203,8 +117,8 @@ describe("Secrets management", () => {
authToken
});
- expect(await searchByValue("the-old-value", orgId)).toEqual([]);
- expect(await searchByValue("the-new-value", orgId)).toHaveLength(1);
+ expect(await searchByValue("the-old-value", authToken)).toEqual([]);
+ expect(await searchByValue("the-new-value", authToken)).toHaveLength(1);
});
// A rename carries no value, so the secret must still be findable by the value it still holds.
@@ -227,7 +141,7 @@ describe("Secrets management", () => {
authToken
});
- const found = await searchByValue("survives-a-rename", orgId);
+ const found = await searchByValue("survives-a-rename", authToken);
expect(found).toHaveLength(1);
expect(found[0].key).toBe("AFTER_RENAME");
});
@@ -241,7 +155,7 @@ describe("Secrets management", () => {
value: "here-then-gone",
authToken
});
- expect(await searchByValue("here-then-gone", orgId)).toHaveLength(1);
+ expect(await searchByValue("here-then-gone", authToken)).toHaveLength(1);
await deleteSecretV2({
workspaceId: projectId,
@@ -251,7 +165,7 @@ describe("Secrets management", () => {
authToken
});
- expect(await searchByValue("here-then-gone", orgId)).toEqual([]);
+ expect(await searchByValue("here-then-gone", authToken)).toEqual([]);
});
// This is the test the org-scoped index exists for. The project-scoped digest cannot match across
@@ -273,7 +187,7 @@ describe("Secrets management", () => {
await createSecretV2({ ...copy, value: shared, authToken });
}
- const found = await searchByValue(shared, orgId);
+ const found = await searchByValue(shared, authToken);
expect(at(found)).toEqual([
`${ENV}/IN_FIRST_ROOT`,
`${ENV}/IN_SECOND_PROJECT`,
@@ -297,8 +211,8 @@ describe("Secrets management", () => {
authToken: other.authToken
});
- expect(await searchByValue(value, other.orgId)).toHaveLength(1);
- expect(await searchByValue(value, orgId)).toEqual([]);
+ expect(await searchByValue(value, other.authToken)).toHaveLength(1);
+ expect(await searchByValue(value, authToken)).toEqual([]);
expect(other.orgId).not.toBe(orgId);
} finally {
await other.cleanup();
diff --git a/backend/src/ee/services/license/__mocks__/license-fns.ts b/backend/src/ee/services/license/__mocks__/license-fns.ts
index e36eadd2ff..3bf41b977c 100644
--- a/backend/src/ee/services/license/__mocks__/license-fns.ts
+++ b/backend/src/ee/services/license/__mocks__/license-fns.ts
@@ -26,7 +26,7 @@ export const getDefaultOnPremFeatures = () => {
enforceGoogleSSO: false,
hsm: false,
oidcSSO: true,
- secretAccessInsights: false,
+ secretAccessInsights: true,
scim: true,
ldap: true,
groups: false,