Renamed key to storageKey and fixed tests.
This commit is contained in:
parent
5ad0e87093
commit
025b3f649a
|
@ -40,15 +40,15 @@ describe("biometrics tests", function () {
|
|||
|
||||
const mockService = mock<OsBiometricService>();
|
||||
(sut as any).platformSpecificService = mockService;
|
||||
await sut.setEncryptionKeyHalf({ service: "test", key: "test", value: "test" });
|
||||
await sut.setEncryptionKeyHalf({ service: "test", storageKey: "test", value: "test" });
|
||||
|
||||
await sut.canAuthBiometric({ service: "test", key: "test", userId });
|
||||
expect(mockService.osSupportsBiometric).toBeCalled();
|
||||
await sut.canAuthBiometric({ service: "test", storageKey: "test", userId });
|
||||
expect(mockService.osSupportsBiometric).toHaveBeenCalled();
|
||||
|
||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sut.authenticateBiometric();
|
||||
expect(mockService.authenticateBiometric).toBeCalled();
|
||||
expect(mockService.authenticateBiometric).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("Should create a platform specific service", function () {
|
||||
|
@ -104,7 +104,7 @@ describe("biometrics tests", function () {
|
|||
it("should return false if client key half is required and not provided", async () => {
|
||||
biometricStateService.getRequirePasswordOnStart.mockResolvedValue(true);
|
||||
|
||||
const result = await sut.canAuthBiometric({ service: "test", key: "test", userId });
|
||||
const result = await sut.canAuthBiometric({ service: "test", storageKey: "test", userId });
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
@ -112,17 +112,17 @@ describe("biometrics tests", function () {
|
|||
it("should call osSupportsBiometric if client key half is provided", async () => {
|
||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sut.setEncryptionKeyHalf({ service: "test", key: "test", value: "test" });
|
||||
sut.setEncryptionKeyHalf({ service: "test", storageKey: "test", value: "test" });
|
||||
|
||||
await sut.canAuthBiometric({ service: "test", key: "test", userId });
|
||||
expect(innerService.osSupportsBiometric).toBeCalled();
|
||||
await sut.canAuthBiometric({ service: "test", storageKey: "test", userId });
|
||||
expect(innerService.osSupportsBiometric).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should call osSupportBiometric if client key half is not required", async () => {
|
||||
biometricStateService.getRequirePasswordOnStart.mockResolvedValue(false);
|
||||
innerService.osSupportsBiometric.mockResolvedValue(true);
|
||||
|
||||
const result = await sut.canAuthBiometric({ service: "test", key: "test", userId });
|
||||
const result = await sut.canAuthBiometric({ service: "test", storageKey: "test", userId });
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(innerService.osSupportsBiometric).toHaveBeenCalled();
|
||||
|
|
|
@ -61,15 +61,15 @@ export class BiometricsService implements BiometricsServiceAbstraction {
|
|||
|
||||
async canAuthBiometric({
|
||||
service,
|
||||
key,
|
||||
storageKey,
|
||||
userId,
|
||||
}: {
|
||||
service: string;
|
||||
key: string;
|
||||
storageKey: string;
|
||||
userId: UserId;
|
||||
}): Promise<boolean> {
|
||||
const requireClientKeyHalf = await this.biometricStateService.getRequirePasswordOnStart(userId);
|
||||
const clientKeyHalfB64 = this.getClientKeyHalf(service, key);
|
||||
const clientKeyHalfB64 = this.getClientKeyHalf(service, storageKey);
|
||||
const clientKeyHalfSatisfied = !requireClientKeyHalf || !!clientKeyHalfB64;
|
||||
return clientKeyHalfSatisfied && (await this.osSupportsBiometric());
|
||||
}
|
||||
|
@ -159,12 +159,12 @@ export class BiometricsService implements BiometricsServiceAbstraction {
|
|||
return response;
|
||||
}
|
||||
|
||||
private clientKeyHalfKey(service: string, key: string): string {
|
||||
return `${service}:${key}`;
|
||||
private clientKeyHalfKey(service: string, storageKey: string): string {
|
||||
return `${service}:${storageKey}`;
|
||||
}
|
||||
|
||||
private getClientKeyHalf(service: string, key: string): string | undefined {
|
||||
return this.clientKeyHalves.get(this.clientKeyHalfKey(service, key)) ?? undefined;
|
||||
private getClientKeyHalf(service: string, storageKey: string): string | undefined {
|
||||
return this.clientKeyHalves.get(this.clientKeyHalfKey(service, storageKey)) ?? undefined;
|
||||
}
|
||||
|
||||
private async enforceClientKeyHalf(service: string, storageKey: string): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue