From 77ee09540ed1bac931c37c4ef3faccf72ac983b2 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Tue, 31 Oct 2023 18:37:35 +0100 Subject: [PATCH] [PM-4163] Fix protonpass importer when totp field is not a URL (#6474) * Fix protonpass importer when totp field is not a URL * Simplify ProtonPass importer totp handling * Use getValueOrDefault for totp import in ProtonPass importer * Use getValueOrDefault for other ProtonPass importer fields --------- Co-authored-by: ttalty <144813356+ttalty@users.noreply.github.com> --- .../protonpass-json/protonpass.json.ts | 2 +- .../protonpass/protonpass-json-importer.ts | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) 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 4217ddd4d5..6b6b2e91f6 100644 --- a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts +++ b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts @@ -159,7 +159,7 @@ export const testData: ProtonPassJsonFile = { username: "other vault username", password: "other vault password", urls: [], - totpUri: "", + totpUri: "JBSWY3DPEHPK3PXP", }, }, 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 86f4444ec4..c161630be5 100644 --- a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts +++ b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts @@ -42,18 +42,16 @@ export class ProtonPassJsonImporter extends BaseImporter implements Importer { this.processFolder(result, vault.name); const cipher = this.initLoginCipher(); - cipher.name = item.data.metadata.name; - cipher.notes = item.data.metadata.note; + cipher.name = this.getValueOrDefault(item.data.metadata.name, "--"); + cipher.notes = this.getValueOrDefault(item.data.metadata.note); switch (item.data.type) { case "login": { const loginContent = item.data.content as ProtonPassLoginItemContent; cipher.login.uris = this.makeUriArray(loginContent.urls); - cipher.login.username = loginContent.username; - cipher.login.password = loginContent.password; - if (loginContent.totpUri != "") { - cipher.login.totp = new URL(loginContent.totpUri).searchParams.get("secret"); - } + cipher.login.username = this.getValueOrDefault(loginContent.username); + cipher.login.password = this.getValueOrDefault(loginContent.password); + cipher.login.totp = this.getValueOrDefault(loginContent.totpUri); for (const extraField of item.data.extraFields) { this.processKvp( cipher, @@ -73,10 +71,10 @@ export class ProtonPassJsonImporter extends BaseImporter implements Importer { const creditCardContent = item.data.content as ProtonPassCreditCardItemContent; cipher.type = CipherType.Card; cipher.card = new CardView(); - cipher.card.cardholderName = creditCardContent.cardholderName; - cipher.card.number = creditCardContent.number; + cipher.card.cardholderName = this.getValueOrDefault(creditCardContent.cardholderName); + cipher.card.number = this.getValueOrDefault(creditCardContent.number); cipher.card.brand = CardView.getCardBrandByPatterns(creditCardContent.number); - cipher.card.code = creditCardContent.verificationNumber; + cipher.card.code = this.getValueOrDefault(creditCardContent.verificationNumber); if (!this.isNullOrWhitespace(creditCardContent.expirationDate)) { cipher.card.expMonth = creditCardContent.expirationDate.substring(0, 2);