Deprecate legacyHttpParser, fix rest tests
This commit is contained in:
parent
6e083c85a4
commit
c7dac5f417
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
|
@ -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")
|
||||||
|
@ -256,7 +255,7 @@ describe("REST Integration", () => {
|
||||||
authConfigId: "c59c14bd1898a43baa08da68959b24686",
|
authConfigId: "c59c14bd1898a43baa08da68959b24686",
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Basic dXNlcjpwYXNzd29yZA==",
|
Authorization: "Basic dXNlcjpwYXNzd29yZA==",
|
||||||
|
@ -269,7 +268,7 @@ describe("REST Integration", () => {
|
||||||
authConfigId: "0d91d732f34e4befabeff50b392a8ff3",
|
authConfigId: "0d91d732f34e4befabeff50b392a8ff3",
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer mytoken",
|
Authorization: "Bearer mytoken",
|
||||||
|
@ -327,7 +326,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
await config.integration.create(query)
|
await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
[pageParam]: pageValue,
|
[pageParam]: pageValue,
|
||||||
[sizeParam]: sizeValue,
|
[sizeParam]: sizeValue,
|
||||||
|
@ -359,7 +358,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
await config.integration.create(query)
|
await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: expect.any(FormData),
|
body: expect.any(FormData),
|
||||||
headers: {},
|
headers: {},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -390,7 +389,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
await config.integration.create(query)
|
await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: expect.any(URLSearchParams),
|
body: expect.any(URLSearchParams),
|
||||||
headers: {},
|
headers: {},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -456,7 +455,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const res = await config.integration.create(query)
|
const res = await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
[pageParam]: pageValue,
|
[pageParam]: pageValue,
|
||||||
[sizeParam]: sizeValue,
|
[sizeParam]: sizeValue,
|
||||||
|
@ -490,7 +489,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const res = await config.integration.create(query)
|
const res = await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: expect.any(FormData),
|
body: expect.any(FormData),
|
||||||
headers: {},
|
headers: {},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -523,7 +522,7 @@ describe("REST Integration", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const res = await config.integration.create(query)
|
const res = await config.integration.create(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
|
||||||
body: expect.any(URLSearchParams),
|
body: expect.any(URLSearchParams),
|
||||||
headers: {},
|
headers: {},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -563,7 +562,7 @@ describe("REST Integration", () => {
|
||||||
legacyHttpParser: true,
|
legacyHttpParser: true,
|
||||||
})
|
})
|
||||||
await config.integration.read({})
|
await config.integration.read({})
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {},
|
headers: {},
|
||||||
extraHttpOptions: {
|
extraHttpOptions: {
|
||||||
|
@ -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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue