mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-328] Move common/importer to libs/importer (tools-migration) (#5060)
* 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
This commit is contained in:
committed by
GitHub
parent
7cfabf053c
commit
a5a12a6723
115
libs/importer/spec/bitwarden-password-protected-importer.spec.ts
Normal file
115
libs/importer/spec/bitwarden-password-protected-importer.spec.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Substitute, Arg, SubstituteOf } from "@fluffy-spoon/substitute";
|
||||
|
||||
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { KdfType } from "@bitwarden/common/enums/kdfType";
|
||||
import { Utils } from "@bitwarden/common/misc/utils";
|
||||
|
||||
import { BitwardenPasswordProtectedImporter } from "../src/importers";
|
||||
import { ImportResult } from "../src/models/import-result";
|
||||
|
||||
import { data as emptyDecryptedData } from "./test-data/bitwarden-json/empty.json";
|
||||
|
||||
describe("BitwardenPasswordProtectedImporter", () => {
|
||||
let importer: BitwardenPasswordProtectedImporter;
|
||||
let cryptoService: SubstituteOf<CryptoService>;
|
||||
let i18nService: SubstituteOf<I18nService>;
|
||||
const password = Utils.newGuid();
|
||||
const result = new ImportResult();
|
||||
let jDoc: {
|
||||
encrypted?: boolean;
|
||||
passwordProtected?: boolean;
|
||||
salt?: string;
|
||||
kdfIterations?: any;
|
||||
kdfType?: any;
|
||||
encKeyValidation_DO_NOT_EDIT?: string;
|
||||
data?: string;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
cryptoService = Substitute.for<CryptoService>();
|
||||
i18nService = Substitute.for<I18nService>();
|
||||
|
||||
jDoc = {
|
||||
encrypted: true,
|
||||
passwordProtected: true,
|
||||
salt: "c2FsdA==",
|
||||
kdfIterations: 100000,
|
||||
kdfType: KdfType.PBKDF2_SHA256,
|
||||
encKeyValidation_DO_NOT_EDIT: Utils.newGuid(),
|
||||
data: Utils.newGuid(),
|
||||
};
|
||||
|
||||
result.success = true;
|
||||
importer = new BitwardenPasswordProtectedImporter(cryptoService, i18nService, password);
|
||||
});
|
||||
|
||||
describe("Required Json Data", () => {
|
||||
it("succeeds with default jdoc", async () => {
|
||||
cryptoService.decryptToUtf8(Arg.any(), Arg.any()).resolves(emptyDecryptedData);
|
||||
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(true);
|
||||
});
|
||||
|
||||
it("fails if encrypted === false", async () => {
|
||||
jDoc.encrypted = false;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if encrypted === null", async () => {
|
||||
jDoc.encrypted = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if passwordProtected === false", async () => {
|
||||
jDoc.passwordProtected = false;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if passwordProtected === null", async () => {
|
||||
jDoc.passwordProtected = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if salt === null", async () => {
|
||||
jDoc.salt = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if kdfIterations === null", async () => {
|
||||
jDoc.kdfIterations = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if kdfIterations is not a number", async () => {
|
||||
jDoc.kdfIterations = "not a number";
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if kdfType === null", async () => {
|
||||
jDoc.kdfType = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if kdfType is not a string", async () => {
|
||||
jDoc.kdfType = "not a valid kdf type";
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if kdfType is not a known kdfType", async () => {
|
||||
jDoc.kdfType = -1;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if encKeyValidation_DO_NOT_EDIT === null", async () => {
|
||||
jDoc.encKeyValidation_DO_NOT_EDIT = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
|
||||
it("fails if data === null", async () => {
|
||||
jDoc.data = null;
|
||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user