diff --git a/packages/insomnia/src/common/__fixtures__/curl/complex-input-xml.sh b/packages/insomnia/src/common/__fixtures__/curl/complex-input-xml.sh new file mode 100755 index 000000000..6c7aba259 --- /dev/null +++ b/packages/insomnia/src/common/__fixtures__/curl/complex-input-xml.sh @@ -0,0 +1,12 @@ +curl \ + --request POST \ + -i \ + --url http://localhost:8000/api/v1/send \ + --header 'x-custom-header :foo bar' \ + --header 'content-type: application/xml' \ + --header 'Cookie: foo=bar' \ + --user 'My User:My:Secret:Password' \ + --cookie NID=91=iOf1sU9Ovlns9Dzn2Ipz05syr2K4AlZ4Kgp84eRVLf3_6DgcNrkqpWg4lfUvCB5cNxD26t \ + -H 'another-header: foo' \ + --data 'HELLO'; + diff --git a/packages/insomnia/src/common/__tests__/import.test.ts b/packages/insomnia/src/common/__tests__/import.test.ts index 90feccde6..4aec26813 100644 --- a/packages/insomnia/src/common/__tests__/import.test.ts +++ b/packages/insomnia/src/common/__tests__/import.test.ts @@ -95,6 +95,35 @@ describe('importRaw()', () => { }); }); + it('should import a curl request to an existing workspace with an XML body', async () => { + const fixturePath = path.join(__dirname, '..', '__fixtures__', 'curl', 'complex-input-xml.sh'); + const content = fs.readFileSync(fixturePath, 'utf8').toString(); + + const existingWorkspace = await workspace.create(); + + const scanResult = await importUtil.scanResources({ + content, + }); + + expect(scanResult.type?.id).toBe('curl'); + expect(scanResult.errors.length).toBe(0); + + await importUtil.importResourcesToWorkspace({ + workspaceId: existingWorkspace._id, + }); + + const workspacesCount = await workspace.count(); + expect(workspacesCount).toBe(1); + + const curlRequests = await request.findByParentId(existingWorkspace._id); + + expect(curlRequests[0]).toMatchObject({ + body: { + "text": "HELLO", + }, + }); + }); + it('should import a postman collection to a new workspace', async () => { const fixturePath = path.join(__dirname, '..', '__fixtures__', 'postman', 'aws-signature-auth-v2_0-input.json'); const content = fs.readFileSync(fixturePath, 'utf8').toString(); diff --git a/packages/insomnia/src/common/import.ts b/packages/insomnia/src/common/import.ts index 1abfb69d8..bd34773b9 100644 --- a/packages/insomnia/src/common/import.ts +++ b/packages/insomnia/src/common/import.ts @@ -147,7 +147,6 @@ export async function scanResources({ export const importPure = async (json: { resources: BaseModel[] } & any) => { const _resources = json.resources; - // console.log("importPure", json); return await importResourcesToProject({ _resources }); }; diff --git a/packages/insomnia/src/utils/importers/importers/curl.ts b/packages/insomnia/src/utils/importers/importers/curl.ts index 28ac3eae8..6ed2b069d 100644 --- a/packages/insomnia/src/utils/importers/importers/curl.ts +++ b/packages/insomnia/src/utils/importers/importers/curl.ts @@ -102,7 +102,7 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => { })); url = href.replace(search, '').replace(/\/$/, ''); - } catch (error) {} + } catch (error) { } /// /////// Authentication ////////// const [username, password] = getPairValue(pairsByName, '', [ @@ -208,6 +208,9 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => { value: decodeURIComponent(parameter.value || ''), }; }); + } else if (dataParameters && mimeType === 'application/xml') { + body.text = dataParameters.map(parameter => `${parameter.name}=${parameter.value}`).join('&'); + body.mimeType = mimeType || ''; } else if (dataParameters.length !== 0) { body.text = dataParameters.map(parameter => `${parameter.name}${parameter.value}`).join('&'); body.mimeType = mimeType || '';