Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
fix 1password csv importer
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Mar 12, 2020
1 parent b816ddd commit 0a30c7e
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/importers/onepasswordWinCsvImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand All @@ -37,45 +38,47 @@ 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') {
cipher.card.expMonth = cipher.card.expMonth.substr(1, 1);
}
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]);
Expand All @@ -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()];
}
}

0 comments on commit 0a30c7e

Please sign in to comment.