From 6bc0ffc9302925452be134a1baaea0d0867f81a0 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Mon, 12 Aug 2024 20:42:04 +0200 Subject: [PATCH] [Beeep] [PM-10767] Improve username importing on protonpass importer (#10471) * Improve username importing on protonpass importer * Conditionally write proton importer custom fields --- libs/importer/spec/protonpass-json-importer.spec.ts | 4 ++-- .../spec/test-data/protonpass-json/protonpass.json.ts | 4 ++-- .../importers/protonpass/protonpass-json-importer.ts | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libs/importer/spec/protonpass-json-importer.spec.ts b/libs/importer/spec/protonpass-json-importer.spec.ts index 5f6bc4fd68..f58e4d5f25 100644 --- a/libs/importer/spec/protonpass-json-importer.spec.ts +++ b/libs/importer/spec/protonpass-json-importer.spec.ts @@ -31,8 +31,8 @@ describe("Protonpass Json Importer", () => { expect(uriView.uri).toEqual("https://example.com/"); expect(cipher.notes).toEqual("My login secure note."); - expect(cipher.fields.at(0).name).toEqual("itemUsername"); - expect(cipher.fields.at(0).value).toEqual("someOtherUsername"); + expect(cipher.fields.at(0).name).toEqual("email"); + expect(cipher.fields.at(0).value).toEqual("Email"); expect(cipher.fields.at(3).name).toEqual("second 2fa secret"); expect(cipher.fields.at(3).value).toEqual("TOTPCODE"); 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 55c2a9109e..b421403166 100644 --- a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts +++ b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts @@ -49,12 +49,12 @@ export const testData: ProtonPassJsonFile = { ], type: "login", content: { - itemEmail: "Username", + itemEmail: "Email", 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", + itemUsername: "Username", }, }, 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 229e508db5..b680f0a387 100644 --- a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts +++ b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts @@ -48,10 +48,17 @@ 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.itemEmail); + + cipher.login.username = this.getValueOrDefault(loginContent.itemUsername); + // if the cipher has no username then the email is used as the username + if (cipher.login.username == null) { + cipher.login.username = this.getValueOrDefault(loginContent.itemEmail); + } else { + this.processKvp(cipher, "email", 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,