1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00
bitwarden-browser/libs/importer/spec/keeper-json-importer.spec.ts
Matt Gibson 78248db590
Platform/pm 19/platform team file moves (#5460)
* Rename service-factory folder

* Move cryptographic service factories

* Move crypto models

* Move crypto services

* Move domain base class

* Platform code owners

* Move desktop log services

* Move log files

* Establish component library ownership

* Move background listeners

* Move background background

* Move localization to Platform

* Move browser alarms to Platform

* Move browser state to Platform

* Move CLI state to Platform

* Move Desktop native concerns to Platform

* Move flag and misc to Platform

* Lint fixes

* Move electron state to platform

* Move web state to Platform

* Move lib state to Platform

* Fix broken tests

* Rename interface to idiomatic TS

* `npm run prettier` 🤖

* Resolve review feedback

* Set platform as owners of web core and shared

* Expand moved services

* Fix test types

---------

Co-authored-by: Hinton <hinton@users.noreply.github.com>
2023-06-06 15:34:53 -05:00

110 lines
4.1 KiB
TypeScript

import { Utils } from "@bitwarden/common/platform/misc/utils";
import { KeeperJsonImporter } from "../src/importers";
import { testData as TestData } from "./test-data/keeper-json/testdata.json";
describe("Keeper Json Importer", () => {
const testDataJson = JSON.stringify(TestData);
let importer: KeeperJsonImporter;
beforeEach(() => {
importer = new KeeperJsonImporter();
});
it("should parse login data", async () => {
const result = await importer.parse(testDataJson);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.name).toEqual("Bank Account 1");
expect(cipher.login.username).toEqual("customer1234");
expect(cipher.login.password).toEqual("4813fJDHF4239fdk");
expect(cipher.login.uris.length).toEqual(1);
const uriView = cipher.login.uris.shift();
expect(uriView.uri).toEqual("https://chase.com");
expect(cipher.notes).toEqual("These are some notes.");
const cipher2 = result.ciphers.shift();
expect(cipher2.name).toEqual("Bank Account 2");
expect(cipher2.login.username).toEqual("mybankusername");
expect(cipher2.login.password).toEqual("w4k4k193f$^&@#*%2");
expect(cipher2.login.uris.length).toEqual(1);
const uriView2 = cipher2.login.uris.shift();
expect(uriView2.uri).toEqual("https://amex.com");
expect(cipher2.notes).toEqual("Some great information here.");
const cipher3 = result.ciphers.shift();
expect(cipher3.name).toEqual("Some Account");
expect(cipher3.login.username).toEqual("someUserName");
expect(cipher3.login.password).toEqual("w4k4k1wergf$^&@#*%2");
expect(cipher3.notes).toBeNull();
expect(cipher3.fields).toBeNull();
expect(cipher3.login.uris.length).toEqual(1);
const uriView3 = cipher3.login.uris.shift();
expect(uriView3.uri).toEqual("https://example.com");
});
it("should import TOTP when present", async () => {
const result = await importer.parse(testDataJson);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.login.totp).toBeNull();
// 2nd Cipher
const cipher2 = result.ciphers.shift();
expect(cipher2.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(testDataJson);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.fields.length).toBe(1);
expect(cipher.fields[0].name).toEqual("Account Number");
expect(cipher.fields[0].value).toEqual("123-456-789");
// 2nd Cipher
const cipher2 = result.ciphers.shift();
expect(cipher2.fields.length).toBe(2);
expect(cipher2.fields[0].name).toEqual("Security Group");
expect(cipher2.fields[0].value).toEqual("Public");
expect(cipher2.fields[1].name).toEqual("IP Address");
expect(cipher2.fields[1].value).toEqual("12.45.67.8");
});
it("should create folders and assigned ciphers to them", async () => {
const result = await importer.parse(testDataJson);
expect(result != null).toBe(true);
const folders = result.folders;
expect(folders.length).toBe(2);
expect(folders[0].name).toBe("Optional Private Folder 1");
expect(folders[1].name).toBe("My Customer 1");
expect(result.folderRelationships[0]).toEqual([0, 0]);
expect(result.folderRelationships[1]).toEqual([1, 0]);
expect(result.folderRelationships[2]).toEqual([1, 1]);
});
it("should create collections if part of an organization", async () => {
importer.organizationId = Utils.newGuid();
const result = await importer.parse(testDataJson);
expect(result != null).toBe(true);
const collections = result.collections;
expect(collections.length).toBe(2);
expect(collections[0].name).toBe("Optional Private Folder 1");
expect(collections[1].name).toBe("My Customer 1");
expect(result.collectionRelationships[0]).toEqual([0, 0]);
expect(result.collectionRelationships[1]).toEqual([1, 0]);
expect(result.collectionRelationships[2]).toEqual([1, 1]);
});
});