Skip to content

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

test: update Kubernetes and connection function tests to include project metadata

Victor Hugo dos Santos3c4e83e53d19
diff --git a/backend/src/ee/services/dynamic-secret/providers/kubernetes.test.ts b/backend/src/ee/services/dynamic-secret/providers/kubernetes.test.ts
index a725d8a5df..ac28a7cf79 100644
--- a/backend/src/ee/services/dynamic-secret/providers/kubernetes.test.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/kubernetes.test.ts
@@ -82,6 +82,9 @@ const STATIC_INPUT_BASE = {
sslRejectUnauthorized: true
};
+/** `TDynamicProviderFns.validateConnection` always receives project metadata; K8s ignores it in this test. */
+const VALIDATE_METADATA = { projectId: "00000000-0000-0000-0000-000000000000" };
+
describe("KubernetesProvider — k8sHttpClient dispatch", () => {
beforeEach(() => {
for (const m of [safeGetMock, safePostMock, safeDeleteMock, rawGetMock, rawPostMock, rawDeleteMock]) {
@@ -100,7 +103,7 @@ describe("KubernetesProvider — k8sHttpClient dispatch", () => {
gatewayV2Service: { getPlatformConnectionDetailsByGatewayId: vi.fn() } as any
});
- await provider.validateConnection({ ...STATIC_INPUT_BASE });
+ await provider.validateConnection({ ...STATIC_INPUT_BASE }, VALIDATE_METADATA);
expect(safeGetMock).toHaveBeenCalledTimes(1);
expect(rawGetMock).not.toHaveBeenCalled();
@@ -123,10 +126,13 @@ describe("KubernetesProvider — k8sHttpClient dispatch", () => {
} as any
});
- await provider.validateConnection({
- ...STATIC_INPUT_BASE,
- gatewayId: "gw-k8s"
- });
+ await provider.validateConnection(
+ {
+ ...STATIC_INPUT_BASE,
+ gatewayId: "gw-k8s"
+ },
+ VALIDATE_METADATA
+ );
expect(rawGetMock).toHaveBeenCalledTimes(1);
expect(safeGetMock).not.toHaveBeenCalled();
@@ -147,11 +153,14 @@ describe("KubernetesProvider — k8sHttpClient dispatch", () => {
gatewayV2Service: { getPlatformConnectionDetailsByGatewayId: vi.fn() } as any
});
- await provider.validateConnection({
- ...STATIC_INPUT_BASE,
- sslEnabled: false,
- ca: undefined
- });
+ await provider.validateConnection(
+ {
+ ...STATIC_INPUT_BASE,
+ sslEnabled: false,
+ ca: undefined
+ },
+ VALIDATE_METADATA
+ );
expect(safeGetMock).toHaveBeenCalledTimes(1);
const [, opts] = safeGetMock.mock.calls[0];
diff --git a/backend/src/services/app-connection/github/github-connection-fns.test.ts b/backend/src/services/app-connection/github/github-connection-fns.test.ts
index 95726c1dac..4024c2d78e 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.test.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.test.ts
@@ -15,8 +15,8 @@ const { safeRequestMock, httpRequestMock, withGatewayProxyMock, withGatewayV2Pro
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
httpRequestMock:
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
- // withGatewayProxy({ callback }, options) -> invoke callback(1234) and return its result
- withGatewayProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(1234)),
+ // withGatewayProxy(cb, options) -> invoke cb(1234); track only cb on the spy (see vi.mock wrappers)
+ withGatewayProxyMock: vi.fn(async (cb: (port: number, httpsAgent?: unknown) => Promise<unknown>) => cb(1234)),
withGatewayV2ProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(5678)),
verifyHostInputValidityMock: vi.fn(async ({ host }: { host: string }) => [host] as string[])
}));
@@ -40,11 +40,17 @@ vi.mock("@app/lib/config/request", () => ({
vi.mock("@app/lib/gateway", () => ({
GatewayProxyProtocol: { Tcp: "tcp", Http: "http" },
- withGatewayProxy: (cb: (port: number) => Promise<unknown>, options: unknown) => withGatewayProxyMock(cb, options)
+ withGatewayProxy: (cb: (port: number, httpsAgent?: unknown) => Promise<unknown>, options: unknown) => {
+ void options;
+ return withGatewayProxyMock(cb);
+ }
}));
vi.mock("@app/lib/gateway-v2/gateway-v2", () => ({
- withGatewayV2Proxy: (cb: (port: number) => Promise<unknown>, options: unknown) => withGatewayV2ProxyMock(cb, options)
+ withGatewayV2Proxy: (cb: (port: number) => Promise<unknown>, options: unknown) => {
+ void options;
+ return withGatewayV2ProxyMock(cb);
+ }
}));
vi.mock("@app/ee/services/dynamic-secret/dynamic-secret-fns", () => ({
diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts
index dd15c5c461..c8809fedce 100644
--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts
+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts
@@ -16,8 +16,14 @@ const { safeRequestMock, httpRequestMock, withGatewayProxyMock, withGatewayV2Pro
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
httpRequestMock:
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
- withGatewayProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(1234)),
- withGatewayV2ProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(5678)),
+ withGatewayProxyMock: vi.fn(async (...args: any[]) => {
+ const cb = args[0] as (port: number, httpsAgent?: unknown) => Promise<unknown>;
+ return cb(1234);
+ }),
+ withGatewayV2ProxyMock: vi.fn(async (...args: any[]) => {
+ const cb = args[0] as (port: number) => Promise<unknown>;
+ return cb(5678);
+ }),
verifyHostInputValidityMock: vi.fn(async ({ host }: { host: string }) => [host] as string[])
}));
diff --git a/backend/src/services/app-connection/netscaler/netscaler-connection-fns.test.ts b/backend/src/services/app-connection/netscaler/netscaler-connection-fns.test.ts
index 10859cc5b1..e8129e6eed 100644
--- a/backend/src/services/app-connection/netscaler/netscaler-connection-fns.test.ts
+++ b/backend/src/services/app-connection/netscaler/netscaler-connection-fns.test.ts
@@ -15,7 +15,10 @@ const { safeRequestMock, httpRequestMock, withGatewayV2ProxyMock } = vi.hoisted(
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
httpRequestMock:
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
- withGatewayV2ProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(5678))
+ withGatewayV2ProxyMock: vi.fn(async (...args: any[]) => {
+ const cb = args[0] as (port: number) => Promise<unknown>;
+ return cb(5678);
+ })
}));
vi.mock("@app/lib/validator", () => ({
diff --git a/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.test.ts b/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.test.ts
index be6282212f..6deeedc09e 100644
--- a/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.test.ts
+++ b/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.test.ts
@@ -13,7 +13,10 @@ const { safeRequestMock, httpRequestMock, withGatewayV2ProxyMock, verifyHostInpu
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
httpRequestMock:
vi.fn<(...args: any[]) => Promise<{ data: unknown; status: number; headers: Record<string, unknown> }>>(),
- withGatewayV2ProxyMock: vi.fn(async (cb: (port: number) => Promise<unknown>) => cb(5678)),
+ withGatewayV2ProxyMock: vi.fn(async (...args: any[]) => {
+ const cb = args[0] as (port: number) => Promise<unknown>;
+ return cb(5678);
+ }),
verifyHostInputValidityMock: vi.fn(async ({ host }: { host: string }) => [host] as string[])
}));