From 3ef10807546972a135b2551fe8e39b328774a84c Mon Sep 17 00:00:00 2001 From: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> Date: Mon, 19 Aug 2024 12:27:00 +0200 Subject: [PATCH] [PM-10791] Set favorite on import from ProtonPass (#10480) * Update import test data with new fields Add new fields to the types file * Set favorites when importing from ProtonPass --------- Co-authored-by: Daniel James Smith --- libs/importer/spec/protonpass-json-importer.spec.ts | 10 ++++++++++ .../spec/test-data/protonpass-json/protonpass.json.ts | 9 ++++++++- .../importers/protonpass/protonpass-json-importer.ts | 1 + .../importers/protonpass/types/protonpass-json-type.ts | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libs/importer/spec/protonpass-json-importer.spec.ts b/libs/importer/spec/protonpass-json-importer.spec.ts index f58e4d5f25..d5f4653c64 100644 --- a/libs/importer/spec/protonpass-json-importer.spec.ts +++ b/libs/importer/spec/protonpass-json-importer.spec.ts @@ -116,4 +116,14 @@ describe("Protonpass Json Importer", () => { expect(ciphers.length).toBe(4); }); + + it("should set favorites", async () => { + const testDataJson = JSON.stringify(testData); + const result = await importer.parse(testDataJson); + + const ciphers = result.ciphers; + expect(ciphers[0].favorite).toBe(true); + expect(ciphers[1].favorite).toBe(false); + expect(ciphers[2].favorite).toBe(true); + }); }); diff --git a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts index ddbe9e89b9..a508a03deb 100644 --- a/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts +++ b/libs/importer/spec/test-data/protonpass-json/protonpass.json.ts @@ -1,7 +1,7 @@ import { ProtonPassJsonFile } from "../../../src/importers/protonpass/types/protonpass-json-type"; export const testData: ProtonPassJsonFile = { - version: "1.3.1", + version: "1.21.2", userId: "REDACTED_USER_ID", encrypted: false, vaults: { @@ -54,6 +54,7 @@ export const testData: ProtonPassJsonFile = { urls: ["https://example.com/", "https://example2.com/"], totpUri: "otpauth://totp/Test%20Login%20-%20Personal%20Vault:Username?issuer=Test%20Login%20-%20Personal%20Vault&secret=TOTPCODE&algorithm=SHA1&digits=6&period=30", + passkeys: [], itemUsername: "Username", }, }, @@ -62,6 +63,7 @@ export const testData: ProtonPassJsonFile = { contentFormatVersion: 1, createTime: 1689182868, modifyTime: 1689182868, + pinned: true, }, { itemId: @@ -83,6 +85,7 @@ export const testData: ProtonPassJsonFile = { contentFormatVersion: 1, createTime: 1689182908, modifyTime: 1689182908, + pinned: false, }, { itemId: @@ -111,6 +114,7 @@ export const testData: ProtonPassJsonFile = { contentFormatVersion: 1, createTime: 1691001643, modifyTime: 1691001643, + pinned: true, }, { itemId: @@ -132,6 +136,7 @@ export const testData: ProtonPassJsonFile = { contentFormatVersion: 1, createTime: 1689182908, modifyTime: 1689182908, + pinned: false, }, ], }, @@ -161,6 +166,7 @@ export const testData: ProtonPassJsonFile = { password: "other vault password", urls: [], totpUri: "JBSWY3DPEHPK3PXP", + passkeys: [], itemUsername: "", }, }, @@ -169,6 +175,7 @@ export const testData: ProtonPassJsonFile = { contentFormatVersion: 1, createTime: 1689182949, modifyTime: 1689182949, + pinned: false, }, ], }, diff --git a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts index 7a7018bde2..b8f6bc170c 100644 --- a/libs/importer/src/importers/protonpass/protonpass-json-importer.ts +++ b/libs/importer/src/importers/protonpass/protonpass-json-importer.ts @@ -43,6 +43,7 @@ export class ProtonPassJsonImporter extends BaseImporter implements Importer { const cipher = this.initLoginCipher(); cipher.name = this.getValueOrDefault(item.data.metadata.name, "--"); cipher.notes = this.getValueOrDefault(item.data.metadata.note); + cipher.favorite = item.pinned; switch (item.data.type) { case "login": { diff --git a/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts b/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts index 4c082a93cf..eb3b4bba5a 100644 --- a/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts +++ b/libs/importer/src/importers/protonpass/types/protonpass-json-type.ts @@ -24,6 +24,7 @@ export type ProtonPassItem = { contentFormatVersion: number; createTime: number; modifyTime: number; + pinned: boolean; }; export enum ProtonPassItemState { @@ -34,6 +35,7 @@ export enum ProtonPassItemState { export type ProtonPassItemData = { metadata: ProtonPassItemMetadata; extraFields: ProtonPassItemExtraField[]; + platformSpecific?: any; type: "login" | "alias" | "creditCard" | "note"; content: ProtonPassLoginItemContent | ProtonPassCreditCardItemContent; }; @@ -60,6 +62,7 @@ export type ProtonPassLoginItemContent = { password?: string; urls?: string[]; totpUri?: string; + passkeys: []; itemUsername?: string; };