diff --git a/packages/server/src/api/controllers/query/index.ts b/packages/server/src/api/controllers/query/index.ts index 5c09a2f3b6..c92f942986 100644 --- a/packages/server/src/api/controllers/query/index.ts +++ b/packages/server/src/api/controllers/query/index.ts @@ -56,6 +56,7 @@ const _import = async (ctx: any) => { config: { url: info.url, defaultHeaders: [], + rejectUnauthorized: true, }, name: info.name, } diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 71294b9cb0..08d2337593 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -78,16 +78,11 @@ const SCHEMA: Integration = { default: {}, }, rejectUnauthorized: { + display: "Reject Unauthorized", type: DatasourceFieldType.BOOLEAN, default: true, required: false, }, - legacyHttpParser: { - display: "Legacy HTTP Support", - type: DatasourceFieldType.BOOLEAN, - required: false, - default: false, - }, }, query: { create: { @@ -397,6 +392,7 @@ class RestIntegration implements IntegrationBase { }) } + // Deprecated by rejectUnauthorized if (this.config.legacyHttpParser) { // https://github.com/nodejs/node/issues/43798 input.extraHttpOptions = { insecureHTTPParser: true } diff --git a/packages/server/src/integrations/tests/rest.spec.ts b/packages/server/src/integrations/tests/rest.spec.ts index d451282a86..d53f9c7ce3 100644 --- a/packages/server/src/integrations/tests/rest.spec.ts +++ b/packages/server/src/integrations/tests/rest.spec.ts @@ -1,17 +1,16 @@ -jest.mock("node-fetch", () => - jest.fn(() => ({ - headers: { - raw: () => { - return { "content-type": ["application/json"] } - }, - get: () => ["application/json"], +const mockFetch = jest.fn(() => ({ + headers: { + raw: () => { + return { "content-type": ["application/json"] } }, - json: jest.fn(() => ({ - my_next_cursor: 123, - })), - text: jest.fn(), - })) -) + get: () => ["application/json"], + }, + json: jest.fn(() => ({ + my_next_cursor: 123, + })), + text: jest.fn(), +})) +jest.mock("node-fetch", () => mockFetch) import fetch from "node-fetch" import { default as RestIntegration } from "../rest" const FormData = require("form-data") @@ -572,4 +571,21 @@ describe("REST Integration", () => { }) }) }) + + it("Attaches custom agent when Reject Unauthorized option is false", async () => { + config = new TestConfiguration({ + url: BASE_URL, + rejectUnauthorized: false, + }) + await config.integration.read({}) + + const calls: any = mockFetch.mock.calls[0] + const url = calls[0] + expect(url).toBe(`${BASE_URL}/`) + + const calledConfig = calls[1] + expect(calledConfig.method).toBe("GET") + expect(calledConfig.headers).toEqual({}) + expect(calledConfig.agent.options.rejectUnauthorized).toBe(false) + }) })