mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-29 12:55:21 +01:00
0e78910582
* Rename all importer related files Renamed all files based on our naming convention which we decided on with https://github.com/bitwarden/adr/blob/master/decisions/0012-angular-filename-convention.md * Removed entries from whitelist-capital-letters.txt * Rename missing safeInCloud test data * Fix broken import * Renamed folders (removed capital letters) * Fix filename of BitwardenCsvImporter * Fix imports of onepassword mac/win importer tests * Remove already renamed folders from whitelist * Rename dashlaneImporters to dashlane Rename the folder Fix all the imports Remove dashlaneImporters from white-list * Rename keeperImporters to keeper Rename the folder Fix all the imports Remove keeperImporters from white-list * Rename onepasswordImporters to onepassword Rename the folder Fix all the imports Remove onepasswordImporters from white-list * Rename safeinCloud test data folder * Fix onepassword importer type imports
109 lines
4.1 KiB
TypeScript
109 lines
4.1 KiB
TypeScript
import { KeeperJsonImporter as Importer } from "@bitwarden/common/importers/keeper/keeper-json-importer";
|
|
import { Utils } from "@bitwarden/common/misc/utils";
|
|
|
|
import { testData as TestData } from "./test-data/keeper-json/testdata.json";
|
|
|
|
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]);
|
|
});
|
|
});
|