[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>
This commit is contained in:
Bernd Schoolmann 2023-10-31 18:37:35 +01:00 committed by GitHub
parent 91e7a45ee4
commit 77ee09540e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View File

@ -159,7 +159,7 @@ export const testData: ProtonPassJsonFile = {
username: "other vault username",
password: "other vault password",
urls: [],
totpUri: "",
totpUri: "JBSWY3DPEHPK3PXP",
},
},
state: 1,

View File

@ -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);