Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Copy Markdown
Contributor Author

@jffhll jffhll Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug line so so lets just remove it.

return await importResourcesToProject({ _resources });
};

Expand Down
56 changes: 28 additions & 28 deletions packages/insomnia/src/ui/components/modals/import-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ const HoppscotchIcon = (props: React.SVGProps<SVGSVGElement>) => {
/>
<path
fill="currentColor"
fill-rule="evenodd"
fillRule="evenodd"
d="M15.632 4.776a8.894 8.894 0 0 1 5.29 7.937c1.867 1.47 3.723 3.528 2.86 5.466-.968 2.174-4.415 2.085-8.334.985A7.113 7.113 0 0 1 5.063 14.54C1.623 12.364-.75 9.862.218 7.688c.863-1.94 3.634-1.937 5.975-1.532a8.894 8.894 0 0 1 9.439-1.38ZM1.862 8.42c-.47 1.056 2.056 4.053 8.972 7.133 6.916 3.079 10.834 2.95 11.304 1.894.39-.874-1.212-2.554-3.046-3.856-1.426-1.02-3.38-2.144-5.929-3.278-.694-.31-.964-1.134-.673-1.789.292-.655.933-1.093 2.282-1.155.635-.002.718-.178.747-.33.036-.232-.287-.47-.62-.618-2.647-1.178-5.888-.684-8.134 1.681-2.195-.491-4.514-.557-4.903.318Z"
clip-rule="evenodd"
clipRule="evenodd"
/>
<path
fill="currentColor"
fill-rule="evenodd"
fillRule="evenodd"
d="M15.632 4.776a8.894 8.894 0 0 1 5.29 7.937c1.867 1.47 3.723 3.528 2.86 5.466-.968 2.174-4.415 2.085-8.334.985A7.113 7.113 0 0 1 5.063 14.54C1.623 12.364-.75 9.862.218 7.688c.863-1.94 3.634-1.937 5.975-1.532a8.894 8.894 0 0 1 9.439-1.38ZM1.862 8.42c-.47 1.056 2.056 4.053 8.972 7.133 6.916 3.079 10.834 2.95 11.304 1.894.39-.874-1.212-2.554-3.046-3.856-1.426-1.02-3.38-2.144-5.929-3.278-.694-.31-.964-1.134-.673-1.789.292-.655.933-1.093 2.282-1.155.635-.002.718-.178.747-.33.036-.232-.287-.47-.62-.618-2.647-1.178-5.888-.684-8.134 1.681-2.195-.491-4.514-.557-4.903.318Z"
clip-rule="evenodd"
clipRule="evenodd"
/>
</svg>
);
Expand Down Expand Up @@ -815,32 +815,32 @@ const ImportResourcesForm = ({
)}
{scanResult.environments &&
scanResult.environments.length > 0 && (
<tr className="table--no-outline-row">
<td>
{scanResult.environments.length}{' '}
{scanResult.environments.length === 1
? 'Environment'
: 'Environments'}
{' with '}
{scanResult.cookieJars?.length}{' '}
{scanResult.cookieJars?.length === 1 ? 'Cookie Jar' : 'Cookie Jars'}
</td>
</tr>
)}
<tr className="table--no-outline-row">
<td>
{scanResult.environments.length}{' '}
{scanResult.environments.length === 1
? 'Environment'
: 'Environments'}
{' with '}
{scanResult.cookieJars?.length}{' '}
{scanResult.cookieJars?.length === 1 ? 'Cookie Jar' : 'Cookie Jars'}
</td>
</tr>
)}
{scanResult.unitTestSuites &&
scanResult.unitTestSuites?.length > 0 && (
<tr className="table--no-outline-row">
<td>
{scanResult.unitTestSuites.length}{' '}
{scanResult.unitTestSuites.length === 1
? 'Test Suite'
: 'Test Suites'}
{' with '}
{scanResult.unitTests?.length}
{scanResult.unitTests?.length === 1 ? ' Test' : ' Tests'}
</td>
</tr>
)}
<tr className="table--no-outline-row">
<td>
{scanResult.unitTestSuites.length}{' '}
{scanResult.unitTestSuites.length === 1
? 'Test Suite'
: 'Test Suites'}
{' with '}
{scanResult.unitTests?.length}
{scanResult.unitTests?.length === 1 ? ' Test' : ' Tests'}
</td>
</tr>
)}
</tbody>
</table>
</div>
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