fix 1password csv importer

This commit is contained in:
Kyle Spearrin 2020-03-12 16:59:59 -04:00
parent b816ddddff
commit 0a30c7eb1e
1 changed files with 23 additions and 16 deletions

View File

@ -6,7 +6,7 @@ import { ImportResult } from '../models/domain/importResult';
import { CipherType } from '../enums/cipherType';
import { CardView } from '../models/view';
const IgnoredProperties = ['ainfo', 'autosubmit', 'notesPlain', 'ps', 'scope', 'tags', 'title', 'uuid'];
const IgnoredProperties = ['ainfo', 'autosubmit', 'notesplain', 'ps', 'scope', 'tags', 'title', 'uuid'];
export class OnePasswordWinCsvImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult {
@ -18,15 +18,16 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
}
results.forEach((value) => {
if (this.isNullOrWhitespace(value.title)) {
if (this.isNullOrWhitespace(this.getProp(value, 'title'))) {
return;
}
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.title, '--');
cipher.notes = this.getValueOrDefault(value.notesPlain, '') + '\n';
cipher.name = this.getValueOrDefault(this.getProp(value, 'title'), '--');
cipher.notes = this.getValueOrDefault(this.getProp(value, 'notesPlain'), '') + '\n';
if (!this.isNullOrWhitespace(value.number) && !this.isNullOrWhitespace(value['expiry date'])) {
if (!this.isNullOrWhitespace(this.getProp(value, 'number')) &&
!this.isNullOrWhitespace(this.getProp(value, 'expiry date'))) {
cipher.type = CipherType.Card;
cipher.card = new CardView();
}
@ -37,30 +38,31 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
continue;
}
const lowerProp = property.toLowerCase();
if (cipher.type === CipherType.Login) {
if (this.isNullOrWhitespace(cipher.login.password) && property === 'password') {
if (this.isNullOrWhitespace(cipher.login.password) && lowerProp === 'password') {
cipher.login.password = value[property];
continue;
} else if (this.isNullOrWhitespace(cipher.login.username) && property === 'username') {
} else if (this.isNullOrWhitespace(cipher.login.username) && lowerProp === 'username') {
cipher.login.username = value[property];
continue;
} else if ((cipher.login.uris == null || cipher.login.uri.length === 0) && property === 'urls') {
} else if ((cipher.login.uris == null || cipher.login.uri.length === 0) && lowerProp === 'urls') {
const urls = value[property].split(this.newLineRegex);
cipher.login.uris = this.makeUriArray(urls);
continue;
}
} else if (cipher.type === CipherType.Card) {
if (this.isNullOrWhitespace(cipher.card.number) && property === 'number') {
if (this.isNullOrWhitespace(cipher.card.number) && lowerProp === 'number') {
cipher.card.number = value[property];
cipher.card.brand = this.getCardBrand(value.number);
cipher.card.brand = this.getCardBrand(this.getProp(value, 'number'));
continue;
} else if (this.isNullOrWhitespace(cipher.card.code) && property === 'verification number') {
} else if (this.isNullOrWhitespace(cipher.card.code) && lowerProp === 'verification number') {
cipher.card.code = value[property];
continue;
} else if (this.isNullOrWhitespace(cipher.card.cardholderName) && property === 'cardholder name') {
} else if (this.isNullOrWhitespace(cipher.card.cardholderName) && lowerProp === 'cardholder name') {
cipher.card.cardholderName = value[property];
continue;
} else if (this.isNullOrWhitespace(cipher.card.expiration) && property === 'expiry date' &&
} else if (this.isNullOrWhitespace(cipher.card.expiration) && lowerProp === 'expiry date' &&
value[property].length === 6) {
cipher.card.expMonth = (value[property] as string).substr(4, 2);
if (cipher.card.expMonth[0] === '0') {
@ -68,14 +70,15 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
}
cipher.card.expYear = (value[property] as string).substr(0, 4);
continue;
} else if (property === 'type') {
} else if (lowerProp === 'type') {
// Skip since brand was determined from number above
continue;
}
}
if (IgnoredProperties.indexOf(property) === -1 && !property.startsWith('section:')) {
if (altUsername == null && property === 'email') {
if (IgnoredProperties.indexOf(lowerProp) === -1 && !lowerProp.startsWith('section:') &&
!lowerProp.startsWith('section ')) {
if (altUsername == null && lowerProp === 'email') {
altUsername = value[property];
}
this.processKvp(cipher, property, value[property]);
@ -95,4 +98,8 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
result.success = true;
return result;
}
private getProp(obj: any, name: string): any {
return obj[name] || obj[name.toUpperCase()];
}
}