From f9539ef68b9f91591f337edb0301a85a56fcbb8a Mon Sep 17 00:00:00 2001 From: aj-rosado <109146700+aj-rosado@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:51:44 +0000 Subject: [PATCH] Calling processFolder method when adding ciphers on PsonoJsonImporter (#7984) --- libs/importer/spec/psono-json-importer.spec.ts | 4 +--- .../spec/test-data/psono-json/folders.ts | 18 ++++++++++++++++++ .../src/importers/psono/psono-json-importer.ts | 12 +++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libs/importer/spec/psono-json-importer.spec.ts b/libs/importer/spec/psono-json-importer.spec.ts index 371a3829f2..82795e5ea5 100644 --- a/libs/importer/spec/psono-json-importer.spec.ts +++ b/libs/importer/spec/psono-json-importer.spec.ts @@ -230,10 +230,8 @@ describe("PSONO JSON Importer", () => { const result = await importer.parse(FoldersTestDataJson); expect(result != null).toBe(true); - const folders = result.folders; // // Check that ciphers have a folder assigned to them - expect(result.ciphers.filter((c) => c.folderId === folders[0].id).length).toBeGreaterThan(0); - expect(result.ciphers.filter((c) => c.folderId === folders[1].id).length).toBeGreaterThan(0); + expect(result.ciphers.length).toEqual(result.folderRelationships.length); }); it("should create collections if part of an organization", async () => { diff --git a/libs/importer/spec/test-data/psono-json/folders.ts b/libs/importer/spec/test-data/psono-json/folders.ts index bcc61ea11f..d6e64b7cdd 100644 --- a/libs/importer/spec/test-data/psono-json/folders.ts +++ b/libs/importer/spec/test-data/psono-json/folders.ts @@ -23,6 +23,24 @@ export const FoldersTestData: PsonoJsonExport = { callback_user: "callbackUser", callback_pass: "callbackPassword", }, + { + type: "website_password", + name: "TestEntry1.2", + autosubmit: true, + urlfilter: "filter", + website_password_title: "TestEntry1.2", + website_password_url: "bitwarden.com", + website_password_username: "testUser", + website_password_password: "testPassword", + website_password_notes: "some notes", + website_password_auto_submit: true, + website_password_url_filter: "filter", + create_date: "2022-12-13T19:24:09.810266Z", + write_date: "2022-12-13T19:24:09.810292Z", + callback_url: "callback", + callback_user: "callbackUser", + callback_pass: "callbackPassword", + }, ], }, { diff --git a/libs/importer/src/importers/psono/psono-json-importer.ts b/libs/importer/src/importers/psono/psono-json-importer.ts index 85fe646517..c28fa86d49 100644 --- a/libs/importer/src/importers/psono/psono-json-importer.ts +++ b/libs/importer/src/importers/psono/psono-json-importer.ts @@ -61,20 +61,22 @@ export class PsonoJsonImporter extends BaseImporter implements Importer { this.parseFolders(result, folder.folders, folder.name); } - this.processFolder(result, folder.name, folderHasItems); - - this.handleItemParsing(result, folder.items); + if (!folderHasItems) { + this.processFolder(result, folder.name, folderHasItems); + } else { + this.handleItemParsing(result, folder.items, folder.name); + } }); } - private handleItemParsing(result: ImportResult, items?: PsonoItemTypes[]) { + private handleItemParsing(result: ImportResult, items?: PsonoItemTypes[], folderName?: string) { if (items == null || items.length === 0) { return; } items.forEach((record) => { const cipher = this.parsePsonoItem(record); - + this.processFolder(result, folderName, true); this.cleanupCipher(cipher); result.ciphers.push(cipher); });