From 83a32cd179795e9cd0fb0651a58aac3fbe98ee3e Mon Sep 17 00:00:00 2001 From: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:45:02 +0200 Subject: [PATCH] [PM-9318] Fix username on protonpass import (#9889) * Fix username field used for ProtonPass import ProtonPass has changed their export format and userName is not itemEmail * Import additional field itemUsername --------- Co-authored-by: Daniel James Smith --- libs/importer/spec/protonpass-json-importer.spec.ts | 9 ++++++--- .../spec/test-data/protonpass-json/protonpass.json.ts | 6 ++++-- .../src/importers/protonpass/protonpass-json-importer.ts | 3 ++- .../importers/protonpass/types/protonpass-json-type.ts | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/importer/spec/protonpass-json-importer.spec.ts b/libs/importer/spec/protonpass-json-importer.spec.ts index c6f8fb4838..5f6bc4fd68 100644 --- a/libs/importer/spec/protonpass-json-importer.spec.ts +++ b/libs/importer/spec/protonpass-json-importer.spec.ts @@ -31,9 +31,12 @@ describe("Protonpass Json Importer", () => { expect(uriView.uri).toEqual("https://example.com/"); expect(cipher.notes).toEqual("My login secure note."); - expect(cipher.fields.at(2).name).toEqual("second 2fa secret"); - expect(cipher.fields.at(2).value).toEqual("TOTPCODE"); - expect(cipher.fields.at(2).type).toEqual(FieldType.Hidden); + expect(cipher.fields.at(0).name).toEqual("itemUsername"); + expect(cipher.fields.at(0).value).toEqual("someOtherUsername"); + + expect(cipher.fields.at(3).name).toEqual("second 2fa secret"); + expect(cipher.fields.at(3).value).toEqual("TOTPCODE"); + expect(cipher.fields.at(3).type).toEqual(FieldType.Hidden); }); it("should parse note data", async () => { diff --git a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts index 6b6b2e91f6..55c2a9109e 100644 --- a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts +++ b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts @@ -49,11 +49,12 @@ export const testData: ProtonPassJsonFile = { ], type: "login", content: { - username: "Username", + itemEmail: "Username", password: "Password", urls: ["https://example.com/", "https://example2.com/"], totpUri: "otpauth://totp/Test%20Login%20-%20Personal%20Vault:Username?issuer=Test%20Login%20-%20Personal%20Vault&secret=TOTPCODE&algorithm=SHA1&digits=6&period=30", + itemUsername: "someOtherUsername", }, }, state: 1, @@ -156,10 +157,11 @@ export const testData: ProtonPassJsonFile = { extraFields: [], type: "login", content: { - username: "other vault username", + itemEmail: "other vault username", password: "other vault password", urls: [], totpUri: "JBSWY3DPEHPK3PXP", + itemUsername: "", }, }, state: 1, diff --git a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts index 22de8c7447..229e508db5 100644 --- a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts +++ b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts @@ -48,9 +48,10 @@ export class ProtonPassJsonImporter extends BaseImporter implements Importer { case "login": { const loginContent = item.data.content as ProtonPassLoginItemContent; cipher.login.uris = this.makeUriArray(loginContent.urls); - cipher.login.username = this.getValueOrDefault(loginContent.username); + cipher.login.username = this.getValueOrDefault(loginContent.itemEmail); cipher.login.password = this.getValueOrDefault(loginContent.password); cipher.login.totp = this.getValueOrDefault(loginContent.totpUri); + this.processKvp(cipher, "itemUsername", loginContent.itemUsername); for (const extraField of item.data.extraFields) { this.processKvp( cipher, diff --git a/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts b/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts index 27b38f434e..4c082a93cf 100644 --- a/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts +++ b/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts @@ -56,10 +56,11 @@ export type ProtonPassItemExtraFieldData = { }; export type ProtonPassLoginItemContent = { - username?: string; + itemEmail?: string; password?: string; urls?: string[]; totpUri?: string; + itemUsername?: string; }; export type ProtonPassCreditCardItemContent = {