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
test(secret-sharing): cover analytics id correlation and request deletion
Vlad Ligai0d07abcbeea8
diff --git a/backend/src/server/routes/v1/secret-requests-router.test.ts b/backend/src/server/routes/v1/secret-requests-router.test.tsindex cb4a042778..1c165fe5bc 100644--- a/backend/src/server/routes/v1/secret-requests-router.test.ts+++ b/backend/src/server/routes/v1/secret-requests-router.test.ts@@ -17,7 +17,17 @@ const buildServer = async () => {app.setSerializerCompiler(serializerCompiler);app.decorate("services", {- secretSharing: { createSecretRequest: vi.fn().mockResolvedValue({ id: REQUEST_ID }) },+ secretSharing: {+ createSecretRequest: vi.fn().mockResolvedValue({ id: REQUEST_ID }),+ deleteSharedSecretById: vi.fn().mockResolvedValue({+ id: REQUEST_ID,+ type: "request",+ accessType: "organization",+ expiresAt: new Date(Date.now() + 86_400_000),+ createdAt: new Date(),+ updatedAt: new Date()+ })+ },auditLog: { createAuditLog: vi.fn().mockResolvedValue(undefined) },telemetry: { sendPostHogEvents }} as never);@@ -43,11 +53,14 @@ describe("secret request routes", () => {app = undefined;});- test("a new secret request's id is not sent to analytics", async () => {+ test.each([+ ["created", { method: "POST", url: URL, body: { expiresIn: "1d" } }],+ ["deleted", { method: "DELETE", url: `${URL}/${REQUEST_ID}` }]+ ] as const)("a %s secret request's id is not sent to analytics", async (_, request) => {const server = await buildServer();app = server.app;- const res = await app.inject({ method: "POST", url: URL, body: { expiresIn: "1d" } });+ const res = await app.inject(request);expect(res.statusCode).toBe(200);expect(server.sendPostHogEvents).toHaveBeenCalledTimes(1);diff --git a/backend/src/server/routes/v1/secret-sharing-router.test.ts b/backend/src/server/routes/v1/secret-sharing-router.test.tsindex 05f8e8ac0a..645a96fa1e 100644--- a/backend/src/server/routes/v1/secret-sharing-router.test.ts+++ b/backend/src/server/routes/v1/secret-sharing-router.test.ts@@ -12,11 +12,12 @@ vi.mock("@app/lib/config/env", async (importOriginal) => ({const URL = "/api/v1/shared-secrets";const SHARE_ID = "q1w2e3r4t5y6u7i8o9p0a1s2d3f4g5h6j7k8l9z0x1c";+const OTHER_SHARE_ID = "m1n2b3v4c5x6z7l8k9j0h1g2f3d4s5a6p7o8i9u0y1t";-const buildServer = async () => {+const buildServer = async (shareId = SHARE_ID) => {const sendPostHogEvents = vi.fn().mockResolvedValue(undefined);const share = {- id: SHARE_ID,+ id: shareId,orgId: null,accessType: "anyone",type: "share",@@ -76,4 +77,24 @@ describe("secret sharing routes", () => {expect(server.sendPostHogEvents).toHaveBeenCalledTimes(1);expect(JSON.stringify(server.sendPostHogEvents.mock.calls)).not.toContain(SHARE_ID);});++ test("a share's create and view events carry the same analytics id, unique to that share", async () => {+ const distinctIdsFor = async (shareId: string) => {+ const server = await buildServer(shareId);+ app = server.app;+ await app.inject({ method: "POST", url: `${URL}/public`, body: { secretValue: "value", expiresIn: "1h" } });+ await app.inject({ method: "POST", url: `${URL}/${shareId}/access`, body: {} });+ await app.close();+ app = undefined;++ expect(server.sendPostHogEvents).toHaveBeenCalledTimes(2);+ return server.sendPostHogEvents.mock.calls.map(([event]) => (event as { distinctId: string }).distinctId);+ };++ const [created, viewed] = await distinctIdsFor(SHARE_ID);+ const [otherCreated] = await distinctIdsFor(OTHER_SHARE_ID);++ expect(viewed).toBe(created);+ expect(otherCreated).not.toBe(created);+ });});