Add import of totp from Lastpass (#361)

* Add import of totp from Lastpass

* Fixed import as request during review
This commit is contained in:
Daniel James Smith 2021-04-28 22:50:37 +02:00 committed by GitHub
parent 5b7d918f29
commit e298ecfee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -1,9 +1,27 @@
import { LastPassCsvImporter as Importer } from '../../../src/importers/lastpassCsvImporter'; import { LastPassCsvImporter as Importer } from '../../../src/importers/lastpassCsvImporter';
import { ImportResult } from '../../../src/models/domain/importResult';
import { CipherView } from '../../../src/models/view/cipherView'; import { CipherView } from '../../../src/models/view/cipherView';
import { FieldView } from '../../../src/models/view/fieldView'; import { FieldView } from '../../../src/models/view/fieldView';
import { FieldType } from '../../../src/enums'; import { CipherType, FieldType } from '../../../src/enums';
function baseExcept(result: ImportResult) {
expect(result).not.toBeNull();
expect(result.success).toBe(true);
expect(result.ciphers.length).toBe(1);
}
function expectLogin(cipher: CipherView) {
expect(cipher.type).toBe(CipherType.Login);
expect(cipher.name).toBe('example.com');
expect(cipher.notes).toBe('super secure notes');
expect(cipher.login.uri).toBe('http://example.com');
expect(cipher.login.username).toBe('someUser');
expect(cipher.login.password).toBe('myPassword');
expect(cipher.login.totp).toBe('Y64VEVMBTSXCYIWRSHRNDZW62MPGVU2G');
}
const CipherData = [ const CipherData = [
{ {
@ -168,4 +186,16 @@ describe('Lastpass CSV Importer', () => {
} }
}); });
}); });
it('should parse login with totp', async () => {
const input = `url,username,password,totp,extra,name,grouping,fav
http://example.com,someUser,myPassword,Y64VEVMBTSXCYIWRSHRNDZW62MPGVU2G,super secure notes,example.com,,0`;
const importer = new Importer();
const result = await importer.parse(input);
baseExcept(result);
const cipher = result.ciphers[0];
expectLogin(cipher);
});
}); });

View File

@ -49,6 +49,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
cipher.login.uris = this.makeUriArray(value.url); cipher.login.uris = this.makeUriArray(value.url);
cipher.login.username = this.getValueOrDefault(value.username); cipher.login.username = this.getValueOrDefault(value.username);
cipher.login.password = this.getValueOrDefault(value.password); cipher.login.password = this.getValueOrDefault(value.password);
cipher.login.totp = this.getValueOrDefault(value.totp);
} else if (cipher.type === CipherType.SecureNote) { } else if (cipher.type === CipherType.SecureNote) {
this.parseSecureNote(value, cipher); this.parseSecureNote(value, cipher);
} else if (cipher.type === CipherType.Card) { } else if (cipher.type === CipherType.Card) {