1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-31 07:33:40 +00:00

[EC-142] Fix error during import of 1pux containing new email field format (#758)

* Add support for complex email field type

* Ensure complex email field type gets imported on identities
This commit is contained in:
Daniel James Smith
2022-04-06 17:33:43 +02:00
committed by GitHub
parent 5f4a8c18fe
commit 3b9ef68f4b
8 changed files with 405 additions and 13 deletions

View File

@@ -258,7 +258,7 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
}
}
} else if (cipher.type === CipherType.Identity) {
if (this.fillIdentity(field, fieldValue, cipher)) {
if (this.fillIdentity(field, fieldValue, cipher, valueKey)) {
return;
}
if (valueKey === "address") {
@@ -312,6 +312,14 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
}
}
if (valueKey === "email") {
// fieldValue is an object casted into a string, so access the plain value instead
const { email_address, provider } = field.value.email;
this.processKvp(cipher, fieldName, email_address, FieldType.Text);
this.processKvp(cipher, "provider", provider, FieldType.Text);
return;
}
// Do not include a password field if it's already in the history
if (
field.title === "password" &&
@@ -440,7 +448,12 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
return false;
}
private fillIdentity(field: FieldsEntity, fieldValue: string, cipher: CipherView): boolean {
private fillIdentity(
field: FieldsEntity,
fieldValue: string,
cipher: CipherView,
valueKey: string
): boolean {
if (this.isNullOrWhitespace(cipher.identity.firstName) && field.id === "firstname") {
cipher.identity.firstName = fieldValue;
return true;
@@ -466,9 +479,18 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
return true;
}
if (this.isNullOrWhitespace(cipher.identity.email) && field.id === "email") {
cipher.identity.email = fieldValue;
return true;
if (this.isNullOrWhitespace(cipher.identity.email)) {
if (valueKey === "email") {
const { email_address, provider } = field.value.email;
cipher.identity.email = this.getValueOrDefault(email_address);
this.processKvp(cipher, "provider", provider, FieldType.Text);
return true;
}
if (field.id === "email") {
cipher.identity.email = fieldValue;
return true;
}
}
if (this.isNullOrWhitespace(cipher.identity.username) && field.id === "username") {

View File

@@ -106,7 +106,7 @@ export interface Value {
date?: number | null;
string?: string | null;
concealed?: string | null;
email?: string | null;
email?: Email | null;
phone?: string | null;
menu?: string | null;
gender?: string | null;
@@ -117,6 +117,12 @@ export interface Value {
creditCardNumber?: string | null;
reference?: string | null;
}
export interface Email {
email_address: string;
provider: string;
}
export interface Address {
street: string;
city: string;