mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
add new types to tests
This commit is contained in:
@@ -7,16 +7,6 @@ describe("AccountSettings", () => {
|
|||||||
expect(AccountSettings.fromJSON(JSON.parse("{}"))).toBeInstanceOf(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", () => {
|
it("should deserialize pinProtected", () => {
|
||||||
const accountSettings = new AccountSettings();
|
const accountSettings = new AccountSettings();
|
||||||
accountSettings.pinProtected = EncryptionPair.fromJSON<string, EncString>({
|
accountSettings.pinProtected = EncryptionPair.fromJSON<string, EncString>({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
|||||||
|
|
||||||
import { EncryptionType } from "../../../enums";
|
import { EncryptionType } from "../../../enums";
|
||||||
import { EncryptService } from "../../../platform/abstractions/encrypt.service";
|
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 { CryptoService } from "../../abstractions/crypto.service";
|
||||||
import { ContainerService } from "../../services/container.service";
|
import { ContainerService } from "../../services/container.service";
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ describe("EncString", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("gets an organization key if required", async () => {
|
it("gets an organization key if required", async () => {
|
||||||
const orgKey = mock<SymmetricCryptoKey>();
|
const orgKey = mock<SymmetricCryptoKey>() as OrgKey;
|
||||||
|
|
||||||
cryptoService.getOrgKey.calledWith("orgId").mockResolvedValue(orgKey);
|
cryptoService.getOrgKey.calledWith("orgId").mockResolvedValue(orgKey);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
|||||||
import { makeStaticByteArray, mockEnc, mockFromJson } from "../../../../spec";
|
import { makeStaticByteArray, mockEnc, mockFromJson } from "../../../../spec";
|
||||||
import { CryptoService } from "../../../platform/abstractions/crypto.service";
|
import { CryptoService } from "../../../platform/abstractions/crypto.service";
|
||||||
import { EncryptService } from "../../../platform/abstractions/encrypt.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 { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
|
||||||
import { ContainerService } from "../../../platform/services/container.service";
|
import { ContainerService } from "../../../platform/services/container.service";
|
||||||
import { AttachmentData } from "../../models/data/attachment.data";
|
import { AttachmentData } from "../../models/data/attachment.data";
|
||||||
@@ -136,8 +136,8 @@ describe("Attachment", () => {
|
|||||||
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
||||||
|
|
||||||
const actual = Attachment.fromJSON({
|
const actual = Attachment.fromJSON({
|
||||||
key: "myKey",
|
key: "myKey" as EncryptedString,
|
||||||
fileName: "myFileName",
|
fileName: "myFileName" as EncryptedString,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
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 { CardData } from "../../../vault/models/data/card.data";
|
||||||
import { Card } from "../../models/domain/card";
|
import { Card } from "../../models/domain/card";
|
||||||
|
|
||||||
@@ -76,12 +76,12 @@ describe("Card", () => {
|
|||||||
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
||||||
|
|
||||||
const actual = Card.fromJSON({
|
const actual = Card.fromJSON({
|
||||||
cardholderName: "mockCardHolder",
|
cardholderName: "mockCardHolder" as EncryptedString,
|
||||||
brand: "mockBrand",
|
brand: "mockBrand" as EncryptedString,
|
||||||
number: "mockNumber",
|
number: "mockNumber" as EncryptedString,
|
||||||
expMonth: "mockExpMonth",
|
expMonth: "mockExpMonth" as EncryptedString,
|
||||||
expYear: "mockExpYear",
|
expYear: "mockExpYear" as EncryptedString,
|
||||||
code: "mockCode",
|
code: "mockCode" as EncryptedString,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
import { mockEnc, mockFromJson } from "../../../../spec";
|
||||||
import { FieldType } from "../../../enums";
|
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 { FieldData } from "../../models/data/field.data";
|
||||||
import { Field } from "../../models/domain/field";
|
import { Field } from "../../models/domain/field";
|
||||||
|
|
||||||
@@ -67,8 +67,8 @@ describe("Field", () => {
|
|||||||
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
||||||
|
|
||||||
const actual = Field.fromJSON({
|
const actual = Field.fromJSON({
|
||||||
name: "myName",
|
name: "myName" as EncryptedString,
|
||||||
value: "myValue",
|
value: "myValue" as EncryptedString,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
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 { FolderData } from "../../models/data/folder.data";
|
||||||
import { Folder } from "../../models/domain/folder";
|
import { Folder } from "../../models/domain/folder";
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ describe("Folder", () => {
|
|||||||
const revisionDate = new Date("2022-08-04T01:06:40.441Z");
|
const revisionDate = new Date("2022-08-04T01:06:40.441Z");
|
||||||
const actual = Folder.fromJSON({
|
const actual = Folder.fromJSON({
|
||||||
revisionDate: revisionDate.toISOString(),
|
revisionDate: revisionDate.toISOString(),
|
||||||
name: "name",
|
name: "name" as EncryptedString,
|
||||||
id: "id",
|
id: "id",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
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 { IdentityData } from "../../models/data/identity.data";
|
||||||
import { Identity } from "../../models/domain/identity";
|
import { Identity } from "../../models/domain/identity";
|
||||||
|
|
||||||
@@ -137,24 +137,24 @@ describe("Identity", () => {
|
|||||||
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
|
||||||
|
|
||||||
const actual = Identity.fromJSON({
|
const actual = Identity.fromJSON({
|
||||||
firstName: "mockFirstName",
|
firstName: "mockFirstName" as EncryptedString,
|
||||||
lastName: "mockLastName",
|
lastName: "mockLastName" as EncryptedString,
|
||||||
address1: "mockAddress1",
|
address1: "mockAddress1" as EncryptedString,
|
||||||
address2: "mockAddress2",
|
address2: "mockAddress2" as EncryptedString,
|
||||||
address3: "mockAddress3",
|
address3: "mockAddress3" as EncryptedString,
|
||||||
city: "mockCity",
|
city: "mockCity" as EncryptedString,
|
||||||
company: "mockCompany",
|
company: "mockCompany" as EncryptedString,
|
||||||
country: "mockCountry",
|
country: "mockCountry" as EncryptedString,
|
||||||
email: "mockEmail",
|
email: "mockEmail" as EncryptedString,
|
||||||
licenseNumber: "mockLicenseNumber",
|
licenseNumber: "mockLicenseNumber" as EncryptedString,
|
||||||
middleName: "mockMiddleName",
|
middleName: "mockMiddleName" as EncryptedString,
|
||||||
passportNumber: "mockPassportNumber",
|
passportNumber: "mockPassportNumber" as EncryptedString,
|
||||||
phone: "mockPhone",
|
phone: "mockPhone" as EncryptedString,
|
||||||
postalCode: "mockPostalCode",
|
postalCode: "mockPostalCode" as EncryptedString,
|
||||||
ssn: "mockSsn",
|
ssn: "mockSsn" as EncryptedString,
|
||||||
state: "mockState",
|
state: "mockState" as EncryptedString,
|
||||||
title: "mockTitle",
|
title: "mockTitle" as EncryptedString,
|
||||||
username: "mockUsername",
|
username: "mockUsername" as EncryptedString,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Substitute, Arg } from "@fluffy-spoon/substitute";
|
|||||||
|
|
||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
import { mockEnc, mockFromJson } from "../../../../spec";
|
||||||
import { UriMatchType } from "../../../enums";
|
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 { LoginData } from "../../models/data/login.data";
|
||||||
import { Login } from "../../models/domain/login";
|
import { Login } from "../../models/domain/login";
|
||||||
import { LoginUri } from "../../models/domain/login-uri";
|
import { LoginUri } from "../../models/domain/login-uri";
|
||||||
@@ -108,10 +108,10 @@ describe("Login DTO", () => {
|
|||||||
|
|
||||||
const actual = Login.fromJSON({
|
const actual = Login.fromJSON({
|
||||||
uris: ["loginUri1", "loginUri2"] as any,
|
uris: ["loginUri1", "loginUri2"] as any,
|
||||||
username: "myUsername",
|
username: "myUsername" as EncryptedString,
|
||||||
password: "myPassword",
|
password: "myPassword" as EncryptedString,
|
||||||
passwordRevisionDate: passwordRevisionDate.toISOString(),
|
passwordRevisionDate: passwordRevisionDate.toISOString(),
|
||||||
totp: "myTotp",
|
totp: "myTotp" as EncryptedString,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mockEnc, mockFromJson } from "../../../../spec";
|
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 { PasswordHistoryData } from "../../models/data/password-history.data";
|
||||||
import { Password } from "../../models/domain/password";
|
import { Password } from "../../models/domain/password";
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ describe("Password", () => {
|
|||||||
const lastUsedDate = new Date("2022-01-31T12:00:00.000Z");
|
const lastUsedDate = new Date("2022-01-31T12:00:00.000Z");
|
||||||
|
|
||||||
const actual = Password.fromJSON({
|
const actual = Password.fromJSON({
|
||||||
password: "myPassword",
|
password: "myPassword" as EncryptedString,
|
||||||
lastUsedDate: lastUsedDate.toISOString(),
|
lastUsedDate: lastUsedDate.toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { I18nService } from "../../platform/abstractions/i18n.service";
|
|||||||
import { StateService } from "../../platform/abstractions/state.service";
|
import { StateService } from "../../platform/abstractions/state.service";
|
||||||
import { EncArrayBuffer } from "../../platform/models/domain/enc-array-buffer";
|
import { EncArrayBuffer } from "../../platform/models/domain/enc-array-buffer";
|
||||||
import { EncString } from "../../platform/models/domain/enc-string";
|
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 { CipherFileUploadService } from "../abstractions/file-upload/cipher-file-upload.service";
|
||||||
import { Cipher } from "../models/domain/cipher";
|
import { Cipher } from "../models/domain/cipher";
|
||||||
|
|
||||||
@@ -59,7 +59,9 @@ describe("Cipher Service", () => {
|
|||||||
it("attachments upload encrypted file contents", async () => {
|
it("attachments upload encrypted file contents", async () => {
|
||||||
const fileName = "filename";
|
const fileName = "filename";
|
||||||
const fileData = new Uint8Array(10).buffer;
|
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);
|
await cipherService.saveAttachmentRawWithServer(new Cipher(), fileName, fileData);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-
|
|||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
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 { StateService } from "@bitwarden/common/platform/services/state.service";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||||
@@ -94,7 +94,7 @@ function generateFolderView() {
|
|||||||
function generateFolder() {
|
function generateFolder() {
|
||||||
const actual = Folder.fromJSON({
|
const actual = Folder.fromJSON({
|
||||||
revisionDate: new Date("2022-08-04T01:06:40.441Z").toISOString(),
|
revisionDate: new Date("2022-08-04T01:06:40.441Z").toISOString(),
|
||||||
name: "name",
|
name: "name" as EncryptedString,
|
||||||
id: "id",
|
id: "id",
|
||||||
});
|
});
|
||||||
return actual;
|
return actual;
|
||||||
@@ -217,8 +217,8 @@ describe("VaultExportService", () => {
|
|||||||
mac = Substitute.for<EncString>();
|
mac = Substitute.for<EncString>();
|
||||||
data = Substitute.for<EncString>();
|
data = Substitute.for<EncString>();
|
||||||
|
|
||||||
mac.encryptedString.returns("mac");
|
mac.encryptedString.returns("mac" as EncryptedString);
|
||||||
data.encryptedString.returns("encData");
|
data.encryptedString.returns("encData" as EncryptedString);
|
||||||
|
|
||||||
jest.spyOn(Utils, "fromBufferToB64").mockReturnValue(salt);
|
jest.spyOn(Utils, "fromBufferToB64").mockReturnValue(salt);
|
||||||
cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1));
|
cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1));
|
||||||
|
|||||||
Reference in New Issue
Block a user