From 07b2aaee6ca264fa34f7019f72e93844012ae854 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Tue, 3 Dec 2024 13:25:17 +0100 Subject: [PATCH] Add tests to verify importing German and Dutch headers work --- .../spec/passwordxp-csv-importer.spec.ts | 74 +++++++++++-------- .../test-data/passwordxp-csv/dutch-headers.ts | 7 ++ .../passwordxp-csv/german-headers.ts | 7 ++ 3 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 libs/importer/spec/test-data/passwordxp-csv/dutch-headers.ts create mode 100644 libs/importer/spec/test-data/passwordxp-csv/german-headers.ts diff --git a/libs/importer/spec/passwordxp-csv-importer.spec.ts b/libs/importer/spec/passwordxp-csv-importer.spec.ts index f707b1138c..c11e7ac053 100644 --- a/libs/importer/spec/passwordxp-csv-importer.spec.ts +++ b/libs/importer/spec/passwordxp-csv-importer.spec.ts @@ -3,10 +3,46 @@ import { CipherType } from "@bitwarden/common/vault/enums"; import { PasswordXPCsvImporter } from "../src/importers"; import { ImportResult } from "../src/models/import-result"; +import { dutchHeaders } from "./test-data/passwordxp-csv/dutch-headers"; +import { germanHeaders } from "./test-data/passwordxp-csv/german-headers"; import { noFolder } from "./test-data/passwordxp-csv/no-folder.csv"; import { withFolders } from "./test-data/passwordxp-csv/passwordxp-with-folders.csv"; import { withoutFolders } from "./test-data/passwordxp-csv/passwordxp-without-folders.csv"; +async function importLoginWithCustomFields(importer: PasswordXPCsvImporter, csvData: string) { + const result: ImportResult = await importer.parse(csvData); + expect(result.success).toBe(true); + + const cipher = result.ciphers.shift(); + expect(cipher.type).toBe(CipherType.Login); + expect(cipher.name).toBe("Title2"); + expect(cipher.notes).toBe("Test Notes"); + expect(cipher.login.username).toBe("Username2"); + expect(cipher.login.password).toBe("12345678"); + expect(cipher.login.uris[0].uri).toBe("http://URL2.com"); + + expect(cipher.fields.length).toBe(5); + let field = cipher.fields.shift(); + expect(field.name).toBe("Account"); + expect(field.value).toBe("Account2"); + + field = cipher.fields.shift(); + expect(field.name).toBe("Modified"); + expect(field.value).toBe("27-3-2024 08:11:21"); + + field = cipher.fields.shift(); + expect(field.name).toBe("Created"); + expect(field.value).toBe("27-3-2024 08:11:21"); + + field = cipher.fields.shift(); + expect(field.name).toBe("Expire on"); + expect(field.value).toBe("27-5-2024 08:11:21"); + + field = cipher.fields.shift(); + expect(field.name).toBe("Modified by"); + expect(field.value).toBe("someone"); +} + describe("PasswordXPCsvImporter", () => { let importer: PasswordXPCsvImporter; @@ -61,38 +97,16 @@ describe("PasswordXPCsvImporter", () => { expect(cipher.login.uris[0].uri).toBe("http://test"); }); - it("should parse CSV data and import unmapped columns as custom fields", async () => { - const result: ImportResult = await importer.parse(withoutFolders); - expect(result.success).toBe(true); + it("should parse CSV data with English headers and import unmapped columns as custom fields", async () => { + await importLoginWithCustomFields(importer, withoutFolders); + }); - const cipher = result.ciphers.shift(); - expect(cipher.type).toBe(CipherType.Login); - expect(cipher.name).toBe("Title2"); - expect(cipher.notes).toBe("Test Notes"); - expect(cipher.login.username).toBe("Username2"); - expect(cipher.login.password).toBe("12345678"); - expect(cipher.login.uris[0].uri).toBe("http://URL2.com"); + it("should parse CSV data with German headers and import unmapped columns as custom fields", async () => { + await importLoginWithCustomFields(importer, germanHeaders); + }); - expect(cipher.fields.length).toBe(5); - let field = cipher.fields.shift(); - expect(field.name).toBe("Account"); - expect(field.value).toBe("Account2"); - - field = cipher.fields.shift(); - expect(field.name).toBe("Modified"); - expect(field.value).toBe("27-3-2024 08:11:21"); - - field = cipher.fields.shift(); - expect(field.name).toBe("Created"); - expect(field.value).toBe("27-3-2024 08:11:21"); - - field = cipher.fields.shift(); - expect(field.name).toBe("Expire on"); - expect(field.value).toBe("27-5-2024 08:11:21"); - - field = cipher.fields.shift(); - expect(field.name).toBe("Modified by"); - expect(field.value).toBe("someone"); + it("should parse CSV data with Dutch headers and import unmapped columns as custom fields", async () => { + await importLoginWithCustomFields(importer, dutchHeaders); }); it("should parse CSV data with folders and assign items to them", async () => { diff --git a/libs/importer/spec/test-data/passwordxp-csv/dutch-headers.ts b/libs/importer/spec/test-data/passwordxp-csv/dutch-headers.ts new file mode 100644 index 0000000000..9cab04f1e6 --- /dev/null +++ b/libs/importer/spec/test-data/passwordxp-csv/dutch-headers.ts @@ -0,0 +1,7 @@ +export const dutchHeaders = `Titel;Gebruikersnaam;Account;URL;Wachtwoord;Gewijzigd;Gemaakt;Verloopt op;Beschrijving;Gewijzigd door +>>> +Title2;Username2;Account2;http://URL2.com;12345678;27-3-2024 08:11:21;27-3-2024 08:11:21;27-5-2024 08:11:21;Test Notes;someone +Title Test 1;Username1;Account1;http://URL1.com;Password1;27-3-2024 08:10:52;27-3-2024 08:10:52;;Test Notes 2; +Certificate 1;;;;;27-3-2024 10:22:39;27-3-2024 10:22:39;;Test Notes Certicate 1; +test;testtest;;http://test;test;27-3-2024 12:36:59;27-3-2024 12:36:59;;Test Notes 3; +`; diff --git a/libs/importer/spec/test-data/passwordxp-csv/german-headers.ts b/libs/importer/spec/test-data/passwordxp-csv/german-headers.ts new file mode 100644 index 0000000000..a6ac21c76d --- /dev/null +++ b/libs/importer/spec/test-data/passwordxp-csv/german-headers.ts @@ -0,0 +1,7 @@ +export const germanHeaders = `Titel;Benutzername;Konto;URL;Passwort;Geändert am;Erstellt am;Läuft ab am;Beschreibung;Geändert von +>>> +Title2;Username2;Account2;http://URL2.com;12345678;27-3-2024 08:11:21;27-3-2024 08:11:21;27-5-2024 08:11:21;Test Notes;someone +Title Test 1;Username1;Account1;http://URL1.com;Password1;27-3-2024 08:10:52;27-3-2024 08:10:52;;Test Notes 2; +Certificate 1;;;;;27-3-2024 10:22:39;27-3-2024 10:22:39;;Test Notes Certicate 1; +test;testtest;;http://test;test;27-3-2024 12:36:59;27-3-2024 12:36:59;;Test Notes 3; +`;