mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-02 13:23:29 +01:00
a4fba0e1c5
* Switch to jest * Fix jslib-angular package name * Make angular test project * Split up tests by jslib project * Remove obsolete node test script * Use legacy deps with jest-preset-angular * Move web tests to common * Remove build from pipeline This was only being used because we were not using ts runners. We are now, so build is unnecessary
109 lines
4.1 KiB
TypeScript
109 lines
4.1 KiB
TypeScript
import { KeeperJsonImporter as Importer } from "jslib-common/importers/keeperImporters/keeperJsonImporter";
|
|
import { Utils } from "jslib-common/misc/utils";
|
|
|
|
import { testData as TestData } from "./testData/keeperJson/testData";
|
|
|
|
describe("Keeper Json Importer", () => {
|
|
const testDataJson = JSON.stringify(TestData);
|
|
|
|
let importer: Importer;
|
|
beforeEach(() => {
|
|
importer = new Importer();
|
|
});
|
|
|
|
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]);
|
|
});
|
|
});
|