mirror of
https://github.com/bitwarden/browser
synced 2026-02-06 03:33:30 +00:00
Fix test
This commit is contained in:
@@ -7,7 +7,7 @@ import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { passwords } from "@bitwarden/desktop-napi";
|
||||
import { BiometricStateService } from "@bitwarden/key-management";
|
||||
|
||||
import OsBiometricsServiceLinux from "../os-biometrics-linux.service";
|
||||
import { default as OsBiometricsServiceLinux } from "./os-biometrics-linux.service";
|
||||
|
||||
jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
biometrics: {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { passwords } from "@bitwarden/desktop-napi";
|
||||
|
||||
import OsBiometricsServiceMac from "./os-biometrics-mac.service";
|
||||
import { default as OsBiometricsServiceMac } from "./os-biometrics-mac.service";
|
||||
|
||||
jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
biometrics: {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { BiometricsStatus, BiometricStateService } from "@bitwarden/key-manageme
|
||||
|
||||
import { WindowMain } from "../../../main/window.main";
|
||||
|
||||
import OsBiometricsServiceWindows from "./os-biometrics-windows.service";
|
||||
import { default as OsBiometricsServiceWindows } from "./os-biometrics-windows.service";
|
||||
|
||||
import OsDerivedKey = biometrics.OsDerivedKey;
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { biometrics, passwords } from "@bitwarden/desktop-napi";
|
||||
import { biometrics_v2, passwords } from "@bitwarden/desktop-napi";
|
||||
import { BiometricsStatus } from "@bitwarden/key-management";
|
||||
|
||||
import OsBiometricsServiceLinux from "./os-biometrics-linux.service";
|
||||
|
||||
jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
biometrics: {
|
||||
biometrics_v2: {
|
||||
initBiometricSystem: jest.fn(() => "mockSystem"),
|
||||
provideKey: jest.fn(),
|
||||
unenroll: jest.fn(),
|
||||
@@ -22,7 +22,7 @@ jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
|
||||
const mockKey = new Uint8Array(64);
|
||||
|
||||
jest.mock("../../utils", () => ({
|
||||
jest.mock("../../../utils", () => ({
|
||||
isFlatpak: jest.fn(() => false),
|
||||
isLinux: jest.fn(() => true),
|
||||
isSnapStore: jest.fn(() => false),
|
||||
@@ -40,28 +40,28 @@ describe("OsBiometricsServiceLinux", () => {
|
||||
|
||||
it("should set biometric key", async () => {
|
||||
await service.setBiometricKey(userId, key);
|
||||
expect(biometrics.provideKey).toHaveBeenCalled();
|
||||
expect(biometrics_v2.provideKey).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should delete biometric key", async () => {
|
||||
await service.deleteBiometricKey(userId);
|
||||
expect(biometrics.unenroll).toHaveBeenCalled();
|
||||
expect(biometrics_v2.unenroll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should get biometric key", async () => {
|
||||
(biometrics.unlock as jest.Mock).mockResolvedValue(mockKey);
|
||||
(biometrics_v2.unlock as jest.Mock).mockResolvedValue(mockKey);
|
||||
const result = await service.getBiometricKey(userId);
|
||||
expect(result).toBeInstanceOf(SymmetricCryptoKey);
|
||||
});
|
||||
|
||||
it("should return null if no biometric key", async () => {
|
||||
(biometrics.unlock as jest.Mock).mockResolvedValue(null);
|
||||
(biometrics_v2.unlock as jest.Mock).mockResolvedValue(null);
|
||||
const result = await service.getBiometricKey(userId);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should authenticate biometric", async () => {
|
||||
(biometrics.authenticate as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.authenticate as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.authenticateBiometric();
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -73,7 +73,7 @@ describe("OsBiometricsServiceLinux", () => {
|
||||
});
|
||||
|
||||
it("should check if setup is needed", async () => {
|
||||
(biometrics.authenticateAvailable as jest.Mock).mockResolvedValue(false);
|
||||
(biometrics_v2.authenticateAvailable as jest.Mock).mockResolvedValue(false);
|
||||
const result = await service.needsSetup();
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -84,7 +84,7 @@ describe("OsBiometricsServiceLinux", () => {
|
||||
});
|
||||
|
||||
it("should get biometrics first unlock status for user", async () => {
|
||||
(biometrics.unlockAvailable as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.unlockAvailable as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.getBiometricsFirstUnlockStatusForUser(userId);
|
||||
expect(result).toBe(BiometricsStatus.Available);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import { passwords } from "@bitwarden/desktop-napi";
|
||||
import OsBiometricsServiceMac from "./os-biometrics-mac.service";
|
||||
|
||||
jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
biometrics: {
|
||||
biometrics_v2: {
|
||||
setBiometricSecret: jest.fn(),
|
||||
getBiometricSecret: jest.fn(),
|
||||
deleteBiometricSecret: jest.fn(),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { mock } from "jest-mock-extended";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { biometrics } from "@bitwarden/desktop-napi";
|
||||
import { biometrics_v2 } from "@bitwarden/desktop-napi";
|
||||
import { BiometricsStatus } from "@bitwarden/key-management";
|
||||
|
||||
import { WindowMain } from "../../main/window.main";
|
||||
@@ -11,7 +11,7 @@ import { WindowMain } from "../../main/window.main";
|
||||
import OsBiometricsServiceWindows from "./os-biometrics-windows.service";
|
||||
|
||||
jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
biometrics: {
|
||||
biometrics_v2: {
|
||||
initBiometricSystem: jest.fn(() => "mockSystem"),
|
||||
provideKey: jest.fn(),
|
||||
enrollPersistent: jest.fn(),
|
||||
@@ -29,7 +29,7 @@ jest.mock("@bitwarden/desktop-napi", () => ({
|
||||
|
||||
const mockKey = new Uint8Array(64);
|
||||
|
||||
jest.mock("../../utils", () => ({
|
||||
jest.mock("../../../utils", () => ({
|
||||
isFlatpak: jest.fn(() => false),
|
||||
isLinux: jest.fn(() => true),
|
||||
isSnapStore: jest.fn(() => false),
|
||||
@@ -51,39 +51,39 @@ describe("OsBiometricsServiceWindows", () => {
|
||||
|
||||
it("should enroll persistent biometric key", async () => {
|
||||
await service.enrollPersistent("user-id" as UserId, new SymmetricCryptoKey(mockKey));
|
||||
expect(biometrics.enrollPersistent).toHaveBeenCalled();
|
||||
expect(biometrics_v2.enrollPersistent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should set biometric key", async () => {
|
||||
await service.setBiometricKey(userId, new SymmetricCryptoKey(mockKey));
|
||||
expect(biometrics.provideKey).toHaveBeenCalled();
|
||||
expect(biometrics_v2.provideKey).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should delete biometric key", async () => {
|
||||
await service.deleteBiometricKey(userId);
|
||||
expect(biometrics.unenroll).toHaveBeenCalled();
|
||||
expect(biometrics_v2.unenroll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should get biometric key", async () => {
|
||||
(biometrics.unlock as jest.Mock).mockResolvedValue(mockKey);
|
||||
(biometrics_v2.unlock as jest.Mock).mockResolvedValue(mockKey);
|
||||
const result = await service.getBiometricKey(userId);
|
||||
expect(result).toBeInstanceOf(SymmetricCryptoKey);
|
||||
});
|
||||
|
||||
it("should return null if no biometric key", async () => {
|
||||
(biometrics.unlock as jest.Mock).mockRejectedValue(new Error("No key found"));
|
||||
(biometrics_v2.unlock as jest.Mock).mockRejectedValue(new Error("No key found"));
|
||||
const result = await service.getBiometricKey(userId);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should authenticate biometric", async () => {
|
||||
(biometrics.authenticate as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.authenticate as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.authenticateBiometric();
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should check if biometrics is supported", async () => {
|
||||
(biometrics.authenticateAvailable as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.authenticateAvailable as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.supportsBiometrics();
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -99,19 +99,19 @@ describe("OsBiometricsServiceWindows", () => {
|
||||
});
|
||||
|
||||
it("should get biometrics first unlock status for user", async () => {
|
||||
(biometrics.unlockAvailable as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.unlockAvailable as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.getBiometricsFirstUnlockStatusForUser(userId);
|
||||
expect(result).toBe(BiometricsStatus.Available);
|
||||
});
|
||||
|
||||
it("should return false for hasPersistentKey false", async () => {
|
||||
(biometrics.hasPersistent as jest.Mock).mockResolvedValue(false);
|
||||
(biometrics_v2.hasPersistent as jest.Mock).mockResolvedValue(false);
|
||||
const result = await service.hasPersistentKey(userId);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false for hasPersistentKey true", async () => {
|
||||
(biometrics.hasPersistent as jest.Mock).mockResolvedValue(true);
|
||||
(biometrics_v2.hasPersistent as jest.Mock).mockResolvedValue(true);
|
||||
const result = await service.hasPersistentKey(userId);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user