diff --git a/libs/importer/spec/securesafe-csv-importer.spec.ts b/libs/importer/spec/securesafe-csv-importer.spec.ts index 8d12ae12d942..2d91ad7fcea2 100644 --- a/libs/importer/spec/securesafe-csv-importer.spec.ts +++ b/libs/importer/spec/securesafe-csv-importer.spec.ts @@ -4,7 +4,11 @@ import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; import { SecureSafeCsvImporter } from "../src/importers"; -import { data_upperUrl, data_lowerUrl } from "./test-data/securesafe-csv/securesafe-example.csv"; +import { + data_upperUrl, + data_lowerUrl, + data_surrounding_slashes, +} from "./test-data/securesafe-csv/securesafe-example.csv"; const CipherData = [ { @@ -49,6 +53,27 @@ const CipherData = [ type: 1, }), }, + { + title: "should change headers to english and remove surrounding slashes if present", + csv: data_surrounding_slashes, + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "Gmail", + login: Object.assign(new LoginView(), { + username: "test@gmail.com", + password: "/test", + uris: [ + Object.assign(new LoginUriView(), { + uri: "https://gmail.com", + }), + ], + }), + notes: "comment/", + type: 1, + }), + }, ]; describe("SecureSafe CSV Importer", () => { diff --git a/libs/importer/spec/test-data/securesafe-csv/securesafe-example.csv.ts b/libs/importer/spec/test-data/securesafe-csv/securesafe-example.csv.ts index 75bf5127bf32..c7e93f579560 100644 --- a/libs/importer/spec/test-data/securesafe-csv/securesafe-example.csv.ts +++ b/libs/importer/spec/test-data/securesafe-csv/securesafe-example.csv.ts @@ -3,3 +3,6 @@ export const data_upperUrl = `"Title","Username","Password","URL","Comment" export const data_lowerUrl = `"Title","Username","Password","url","Comment" "Gmail","test@gmail.com","test","https://gmail.com"`; + +export const data_surrounding_slashes = `"/Titel/","/Benutzername/","/Passwort/","/URL/","/Kommentar/", +"/Gmail/","/test@gmail.com/","/test","/https://gmail.com/","comment/"`; diff --git a/libs/importer/src/importers/securesafe-csv-importer.ts b/libs/importer/src/importers/securesafe-csv-importer.ts index 1664932cf5e4..53f1460fde66 100644 --- a/libs/importer/src/importers/securesafe-csv-importer.ts +++ b/libs/importer/src/importers/securesafe-csv-importer.ts @@ -12,9 +12,28 @@ export class SecureSafeCsvImporter extends BaseImporter implements Importer { return Promise.resolve(result); } + // SecureSafe currently exports values in multiple languages. - 09/05/2024 + // New headers are used to ensure import success. + const newHeaders = ["Title", "Username", "Password", "URL", "Comment"]; + + // SecureSafe can surround values in slashes. - 09/05/2024 + // This removes any surrounding slashes from the values. + const headers = Object.keys(results[0]); + const remappedResults = results.map((row) => { + const remappedRow: any = {}; + newHeaders.forEach((header, index) => { + let value = row[headers[index]]; + if (typeof value === "string" && value.startsWith("/") && value.endsWith("/")) { + value = value.slice(1, -1); + } + remappedRow[header] = value; + }); + return remappedRow; + }); + // The url field can be in different case formats. - const urlField = Object.keys(results[0]).find((k) => /url/i.test(k)); - results.forEach((value) => { + const urlField = Object.keys(remappedResults[0]).find((k) => /url/i.test(k)); + remappedResults.forEach((value) => { const cipher = this.initLoginCipher(); cipher.name = this.getValueOrDefault(value.Title); cipher.notes = this.getValueOrDefault(value.Comment);