From a8168d6ee7ebcde490fb014b3c5f555485412762 Mon Sep 17 00:00:00 2001 From: Linus Aarnio <42450444+linusaarnio@users.noreply.github.com> Date: Thu, 16 Dec 2021 18:46:33 +0100 Subject: [PATCH] Fix for issue #1287 in bitwarden/web (#569) * Format the fieldvalue as a LocaleDateString instead of epoch when importing a date from 1P This would be better solved by storing it as a date FieldType instead of Text. But since it is unclear when new field types are added, this solution serves as a fix for now and also guides the solution when new fieldtype exists. * Remove trailing whitespace * Add tests for custom fields of 1pif imported identity * Change representation of 1pif imported dates to UTC string * Changes after running prettier Co-authored-by: Daniel James Smith --- .../onepasswordImporters/onepassword1PifImporter.ts | 6 +++++- .../importers/onepassword1PifImporter.spec.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts b/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts index 01ec4e5954..fd202ba569 100644 --- a/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts +++ b/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts @@ -172,7 +172,11 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer { return; } - const fieldValue = field[valueKey].toString(); + // TODO: when date FieldType exists, store this as a date field type instead of formatted Text if k is 'date' + const fieldValue = + field.k === "date" + ? new Date(field[valueKey] * 1000).toUTCString() + : field[valueKey].toString(); const fieldDesignation = field[designationKey] != null ? field[designationKey].toString() : null; diff --git a/spec/common/importers/onepassword1PifImporter.spec.ts b/spec/common/importers/onepassword1PifImporter.spec.ts index ade73e997e..ffa2417a10 100644 --- a/spec/common/importers/onepassword1PifImporter.spec.ts +++ b/spec/common/importers/onepassword1PifImporter.spec.ts @@ -476,6 +476,19 @@ describe("1Password 1Pif Importer", () => { // remaining fields as custom fields expect(cipher.fields.length).toEqual(6); + const fields = cipher.fields; + expect(fields[0].name).toEqual("sex"); + expect(fields[0].value).toEqual("male"); + expect(fields[1].name).toEqual("birth date"); + expect(fields[1].value).toEqual("Mon, 11 Mar 2019 12:01:00 GMT"); + expect(fields[2].name).toEqual("occupation"); + expect(fields[2].value).toEqual("Engineer"); + expect(fields[3].name).toEqual("department"); + expect(fields[3].value).toEqual("IT"); + expect(fields[4].name).toEqual("job title"); + expect(fields[4].value).toEqual("Developer"); + expect(fields[5].name).toEqual("home"); + expect(fields[5].value).toEqual("+49 333 222 111"); }); it("should create password history", async () => {