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

Skip FirefoxAccounts during Firefox CSV Import #323

Merged
merged 3 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions spec/common/importers/firefoxCsvImporter.spec.ts
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 = [
MGibson1 marked this conversation as resolved.
Show resolved Hide resolved
{
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]);
}
}
});
});
});
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"
`;
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"`;
4 changes: 3 additions & 1 deletion src/importers/firefoxCsvImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class FirefoxCsvImporter extends BaseImporter implements Importer {
return Promise.resolve(result);
}

results.forEach(value => {
results.filter(value => {
return value.url !== 'chrome://FirefoxAccounts';
}).forEach(value => {
const cipher = this.initLoginCipher();
const url = this.getValueOrDefault(value.url, this.getValueOrDefault(value.hostname));
cipher.name = this.getValueOrDefault(this.nameFromUrl(url), '--');
Expand Down