fix(common): handle non-string values in Postman collection import (#6137)
Co-authored-by: atharvasingh7007 <singhatharva7007@gmail.com> Co-authored-by: XHamzaX <hamzaswitch1221@gmail.com> Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
76329eaf31
commit
174c87d5d3
2 changed files with 64 additions and 4 deletions
|
|
@ -0,0 +1,60 @@
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
|
import { describe, expect, it } from "vitest"
|
||||||
|
|
||||||
|
import { hoppPostmanImporter } from "../import-export/import/postman"
|
||||||
|
|
||||||
|
const postmanCollectionWithArrayHeader = JSON.stringify({
|
||||||
|
info: {
|
||||||
|
name: "Array Header Import",
|
||||||
|
schema:
|
||||||
|
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||||
|
},
|
||||||
|
item: [
|
||||||
|
{
|
||||||
|
name: "Import Array Header",
|
||||||
|
request: {
|
||||||
|
method: "GET",
|
||||||
|
header: [
|
||||||
|
{
|
||||||
|
key: "Authorization",
|
||||||
|
value: ["Basic xxxxx", "Basic xxxxxxxxxxxx="],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "Content-Type",
|
||||||
|
value: "application/x-www-form-urlencoded",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
url: "https://echo.hoppscotch.io/get",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("Postman importer", () => {
|
||||||
|
it("coerces array header values instead of crashing during import", async () => {
|
||||||
|
const result = await hoppPostmanImporter([
|
||||||
|
postmanCollectionWithArrayHeader,
|
||||||
|
])()
|
||||||
|
|
||||||
|
expect(E.isRight(result)).toBe(true)
|
||||||
|
|
||||||
|
if (E.isLeft(result)) {
|
||||||
|
throw new Error("Expected Postman import to succeed")
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result.right[0].requests[0].headers).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
key: "Authorization",
|
||||||
|
value: "Basic xxxxx,Basic xxxxxxxxxxxx=",
|
||||||
|
active: true,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
key: "Content-Type",
|
||||||
|
value: "application/x-www-form-urlencoded",
|
||||||
|
active: true,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -63,10 +63,10 @@ const getCollectionSchema = (jsonStr: string): string | null => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const replacePMVarTemplating = flow(
|
export const replacePMVarTemplating = (value: unknown): string => {
|
||||||
S.replace(/{{\s*/g, "<<"),
|
const str = typeof value === "string" ? value : String(value ?? "")
|
||||||
S.replace(/\s*}}/g, ">>")
|
return pipe(str, S.replace(/{{\s*/g, "<<"), S.replace(/\s*}}/g, ">>"))
|
||||||
)
|
}
|
||||||
|
|
||||||
const PMRawLanguageOptionsToContentTypeMap: Record<
|
const PMRawLanguageOptionsToContentTypeMap: Record<
|
||||||
PMRawLanguage,
|
PMRawLanguage,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue