diff --git a/plugins/importer-postman/src/index.ts b/plugins/importer-postman/src/index.ts index 9f05859f..3c720108 100644 --- a/plugins/importer-postman/src/index.ts +++ b/plugins/importer-postman/src/index.ts @@ -16,6 +16,20 @@ const POSTMAN_2_1_0_SCHEMA = "https://schema.getpostman.com/json/collection/v2.1 const POSTMAN_2_0_0_SCHEMA = "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"; const VALID_SCHEMAS = [POSTMAN_2_0_0_SCHEMA, POSTMAN_2_1_0_SCHEMA]; +// Both products happen to spell these the same way, but the names are written +// out so anything Yaak's oauth1 plugin can't offer as a select option lands on +// the default instead of being passed straight through. +const OAUTH1_SIGNATURE_METHODS: Record = { + "HMAC-SHA1": "HMAC-SHA1", + "HMAC-SHA256": "HMAC-SHA256", + "HMAC-SHA512": "HMAC-SHA512", + "RSA-SHA1": "RSA-SHA1", + "RSA-SHA256": "RSA-SHA256", + "RSA-SHA512": "RSA-SHA512", + PLAINTEXT: "PLAINTEXT", +}; +const DEFAULT_OAUTH1_SIGNATURE_METHOD = "HMAC-SHA1"; + type AtLeast = Partial & Pick; interface ExportResources { @@ -98,6 +112,7 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin id: generateId("folder"), name: v.name, folderId, + ...importAuth(v.auth), }; trackSourceKey(folder.id, v, "item"); exportResources.folders.push(folder); @@ -222,8 +237,6 @@ function convertUrl(rawUrl: unknown): Pick v += `#${url.hash}`; } - // TODO: Implement url.variables (path variables) - return { url: v, urlParameters: params }; } @@ -274,6 +287,31 @@ function importAuth(rawAuth: unknown): Pick { expect(keyOf(before, before?.resources.workspaces[0]?.id)).toBe("collection:collection-id"); }); + test("Falls back to the default OAuth 1 signature method for unrecognized ones", () => { + const result = convertPostman( + JSON.stringify({ + info: { + name: "OAuth 1 Signature", + schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + }, + item: [ + { + name: "Request", + request: { + method: "GET", + url: "https://yaak.app", + auth: { + type: "oauth1", + oauth1: [{ key: "signatureMethod", value: "HMAC-SHA384" }], + }, + }, + }, + ], + }), + ); + + expect(result?.resources.httpRequests).toEqual([ + expect.objectContaining({ + authenticationType: "oauth1", + authentication: { signatureMethod: "HMAC-SHA1" }, + }), + ]); + }); + test("Omits keys for items the collection never identified", () => { const result = convertPostman( JSON.stringify({