1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 03:03:43 +00:00
Files
browser/libs/importer/src/importers/keeper/keeper-csv-importer.spec.ts
Shane Melton 391f540d1f [PM-22136] Implement SDK cipher encryption (#15337)
* [PM-22136] Update sdk cipher view map to support uknown uuid type

* [PM-22136] Add key to CipherView for copying to SdkCipherView for encryption

* [PM-22136] Add fromSdk* helpers to Cipher domain objects

* [PM-22136] Add toSdk* helpers to Cipher View objects

* [PM-22136] Add encrypt() to cipher encryption service

* [PM-22136] Add feature flag

* [PM-22136] Use new SDK encrypt method when feature flag is enabled

* [PM-22136] Filter out null/empty URIs

* [PM-22136] Change default value for cipher view arrays to []. See ADR-0014.

* [PM-22136] Keep encrypted key value on attachment so that it is passed to the SDK

* [PM-22136] Keep encrypted key value on CipherView so that it is passed to the SDK during encryption

* [PM-22136] Update failing attachment test

* [PM-22136] Update failing importer tests due to new default value for arrays

* [PM-22136] Update CipherView.fromJson to handle the prototype of EncString for the cipher key

* [PM-22136] Add tickets for followup work

* [PM-22136] Use new set_fido2_credentials SDK method instead

* [PM-22136] Fix missing prototype when decrypting Fido2Credentials

* [PM-22136] Fix test after sdk change

* [PM-22136] Update @bitwarden/sdk-internal version

* [PM-22136] Fix some strict typing errors

* [PM-23348] Migrate move cipher to org to SDK (#15567)

* [PM-23348] Add moveToOrganization method to cipher-encryption.service.ts

* [PM-23348] Use cipherEncryptionService.moveToOrganization in cipherService shareWithServer and shareManyWithServer methods

* [PM-23348] Update cipherFormService to use the shareWithServer() method instead of encrypt()

* [PM-23348] Fix typo

* [PM-23348] Add missing docs

* [PM-22136] Fix EncString import after merge with main
2025-07-21 23:27:01 -07:00

156 lines
5.5 KiB
TypeScript

import { Utils } from "@bitwarden/common/platform/misc/utils";
import {
testData as TestData,
testDataMultiCollection,
} from "../spec-data/keeper-csv/testdata.csv";
import { KeeperCsvImporter } from "./keeper-csv-importer";
describe("Keeper CSV Importer", () => {
let importer: KeeperCsvImporter;
beforeEach(() => {
importer = new KeeperCsvImporter();
});
it("should parse login data", async () => {
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.name).toEqual("Bar");
expect(cipher.login.username).toEqual("john.doe@example.com");
expect(cipher.login.password).toEqual("1234567890abcdef");
expect(cipher.login.uris.length).toEqual(1);
const uriView = cipher.login.uris.shift();
expect(uriView.uri).toEqual("https://example.com/");
expect(cipher.notes).toEqual("These are some notes.");
const cipher2 = result.ciphers.shift();
expect(cipher2.name).toEqual("Bar 1");
expect(cipher2.login.username).toEqual("john.doe1@example.com");
expect(cipher2.login.password).toEqual("234567890abcdef1");
expect(cipher2.login.uris.length).toEqual(1);
const uriView2 = cipher2.login.uris.shift();
expect(uriView2.uri).toEqual("https://an.example.com/");
expect(cipher2.notes).toBeNull();
const cipher3 = result.ciphers.shift();
expect(cipher3.name).toEqual("Bar 2");
expect(cipher3.login.username).toEqual("john.doe2@example.com");
expect(cipher3.login.password).toEqual("34567890abcdef12");
expect(cipher3.notes).toBeNull();
expect(cipher3.login.uris.length).toEqual(1);
const uriView3 = cipher3.login.uris.shift();
expect(uriView3.uri).toEqual("https://another.example.com/");
});
it("should import TOTP when present", async () => {
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.login.totp).toBeNull();
const cipher2 = result.ciphers.shift();
expect(cipher2.login.totp).toBeNull();
const cipher3 = result.ciphers.shift();
expect(cipher3.login.totp).toEqual(
"otpauth://totp/Amazon:me@company.com?secret=JBSWY3DPEHPK3PXP&issuer=Amazon&algorithm=SHA1&digits=6&period=30",
);
});
it("should parse custom fields", async () => {
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.fields.length).toBe(0);
const cipher2 = result.ciphers.shift();
expect(cipher2.fields.length).toBe(2);
expect(cipher2.fields[0].name).toEqual("Account ID");
expect(cipher2.fields[0].value).toEqual("12345");
expect(cipher2.fields[1].name).toEqual("Org ID");
expect(cipher2.fields[1].value).toEqual("54321");
const cipher3 = result.ciphers.shift();
expect(cipher3.fields[0].name).toEqual("Account ID");
expect(cipher3.fields[0].value).toEqual("23456");
});
it("should create folders, with subfolders and relationships", async () => {
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
const folders = result.folders;
expect(folders).not.toBeNull();
expect(folders.length).toBe(2);
const folder1 = folders.shift();
expect(folder1.name).toBe("Foo");
//With subfolders
const folder2 = folders.shift();
expect(folder2.name).toBe("Foo/Baz");
// [Cipher, Folder]
expect(result.folderRelationships.length).toBe(3);
expect(result.folderRelationships[0]).toEqual([0, 0]);
expect(result.folderRelationships[1]).toEqual([1, 0]);
expect(result.folderRelationships[2]).toEqual([2, 1]);
});
it("should create collections, with subcollections and relationships", async () => {
importer.organizationId = Utils.newGuid();
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
const collections = result.collections;
expect(collections).not.toBeNull();
expect(collections.length).toBe(2);
const collections1 = collections.shift();
expect(collections1.name).toBe("Foo");
//With subCollection
const collections2 = collections.shift();
expect(collections2.name).toBe("Foo/Baz");
// [Cipher, Folder]
expect(result.collectionRelationships.length).toBe(3);
expect(result.collectionRelationships[0]).toEqual([0, 0]);
expect(result.collectionRelationships[1]).toEqual([1, 0]);
expect(result.collectionRelationships[2]).toEqual([2, 1]);
});
it("should create collections tree, with child collections and relationships", async () => {
importer.organizationId = Utils.newGuid();
const result = await importer.parse(testDataMultiCollection);
expect(result != null).toBe(true);
const collections = result.collections;
expect(collections).not.toBeNull();
expect(collections.length).toBe(3);
// collection with the cipher
const collections1 = collections.shift();
expect(collections1.name).toBe("Foo/Baz/Bar");
//second level collection
const collections2 = collections.shift();
expect(collections2.name).toBe("Foo/Baz");
//third level
const collections3 = collections.shift();
expect(collections3.name).toBe("Foo");
// [Cipher, Folder]
expect(result.collectionRelationships.length).toBe(3);
expect(result.collectionRelationships[0]).toEqual([0, 0]);
expect(result.collectionRelationships[1]).toEqual([1, 1]);
expect(result.collectionRelationships[2]).toEqual([2, 2]);
});
});