1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-22 21:21:35 +01:00

add new types to tests

This commit is contained in:
Jacob Fink 2023-06-20 09:15:15 -04:00
parent a24c49adae
commit 87bf80a461
No known key found for this signature in database
GPG Key ID: C2F7ACF05859D008
11 changed files with 50 additions and 58 deletions

View File

@ -7,16 +7,6 @@ describe("AccountSettings", () => {
expect(AccountSettings.fromJSON(JSON.parse("{}"))).toBeInstanceOf(AccountSettings);
});
it("should deserialize userSymKeyPin", () => {
const accountSettings = new AccountSettings();
accountSettings.userSymKeyPin = EncString.fromJSON("encrypted");
const jsonObj = JSON.parse(JSON.stringify(accountSettings));
const actual = AccountSettings.fromJSON(jsonObj);
expect(actual.userSymKeyPin).toBeInstanceOf(EncString);
expect(actual.userSymKeyPin.encryptedString).toEqual("encrypted");
});
it("should deserialize pinProtected", () => {
const accountSettings = new AccountSettings();
accountSettings.pinProtected = EncryptionPair.fromJSON<string, EncString>({

View File

@ -4,7 +4,7 @@ import { mock, MockProxy } from "jest-mock-extended";
import { EncryptionType } from "../../../enums";
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
import { OrgKey, SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
import { CryptoService } from "../../abstractions/crypto.service";
import { ContainerService } from "../../services/container.service";
@ -230,7 +230,7 @@ describe("EncString", () => {
});
it("gets an organization key if required", async () => {
const orgKey = mock<SymmetricCryptoKey>();
const orgKey = mock<SymmetricCryptoKey>() as OrgKey;
cryptoService.getOrgKey.calledWith("orgId").mockResolvedValue(orgKey);

View File

@ -3,7 +3,7 @@ import { mock, MockProxy } from "jest-mock-extended";
import { makeStaticByteArray, mockEnc, mockFromJson } from "../../../../spec";
import { CryptoService } from "../../../platform/abstractions/crypto.service";
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
import { ContainerService } from "../../../platform/services/container.service";
import { AttachmentData } from "../../models/data/attachment.data";
@ -136,8 +136,8 @@ describe("Attachment", () => {
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
const actual = Attachment.fromJSON({
key: "myKey",
fileName: "myFileName",
key: "myKey" as EncryptedString,
fileName: "myFileName" as EncryptedString,
});
expect(actual).toEqual({

View File

@ -1,5 +1,5 @@
import { mockEnc, mockFromJson } from "../../../../spec";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { CardData } from "../../../vault/models/data/card.data";
import { Card } from "../../models/domain/card";
@ -76,12 +76,12 @@ describe("Card", () => {
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
const actual = Card.fromJSON({
cardholderName: "mockCardHolder",
brand: "mockBrand",
number: "mockNumber",
expMonth: "mockExpMonth",
expYear: "mockExpYear",
code: "mockCode",
cardholderName: "mockCardHolder" as EncryptedString,
brand: "mockBrand" as EncryptedString,
number: "mockNumber" as EncryptedString,
expMonth: "mockExpMonth" as EncryptedString,
expYear: "mockExpYear" as EncryptedString,
code: "mockCode" as EncryptedString,
});
expect(actual).toEqual({

View File

@ -1,6 +1,6 @@
import { mockEnc, mockFromJson } from "../../../../spec";
import { FieldType } from "../../../enums";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { FieldData } from "../../models/data/field.data";
import { Field } from "../../models/domain/field";
@ -67,8 +67,8 @@ describe("Field", () => {
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
const actual = Field.fromJSON({
name: "myName",
value: "myValue",
name: "myName" as EncryptedString,
value: "myValue" as EncryptedString,
});
expect(actual).toEqual({

View File

@ -1,5 +1,5 @@
import { mockEnc, mockFromJson } from "../../../../spec";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { FolderData } from "../../models/data/folder.data";
import { Folder } from "../../models/domain/folder";
@ -47,7 +47,7 @@ describe("Folder", () => {
const revisionDate = new Date("2022-08-04T01:06:40.441Z");
const actual = Folder.fromJSON({
revisionDate: revisionDate.toISOString(),
name: "name",
name: "name" as EncryptedString,
id: "id",
});

View File

@ -1,5 +1,5 @@
import { mockEnc, mockFromJson } from "../../../../spec";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { IdentityData } from "../../models/data/identity.data";
import { Identity } from "../../models/domain/identity";
@ -137,24 +137,24 @@ describe("Identity", () => {
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
const actual = Identity.fromJSON({
firstName: "mockFirstName",
lastName: "mockLastName",
address1: "mockAddress1",
address2: "mockAddress2",
address3: "mockAddress3",
city: "mockCity",
company: "mockCompany",
country: "mockCountry",
email: "mockEmail",
licenseNumber: "mockLicenseNumber",
middleName: "mockMiddleName",
passportNumber: "mockPassportNumber",
phone: "mockPhone",
postalCode: "mockPostalCode",
ssn: "mockSsn",
state: "mockState",
title: "mockTitle",
username: "mockUsername",
firstName: "mockFirstName" as EncryptedString,
lastName: "mockLastName" as EncryptedString,
address1: "mockAddress1" as EncryptedString,
address2: "mockAddress2" as EncryptedString,
address3: "mockAddress3" as EncryptedString,
city: "mockCity" as EncryptedString,
company: "mockCompany" as EncryptedString,
country: "mockCountry" as EncryptedString,
email: "mockEmail" as EncryptedString,
licenseNumber: "mockLicenseNumber" as EncryptedString,
middleName: "mockMiddleName" as EncryptedString,
passportNumber: "mockPassportNumber" as EncryptedString,
phone: "mockPhone" as EncryptedString,
postalCode: "mockPostalCode" as EncryptedString,
ssn: "mockSsn" as EncryptedString,
state: "mockState" as EncryptedString,
title: "mockTitle" as EncryptedString,
username: "mockUsername" as EncryptedString,
});
expect(actual).toEqual({

View File

@ -3,7 +3,7 @@ import { Substitute, Arg } from "@fluffy-spoon/substitute";
import { mockEnc, mockFromJson } from "../../../../spec";
import { UriMatchType } from "../../../enums";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { LoginData } from "../../models/data/login.data";
import { Login } from "../../models/domain/login";
import { LoginUri } from "../../models/domain/login-uri";
@ -108,10 +108,10 @@ describe("Login DTO", () => {
const actual = Login.fromJSON({
uris: ["loginUri1", "loginUri2"] as any,
username: "myUsername",
password: "myPassword",
username: "myUsername" as EncryptedString,
password: "myPassword" as EncryptedString,
passwordRevisionDate: passwordRevisionDate.toISOString(),
totp: "myTotp",
totp: "myTotp" as EncryptedString,
});
expect(actual).toEqual({

View File

@ -1,5 +1,5 @@
import { mockEnc, mockFromJson } from "../../../../spec";
import { EncString } from "../../../platform/models/domain/enc-string";
import { EncryptedString, EncString } from "../../../platform/models/domain/enc-string";
import { PasswordHistoryData } from "../../models/data/password-history.data";
import { Password } from "../../models/domain/password";
@ -55,7 +55,7 @@ describe("Password", () => {
const lastUsedDate = new Date("2022-01-31T12:00:00.000Z");
const actual = Password.fromJSON({
password: "myPassword",
password: "myPassword" as EncryptedString,
lastUsedDate: lastUsedDate.toISOString(),
});

View File

@ -10,7 +10,7 @@ import { I18nService } from "../../platform/abstractions/i18n.service";
import { StateService } from "../../platform/abstractions/state.service";
import { EncArrayBuffer } from "../../platform/models/domain/enc-array-buffer";
import { EncString } from "../../platform/models/domain/enc-string";
import { SymmetricCryptoKey } from "../../platform/models/domain/symmetric-crypto-key";
import { OrgKey, SymmetricCryptoKey } from "../../platform/models/domain/symmetric-crypto-key";
import { CipherFileUploadService } from "../abstractions/file-upload/cipher-file-upload.service";
import { Cipher } from "../models/domain/cipher";
@ -59,7 +59,9 @@ describe("Cipher Service", () => {
it("attachments upload encrypted file contents", async () => {
const fileName = "filename";
const fileData = new Uint8Array(10).buffer;
cryptoService.getOrgKey(Arg.any()).resolves(new SymmetricCryptoKey(new Uint8Array(32).buffer));
cryptoService
.getOrgKey(Arg.any())
.resolves(new SymmetricCryptoKey(new Uint8Array(32).buffer) as OrgKey);
await cipherService.saveAttachmentRawWithServer(new Cipher(), fileName, fileData);

View File

@ -8,7 +8,7 @@ import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { StateService } from "@bitwarden/common/platform/services/state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
@ -94,7 +94,7 @@ function generateFolderView() {
function generateFolder() {
const actual = Folder.fromJSON({
revisionDate: new Date("2022-08-04T01:06:40.441Z").toISOString(),
name: "name",
name: "name" as EncryptedString,
id: "id",
});
return actual;
@ -217,8 +217,8 @@ describe("VaultExportService", () => {
mac = Substitute.for<EncString>();
data = Substitute.for<EncString>();
mac.encryptedString.returns("mac");
data.encryptedString.returns("encData");
mac.encryptedString.returns("mac" as EncryptedString);
data.encryptedString.returns("encData" as EncryptedString);
jest.spyOn(Utils, "fromBufferToB64").mockReturnValue(salt);
cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1));