From 8644d84e68934abd51cb74646c3b6e0452d620af Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Tue, 14 Dec 2021 10:22:09 +0100 Subject: [PATCH] FSescure-Importer: Add support for style = global (#578) * Fescure-Importer: Add support for style = global * Fix linting --- common/src/importers/fsecureFskImporter.ts | 2 +- .../importers/fsecureFskImporter.spec.ts | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 spec/common/importers/fsecureFskImporter.spec.ts diff --git a/common/src/importers/fsecureFskImporter.ts b/common/src/importers/fsecureFskImporter.ts index 1aac8932f0..04f3d971c9 100644 --- a/common/src/importers/fsecureFskImporter.ts +++ b/common/src/importers/fsecureFskImporter.ts @@ -26,7 +26,7 @@ export class FSecureFskImporter extends BaseImporter implements Importer { cipher.name = this.getValueOrDefault(value.service); cipher.notes = this.getValueOrDefault(value.notes); - if (value.style === 'website') { + if (value.style === 'website' || value.style === 'globe') { cipher.login.username = this.getValueOrDefault(value.username); cipher.login.password = this.getValueOrDefault(value.password); cipher.login.uris = this.makeUriArray(value.url); diff --git a/spec/common/importers/fsecureFskImporter.spec.ts b/spec/common/importers/fsecureFskImporter.spec.ts new file mode 100644 index 0000000000..a2aab4930f --- /dev/null +++ b/spec/common/importers/fsecureFskImporter.spec.ts @@ -0,0 +1,80 @@ +import { FSecureFskImporter as Importer } from 'jslib-common/importers/fsecureFskImporter'; + +const TestDataWithStyleSetToWebsite: string = + JSON.stringify({ + data: { + '8d58b5cf252dd06fbd98f5289e918ab1': { + color: '#00baff', + reatedDate: 1609302913, + creditCvv: '', + creditExpiry: '', + creditNumber: '', + favorite: 0, + modifiedDate: 1609302913, + notes: 'note', + password: 'word', + passwordList: [], + passwordModifiedDate: 1609302913, + rev: 1, + service: 'My first pass', + style: 'website', + type: 1, + url: 'https://bitwarden.com', + username: 'pass', + }, + }, + }); + +const TestDataWithStyleSetToGlobe: string = + JSON.stringify({ + data: { + '8d58b5cf252dd06fbd98f5289e918ab1': { + color: '#00baff', + reatedDate: 1609302913, + creditCvv: '', + creditExpiry: '', + creditNumber: '', + favorite: 0, + modifiedDate: 1609302913, + notes: 'note', + password: 'word', + passwordList: [], + passwordModifiedDate: 1609302913, + rev: 1, + service: 'My first pass', + style: 'globe', + type: 1, + url: 'https://bitwarden.com', + username: 'pass', + }, + }, + }); + + +describe('FSecure FSK Importer', () => { + it('should parse data with style set to website', async () => { + const importer = new Importer(); + const result = await importer.parse(TestDataWithStyleSetToWebsite); + expect(result != null).toBe(true); + + const cipher = result.ciphers.shift(); + expect(cipher.login.username).toEqual('pass'); + expect(cipher.login.password).toEqual('word'); + expect(cipher.login.uris.length).toEqual(1); + const uriView = cipher.login.uris.shift(); + expect(uriView.uri).toEqual('https://bitwarden.com'); + }); + + it('should parse data with style set to globe', async () => { + const importer = new Importer(); + const result = await importer.parse(TestDataWithStyleSetToGlobe); + expect(result != null).toBe(true); + + const cipher = result.ciphers.shift(); + expect(cipher.login.username).toEqual('pass'); + expect(cipher.login.password).toEqual('word'); + expect(cipher.login.uris.length).toEqual(1); + const uriView = cipher.login.uris.shift(); + expect(uriView.uri).toEqual('https://bitwarden.com'); + }); +});