1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

Merge pull request #8227

Deprecate legacyHttpParser, fix rest tests
This commit is contained in:
Rory Powell 2022-10-12 19:56:02 +01:00 committed by GitHub
commit 163c8127fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 19 deletions

View file

@ -56,6 +56,7 @@ const _import = async (ctx: any) => {
config: { config: {
url: info.url, url: info.url,
defaultHeaders: [], defaultHeaders: [],
rejectUnauthorized: true,
}, },
name: info.name, name: info.name,
} }

View file

@ -78,16 +78,11 @@ const SCHEMA: Integration = {
default: {}, default: {},
}, },
rejectUnauthorized: { rejectUnauthorized: {
display: "Reject Unauthorized",
type: DatasourceFieldType.BOOLEAN, type: DatasourceFieldType.BOOLEAN,
default: true, default: true,
required: false, required: false,
}, },
legacyHttpParser: {
display: "Legacy HTTP Support",
type: DatasourceFieldType.BOOLEAN,
required: false,
default: false,
},
}, },
query: { query: {
create: { create: {
@ -397,6 +392,7 @@ class RestIntegration implements IntegrationBase {
}) })
} }
// Deprecated by rejectUnauthorized
if (this.config.legacyHttpParser) { if (this.config.legacyHttpParser) {
// https://github.com/nodejs/node/issues/43798 // https://github.com/nodejs/node/issues/43798
input.extraHttpOptions = { insecureHTTPParser: true } input.extraHttpOptions = { insecureHTTPParser: true }

View file

@ -1,17 +1,16 @@
jest.mock("node-fetch", () => const mockFetch = jest.fn(() => ({
jest.fn(() => ({ headers: {
headers: { raw: () => {
raw: () => { return { "content-type": ["application/json"] }
return { "content-type": ["application/json"] }
},
get: () => ["application/json"],
}, },
json: jest.fn(() => ({ get: () => ["application/json"],
my_next_cursor: 123, },
})), json: jest.fn(() => ({
text: jest.fn(), my_next_cursor: 123,
})) })),
) text: jest.fn(),
}))
jest.mock("node-fetch", () => mockFetch)
import fetch from "node-fetch" import fetch from "node-fetch"
import { default as RestIntegration } from "../rest" import { default as RestIntegration } from "../rest"
const FormData = require("form-data") 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)
})
}) })