Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

test: deflake DNS-dependent CI tests (#13412)

Tobias Wochinger81e1ba312088
diff --git a/web/src/__tests__/server/llm-connections-api.servertest.ts b/web/src/__tests__/server/llm-connections-api.servertest.ts
index 8590f912dd..f6e2f5ceff 100644
--- a/web/src/__tests__/server/llm-connections-api.servertest.ts
+++ b/web/src/__tests__/server/llm-connections-api.servertest.ts
@@ -16,6 +16,14 @@ import { encrypt } from "@langfuse/shared/encryption";
const generateUniqueProvider = (baseName: string) =>
`${baseName}-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
+// Use public IP literals for happy-path baseURL tests so these API tests do
+// not depend on external DNS. DNS/SSRF behavior is covered by focused
+// baseUrlValidation tests.
+const TEST_PUBLIC_LLM_BASE_URL = "https://1.1.1.1/v1";
+const TEST_UPDATED_PUBLIC_LLM_BASE_URL = "https://1.1.1.1/v2";
+const TEST_CUSTOM_PUBLIC_LLM_BASE_URL = "https://1.1.1.1/custom/v1";
+const TEST_SCHEMA_PUBLIC_LLM_BASE_URL = "https://1.1.1.1/schema/v1";
+
const BEDROCK_AWS_CREDENTIALS = {
accessKeyId: "AKIAIOSFODNN7EXAMPLE",
secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
@@ -79,7 +87,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
adapter: LLMAdapter.OpenAI,
secretKey: encrypt("sk-test1"),
displaySecretKey: "...est1",
- baseURL: "https://api.openai.com/v1",
+ baseURL: TEST_PUBLIC_LLM_BASE_URL,
customModels: ["gpt-4", "gpt-3.5-turbo"],
withDefaultModels: true,
extraHeaders: encrypt(JSON.stringify({ "X-Custom": "header1" })),
@@ -136,7 +144,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
expect(secondConnection.provider).toBe(provider1);
expect(secondConnection.adapter).toBe(LLMAdapter.OpenAI);
expect(secondConnection.displaySecretKey).toBe("...est1");
- expect(secondConnection.baseURL).toBe("https://api.openai.com/v1");
+ expect(secondConnection.baseURL).toBe(TEST_PUBLIC_LLM_BASE_URL);
expect(secondConnection.customModels).toEqual(["gpt-4", "gpt-3.5-turbo"]);
expect(secondConnection.withDefaultModels).toBe(true);
expect(secondConnection.extraHeaderKeys).toEqual(["X-Custom"]);
@@ -302,7 +310,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
provider: generateUniqueProvider("openai"),
adapter: LLMAdapter.OpenAI,
secretKey: "sk-test123",
- baseURL: "https://api.openai.com/v1",
+ baseURL: TEST_PUBLIC_LLM_BASE_URL,
customModels: ["gpt-4", "gpt-3.5-turbo"],
withDefaultModels: true,
extraHeaders: {
@@ -323,7 +331,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
expect(response.body.provider).toBe(createData.provider);
expect(response.body.adapter).toBe(LLMAdapter.OpenAI);
expect(response.body.displaySecretKey).toBe("...t123");
- expect(response.body.baseURL).toBe("https://api.openai.com/v1");
+ expect(response.body.baseURL).toBe(TEST_PUBLIC_LLM_BASE_URL);
expect(response.body.customModels).toEqual(["gpt-4", "gpt-3.5-turbo"]);
expect(response.body.withDefaultModels).toBe(true);
expect(response.body.extraHeaderKeys).toEqual(["X-Custom"]);
@@ -403,7 +411,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
adapter: LLMAdapter.OpenAI,
secretKey: encrypt("sk-original"),
displaySecretKey: "...nal",
- baseURL: "https://original.com",
+ baseURL: TEST_PUBLIC_LLM_BASE_URL,
customModels: ["gpt-3.5"],
withDefaultModels: true,
},
@@ -414,7 +422,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
provider: existingProvider,
adapter: LLMAdapter.Anthropic, // Changed adapter
secretKey: "sk-updated",
- baseURL: "https://updated.com",
+ baseURL: TEST_UPDATED_PUBLIC_LLM_BASE_URL,
customModels: ["claude-3"],
withDefaultModels: false,
};
@@ -433,7 +441,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
expect(response.body.provider).toBe(existingProvider);
expect(response.body.adapter).toBe(LLMAdapter.Anthropic); // Updated
expect(response.body.displaySecretKey).toBe("...ated"); // Updated
- expect(response.body.baseURL).toBe("https://updated.com"); // Updated
+ expect(response.body.baseURL).toBe(TEST_UPDATED_PUBLIC_LLM_BASE_URL); // Updated
expect(response.body.customModels).toEqual(["claude-3"]); // Updated
expect(response.body.withDefaultModels).toBe(false); // Updated
});
@@ -634,7 +642,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
provider: generateUniqueProvider("full-test"),
adapter: LLMAdapter.OpenAI,
secretKey: "sk-full-test",
- baseURL: "https://custom.api.com/v1",
+ baseURL: TEST_CUSTOM_PUBLIC_LLM_BASE_URL,
customModels: ["custom-model-1", "custom-model-2"],
withDefaultModels: false,
extraHeaders: {
@@ -647,7 +655,9 @@ describe("/api/public/llm-connections API Endpoints", () => {
);
expect(fullDataResponse.status).toBe(201);
- expect(fullDataResponse.body.baseURL).toBe("https://custom.api.com/v1");
+ expect(fullDataResponse.body.baseURL).toBe(
+ TEST_CUSTOM_PUBLIC_LLM_BASE_URL,
+ );
expect(fullDataResponse.body.customModels).toEqual([
"custom-model-1",
"custom-model-2",
@@ -1539,7 +1549,7 @@ describe("/api/public/llm-connections API Endpoints", () => {
provider: generateUniqueProvider("schema-test"),
adapter: LLMAdapter.OpenAI,
secretKey: "sk-schema-test",
- baseURL: "https://api.example.com/v1",
+ baseURL: TEST_SCHEMA_PUBLIC_LLM_BASE_URL,
customModels: ["model-1", "model-2"],
withDefaultModels: true,
extraHeaders: { "X-Test": "value" },
diff --git a/worker/src/__tests__/webhook-validation.test.ts b/worker/src/__tests__/webhook-validation.test.ts
index e5a5e175e5..a4254b330c 100644
--- a/worker/src/__tests__/webhook-validation.test.ts
+++ b/worker/src/__tests__/webhook-validation.test.ts
@@ -1,5 +1,38 @@
-import { describe, it, expect } from "vitest";
-import { validateWebhookURL } from "@langfuse/shared/src/server";
+import { beforeEach, describe, it, expect, vi } from "vitest";
+
+const { resolve4Mock, resolve6Mock } = vi.hoisted(() => ({
+ resolve4Mock: vi.fn<(hostname: string) => Promise<string[]>>(),
+ resolve6Mock: vi.fn<(hostname: string) => Promise<string[]>>(),
+}));
+
+vi.mock("node:dns/promises", () => ({
+ default: {
+ resolve4: resolve4Mock,
+ resolve6: resolve6Mock,
+ },
+ resolve4: resolve4Mock,
+ resolve6: resolve6Mock,
+}));
+
+import { validateWebhookURL } from "../../../packages/shared/src/server/webhooks/validation";
+
+const nonexistentDomain = "this-domain-definitely-does-not-exist-12345.com";
+
+const dnsError = (code: string, hostname: string) =>
+ Object.assign(new Error(`queryA ${code} ${hostname}`), { code });
+
+beforeEach(() => {
+ vi.clearAllMocks();
+
+ resolve4Mock.mockImplementation(async (hostname: string) => {
+ if (hostname === nonexistentDomain) {
+ throw dnsError("ENOTFOUND", hostname);
+ }
+
+ return ["93.184.216.34"];
+ });
+ resolve6Mock.mockRejectedValue(dnsError("ENODATA", "mocked-hostname"));
+});
describe("Webhook URL Validation", () => {
describe("validateWebhookURL", () => {
@@ -109,10 +142,10 @@ describe("Webhook URL Validation", () => {
it("should handle DNS resolution failures gracefully", async () => {
await expect(
- validateWebhookURL(
- "https://this-domain-definitely-does-not-exist-12345.com/hook",
- ),
+ validateWebhookURL(`https://${nonexistentDomain}/hook`),
).rejects.toThrow("DNS lookup failed");
+ expect(resolve4Mock).toHaveBeenCalledWith(nonexistentDomain);
+ expect(resolve6Mock).toHaveBeenCalledWith(nonexistentDomain);
});
it("should reject URL-encoded localhost bypass attempts", async () => {