forked from bitwarden/jslib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip FirefoxAccounts during Firefox CSV Import (bitwarden#323)
* Skip FirefoxAccounts during Firefox CSV Import Firefox exports 'chrome://FirefoxAccounts' if Firefox Accouts are used in browser. It's quite hacky - password field in CSV is actually a JSON encoded data, not a password. Because it's not a useful record, it should be skipped during import. * Fix indentation * Move test Firefox test data to files, fix linter errors
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { FirefoxCsvImporter as Importer } from '../../../src/importers/firefoxCsvImporter'; | ||
|
||
import { CipherView } from '../../../src/models/view/cipherView'; | ||
import { LoginUriView } from '../../../src/models/view/loginUriView'; | ||
import { LoginView } from '../../../src/models/view/loginView'; | ||
|
||
import { data as firefoxAccountsData } from './testData/firefoxCsv/firefoxAccountsData.csv'; | ||
import { data as simplePasswordData } from './testData/firefoxCsv/simplePasswordData.csv'; | ||
|
||
const CipherData = [ | ||
{ | ||
title: 'should parse password', | ||
csv: simplePasswordData, | ||
expected: Object.assign(new CipherView(), { | ||
id: null, | ||
organizationId: null, | ||
folderId: null, | ||
name: 'example.com', | ||
login: Object.assign(new LoginView(), { | ||
username: 'foo', | ||
password: 'bar', | ||
uris: [ | ||
Object.assign(new LoginUriView(), { | ||
uri: 'https://example.com', | ||
}), | ||
], | ||
}), | ||
notes: null, | ||
type: 1, | ||
}), | ||
}, | ||
{ | ||
title: 'should skip "chrome://FirefoxAccounts"', | ||
csv: firefoxAccountsData, | ||
expected: Object.assign(new CipherView(), { | ||
id: null, | ||
organizationId: null, | ||
folderId: null, | ||
name: 'example.com', | ||
login: Object.assign(new LoginView(), { | ||
username: 'foo', | ||
password: 'bar', | ||
uris: [ | ||
Object.assign(new LoginUriView(), { | ||
uri: 'https://example.com', | ||
}), | ||
], | ||
}), | ||
notes: null, | ||
type: 1, | ||
}), | ||
}, | ||
]; | ||
|
||
describe('Firefox CSV Importer', () => { | ||
CipherData.forEach(data => { | ||
it(data.title, async () => { | ||
const importer = new Importer(); | ||
const result = await importer.parse(data.csv); | ||
expect(result != null).toBe(true); | ||
expect(result.ciphers.length).toBeGreaterThan(0); | ||
|
||
const cipher = result.ciphers.shift(); | ||
let property: keyof typeof data.expected; | ||
for (property in data.expected) { | ||
if (data.expected.hasOwnProperty(property)) { | ||
expect(cipher.hasOwnProperty(property)).toBe(true); | ||
expect(cipher[property]).toEqual(data.expected[property]); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
spec/common/importers/testData/firefoxCsv/firefoxAccountsData.csv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const data = `"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged" | ||
"chrome://FirefoxAccounts","bla-bla-foo-bar","{""version"":1,""accountData"":{""kSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kXCS"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtKbHash"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""scopedKeys"":{""https://identity.mozilla.com/apps/oldsync"":{""kid"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""},""sync:addon_storage"":{""kid"":""xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""}}}}","Firefox Accounts credentials",,"{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900" | ||
"https://example.com","foo","bar",,"","{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900" | ||
`; |
2 changes: 2 additions & 0 deletions
2
spec/common/importers/testData/firefoxCsv/simplePasswordData.csv.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const data = `"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged" | ||
"https://example.com","foo","bar",,"","{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters