-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53574ab
commit e240947
Showing
3 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { NgZone } from "@angular/core"; | |
import { mock, MockProxy } from "jest-mock-extended"; | ||
import { of } from "rxjs"; | ||
|
||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; | ||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; | ||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service"; | ||
|
@@ -27,7 +27,7 @@ import { BiometricMessageHandlerService } from "./biometric-message-handler.serv | |
|
||
const SomeUser = "SomeUser" as UserId; | ||
const AnotherUser = "SomeOtherUser" as UserId; | ||
const accounts = { | ||
const accounts: Record<UserId, AccountInfo> = { | ||
[SomeUser]: { | ||
name: "some user", | ||
email: "[email protected]", | ||
|
@@ -108,13 +108,38 @@ describe("BiometricMessageHandlerService", () => { | |
}); | ||
|
||
describe("setup encryption", () => { | ||
it("should ignore when public key missing in message", async () => { | ||
await service.handleMessage({ | ||
appId: "appId", | ||
message: { | ||
command: "setupEncryption", | ||
messageId: 0, | ||
userId: "unknownUser" as UserId, | ||
}, | ||
}); | ||
expect((global as any).ipc.platform.nativeMessaging.sendMessage).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should ignore when user id missing in message", async () => { | ||
await service.handleMessage({ | ||
appId: "appId", | ||
message: { | ||
command: "setupEncryption", | ||
messageId: 0, | ||
publicKey: Utils.fromUtf8ToB64("publicKey"), | ||
}, | ||
}); | ||
expect((global as any).ipc.platform.nativeMessaging.sendMessage).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should reject when user is not in app", async () => { | ||
await service.handleMessage({ | ||
appId: "appId", | ||
message: { | ||
command: "setupEncryption", | ||
messageId: 0, | ||
userId: "unknownUser" as UserId, | ||
publicKey: Utils.fromUtf8ToB64("publicKey"), | ||
}, | ||
}); | ||
expect((global as any).ipc.platform.nativeMessaging.sendMessage).toHaveBeenCalledWith({ | ||
|
@@ -362,12 +387,15 @@ describe("BiometricMessageHandlerService", () => { | |
// always reload when another user is active than the requested one | ||
[SomeUser, AuthenticationStatus.Unlocked, AnotherUser, false, true], | ||
[SomeUser, AuthenticationStatus.Locked, AnotherUser, false, true], | ||
// don't reload when no active user | ||
[null, AuthenticationStatus.Unlocked, AnotherUser, false, false], | ||
|
||
// don't reload in dev mode | ||
[SomeUser, AuthenticationStatus.Unlocked, SomeUser, true, false], | ||
[SomeUser, AuthenticationStatus.Locked, SomeUser, true, false], | ||
[SomeUser, AuthenticationStatus.Unlocked, AnotherUser, true, false], | ||
[SomeUser, AuthenticationStatus.Locked, AnotherUser, true, false], | ||
[null, AuthenticationStatus.Unlocked, AnotherUser, true, false], | ||
]; | ||
|
||
it.each(testCases)( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters