mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[PM-18038] Fix safari using outdated biometrics protocol (#13287)
* Fix safari using outdated biometrics protocol * Remove logging * Remove log * Move canEnableBiometricUnlock to biometric service * Fix build * Add tests * Fix type error * Attempt to fix build * Fix build * Fix test failure
This commit is contained in:
@@ -248,6 +248,7 @@ describe("SettingsComponent", () => {
|
||||
describe("biometrics enabled", () => {
|
||||
beforeEach(() => {
|
||||
desktopBiometricsService.getBiometricsStatus.mockResolvedValue(BiometricsStatus.Available);
|
||||
desktopBiometricsService.canEnableBiometricUnlock.mockResolvedValue(true);
|
||||
vaultTimeoutSettingsService.isBiometricLockSet.mockResolvedValue(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -388,24 +388,12 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
});
|
||||
|
||||
this.supportsBiometric = this.shouldAllowBiometricSetup(
|
||||
await this.biometricsService.getBiometricsStatus(),
|
||||
);
|
||||
this.supportsBiometric = await this.biometricsService.canEnableBiometricUnlock();
|
||||
this.timerId = setInterval(async () => {
|
||||
this.supportsBiometric = this.shouldAllowBiometricSetup(
|
||||
await this.biometricsService.getBiometricsStatus(),
|
||||
);
|
||||
this.supportsBiometric = await this.biometricsService.canEnableBiometricUnlock();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private shouldAllowBiometricSetup(biometricStatus: BiometricsStatus): boolean {
|
||||
return [
|
||||
BiometricsStatus.Available,
|
||||
BiometricsStatus.AutoSetupNeeded,
|
||||
BiometricsStatus.ManualSetupNeeded,
|
||||
].includes(biometricStatus);
|
||||
}
|
||||
|
||||
async saveVaultTimeout(newValue: VaultTimeout) {
|
||||
if (newValue === VaultTimeoutStringType.Never) {
|
||||
const confirmed = await this.dialogService.openSimpleDialog({
|
||||
|
||||
@@ -163,4 +163,8 @@ export class MainBiometricsService extends DesktopBiometricsService {
|
||||
async getShouldAutopromptNow(): Promise<boolean> {
|
||||
return this.shouldAutoPrompt;
|
||||
}
|
||||
|
||||
async canEnableBiometricUnlock(): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { BiometricsStatus } from "@bitwarden/key-management";
|
||||
|
||||
import { RendererBiometricsService } from "./renderer-biometrics.service";
|
||||
|
||||
describe("renderer biometrics service tests", function () {
|
||||
beforeEach(() => {
|
||||
(global as any).ipc = {
|
||||
keyManagement: {
|
||||
biometric: {
|
||||
authenticateWithBiometrics: jest.fn(),
|
||||
getBiometricsStatus: jest.fn(),
|
||||
unlockWithBiometricsForUser: jest.fn(),
|
||||
getBiometricsStatusForUser: jest.fn(),
|
||||
deleteBiometricUnlockKeyForUser: jest.fn(),
|
||||
setupBiometrics: jest.fn(),
|
||||
setClientKeyHalfForUser: jest.fn(),
|
||||
getShouldAutoprompt: jest.fn(),
|
||||
setShouldAutoprompt: jest.fn(),
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe("canEnableBiometricUnlock", () => {
|
||||
const table: [BiometricsStatus, boolean][] = [
|
||||
[BiometricsStatus.Available, true],
|
||||
[BiometricsStatus.AutoSetupNeeded, true],
|
||||
[BiometricsStatus.ManualSetupNeeded, true],
|
||||
|
||||
[BiometricsStatus.UnlockNeeded, false],
|
||||
[BiometricsStatus.HardwareUnavailable, false],
|
||||
[BiometricsStatus.PlatformUnsupported, false],
|
||||
[BiometricsStatus.NotEnabledLocally, false],
|
||||
];
|
||||
test.each(table)("canEnableBiometricUnlock(%s) === %s", async (status, expected) => {
|
||||
const service = new RendererBiometricsService();
|
||||
(global as any).ipc.keyManagement.biometric.getBiometricsStatus.mockResolvedValue(status);
|
||||
|
||||
const result = await service.canEnableBiometricUnlock();
|
||||
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -51,4 +51,13 @@ export class RendererBiometricsService extends DesktopBiometricsService {
|
||||
async setShouldAutopromptNow(value: boolean): Promise<void> {
|
||||
return await ipc.keyManagement.biometric.setShouldAutoprompt(value);
|
||||
}
|
||||
|
||||
async canEnableBiometricUnlock(): Promise<boolean> {
|
||||
const biometricStatus = await this.getBiometricsStatus();
|
||||
return [
|
||||
BiometricsStatus.Available,
|
||||
BiometricsStatus.AutoSetupNeeded,
|
||||
BiometricsStatus.ManualSetupNeeded,
|
||||
].includes(biometricStatus);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user