mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-17 10:55:20 +01:00
a5a12a6723
* Create and register new libs/importer Create package.json Create tsconfig Create jest.config Extend shared and root tsconfig and jest.configs Register with eslint * Move importer-related files to libs/importer * Move importer-spec-related files to libs/importer Move import.service.spec * Update package-lock.json * Set CODEOWNERS for new libs/importer * Register libs/importer with cli and fix imports * Register libs/importer with web and fix imports * Move importOption into models Rename importOptions to import-options * Fix linting issues after updating prettier * Only expose necessary files from libs/importer Fix tsconfig files - Removes the trailing /index on imports in web/cli As the spec-files no longer can access the internals via @bitwarden/importer they import by path (../src/importers) * Add barrel files to vendors with more than one importer
110 lines
4.1 KiB
TypeScript
110 lines
4.1 KiB
TypeScript
import { Utils } from "@bitwarden/common/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]);
|
|
});
|
|
});
|