Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
[#152] Fix cURL/XML import missing '='
Browse files Browse the repository at this point in the history
  • Loading branch information
jffhll committed Feb 22, 2024
1 parent bcb22aa commit 63dd5bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 '<?xml version="1.0"?<test>HELLO</test>';

29 changes: 29 additions & 0 deletions packages/insomnia/src/common/__tests__/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<?xml version=\"1.0\"?<test>HELLO</test>",
},
});
});

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();
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/common/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};

Expand Down
5 changes: 4 additions & 1 deletion packages/insomnia/src/utils/importers/importers/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => {
}));

url = href.replace(search, '').replace(/\/$/, '');
} catch (error) {}
} catch (error) { }

/// /////// Authentication //////////
const [username, password] = getPairValue(pairsByName, '', [
Expand Down Expand Up @@ -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 || '';
Expand Down

0 comments on commit 63dd5bf

Please sign in to comment.