1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

[PM-10814] Fix nordpass importer (#10491)

* import additional_urls from nordpass csv

* use type column of nordpass csv to get type of record

* fixed wrong naming of nordpass csv type

* impot custom fields from nordpass csv

* fix parse nordpass custom_fields

* fixed parsing of additional_urls in nordpass import

* update nordpass csv importer tests

* Capitalize type names

* Add test for OrgImport/CollectionCreation and fix Org-import

* Add test to verify success equals false when parsing fails.

* use "Text" as default FieldType of nordpass custom fields

* implemented seperated test for additional fields

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Florian Lang
2024-08-20 12:39:34 +02:00
committed by GitHub
parent 3a31eb2f10
commit 34943ed1fb
7 changed files with 113 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
import { SecureNoteType, CipherType } from "@bitwarden/common/vault/enums";
import { SecureNoteType, CipherType, FieldType } from "@bitwarden/common/vault/enums";
import { CardView } from "@bitwarden/common/vault/models/view/card.view";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
@@ -8,9 +8,10 @@ import { ImportResult } from "../models/import-result";
import { BaseImporter } from "./base-importer";
import { Importer } from "./importer";
type nodePassCsvParsed = {
type NordPassCsvParsed = {
name: string;
url: string;
additional_urls: string;
username: string;
password: string;
note: string;
@@ -28,12 +29,20 @@ type nodePassCsvParsed = {
city: string;
country: string;
state: string;
type: string;
custom_fields: string;
};
type NordPassCustomField = {
label: string;
type: string;
value: string;
};
export class NordPassCsvImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
const result = new ImportResult();
const results: nodePassCsvParsed[] = this.parseCsv(data, true);
const results: NordPassCsvParsed[] = this.parseCsv(data, true);
if (results == null) {
result.success = false;
return Promise.resolve(result);
@@ -45,21 +54,40 @@ export class NordPassCsvImporter extends BaseImporter implements Importer {
return;
}
if (!this.organization) {
this.processFolder(result, record.folder);
}
this.processFolder(result, record.folder);
const cipher = new CipherView();
cipher.name = this.getValueOrDefault(record.name, "--");
cipher.notes = this.getValueOrDefault(record.note);
if (record.custom_fields) {
const customFieldsParsed: NordPassCustomField[] = JSON.parse(record.custom_fields);
if (customFieldsParsed && customFieldsParsed.length > 0) {
customFieldsParsed.forEach((field) => {
let fieldType = FieldType.Text;
if (field.type == "hidden") {
fieldType = FieldType.Hidden;
}
this.processKvp(cipher, field.label, field.value, fieldType);
});
}
}
switch (recordType) {
case CipherType.Login:
cipher.type = CipherType.Login;
cipher.login = new LoginView();
cipher.login.username = this.getValueOrDefault(record.username);
cipher.login.password = this.getValueOrDefault(record.password);
cipher.login.uris = this.makeUriArray(record.url);
if (record.additional_urls) {
const additionalUrlsParsed: string[] = JSON.parse(record.additional_urls);
const uris = [record.url, ...additionalUrlsParsed];
cipher.login.uris = this.makeUriArray(uris);
} else {
cipher.login.uris = this.makeUriArray(record.url);
}
break;
case CipherType.Card:
cipher.type = CipherType.Card;
@@ -106,21 +134,16 @@ export class NordPassCsvImporter extends BaseImporter implements Importer {
return Promise.resolve(result);
}
private evaluateType(record: nodePassCsvParsed): CipherType {
if (!this.isNullOrWhitespace(record.username)) {
return CipherType.Login;
}
if (!this.isNullOrWhitespace(record.cardnumber)) {
return CipherType.Card;
}
if (!this.isNullOrWhitespace(record.full_name)) {
return CipherType.Identity;
}
if (!this.isNullOrWhitespace(record.note)) {
return CipherType.SecureNote;
private evaluateType(record: NordPassCsvParsed): CipherType {
switch (record.type) {
case "password":
return CipherType.Login;
case "credit_card":
return CipherType.Card;
case "note":
return CipherType.SecureNote;
case "identity":
return CipherType.Identity;
}
return undefined;