mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
[PAM-574] Vault: CipherService stops messaging the overlay (#24659)
This commit is contained in:
@@ -1226,7 +1226,6 @@ export default class MainBackground {
|
||||
this.accountService,
|
||||
this.logService,
|
||||
this.cipherEncryptionService,
|
||||
this.messagingService,
|
||||
this.cipherSdkService,
|
||||
);
|
||||
this.fillCipherPolicy =
|
||||
|
||||
@@ -992,7 +992,6 @@ export class ServiceContainer {
|
||||
this.accountService,
|
||||
this.logService,
|
||||
this.cipherEncryptionService,
|
||||
this.messagingService,
|
||||
this.cipherSdkService,
|
||||
);
|
||||
|
||||
|
||||
@@ -740,7 +740,6 @@ const safeProviders: SafeProvider[] = [
|
||||
accountService: AccountServiceAbstraction,
|
||||
logService: LogService,
|
||||
cipherEncryptionService: CipherEncryptionService,
|
||||
messagingService: MessagingServiceAbstraction,
|
||||
cipherSdkService: CipherSdkService,
|
||||
) =>
|
||||
new CipherService(
|
||||
@@ -757,7 +756,6 @@ const safeProviders: SafeProvider[] = [
|
||||
accountService,
|
||||
logService,
|
||||
cipherEncryptionService,
|
||||
messagingService,
|
||||
cipherSdkService,
|
||||
),
|
||||
deps: [
|
||||
@@ -774,7 +772,6 @@ const safeProviders: SafeProvider[] = [
|
||||
AccountServiceAbstraction,
|
||||
LogService,
|
||||
CipherEncryptionService,
|
||||
MessagingServiceAbstraction,
|
||||
CipherSdkService,
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -7,9 +7,12 @@ import { CipherView } from "../models/view/cipher.view";
|
||||
* Full views of restricted ciphers. A licensed feature implements it. The default reveals nothing.
|
||||
*
|
||||
* Every implementation must follow these rules:
|
||||
* - Keep the views in process memory only. Never persist them, encrypted or decrypted (no
|
||||
* `StateProvider` key).
|
||||
* - Clear a user's views when that user leaves the unlocked state or logs out, in every process.
|
||||
* - Never write a view to disk, encrypted or decrypted. Keep decrypted views in process memory.
|
||||
* Processes of one client can share an encrypted copy through session memory state (a
|
||||
* `"memory"` `StateDefinition`). Never use `"memory-large-object"`: the MV3 browser backs it with
|
||||
* disk.
|
||||
* - Clear a user's views and shared copies when that user leaves the unlocked state or logs out,
|
||||
* in every process.
|
||||
* - Return only full (not partial) views whose `id` is the requested cipher.
|
||||
* - Never return a view after its reveal ends.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { BehaviorSubject, Observable, filter, firstValueFrom, map, of, throwError } from "rxjs";
|
||||
import { BehaviorSubject, Observable, firstValueFrom, map, of, throwError } from "rxjs";
|
||||
|
||||
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
SymmetricCryptoKey,
|
||||
} from "@bitwarden/legacy-crypto";
|
||||
import { Measurement } from "@bitwarden/logging";
|
||||
import { MessageSender } from "@bitwarden/messaging";
|
||||
import { CipherListView } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { FakeAccountService, mockAccountServiceWith } from "../../../spec/fake-account-service";
|
||||
@@ -110,7 +109,6 @@ describe("Cipher Service", () => {
|
||||
const logService = mock<LogService>({ startMeasurement: () => mock<Measurement>() });
|
||||
const stateProvider = new FakeStateProvider(accountService);
|
||||
const cipherEncryptionService = mock<CipherEncryptionService>();
|
||||
const messageSender = mock<MessageSender>();
|
||||
const cipherSdkService = mock<CipherSdkService>();
|
||||
|
||||
const userId = "TestUserId" as UserId;
|
||||
@@ -151,7 +149,6 @@ describe("Cipher Service", () => {
|
||||
accountService,
|
||||
logService,
|
||||
cipherEncryptionService,
|
||||
messageSender,
|
||||
cipherSdkService,
|
||||
);
|
||||
|
||||
@@ -511,28 +508,6 @@ describe("Cipher Service", () => {
|
||||
newUserKey,
|
||||
);
|
||||
});
|
||||
|
||||
it("sends overlay update when cipherViews$ emits", async () => {
|
||||
(cipherService.cipherViews$ as jest.Mock)?.mockRestore();
|
||||
stateProvider.singleUser
|
||||
.getFake(mockUserId, ENCRYPTED_CIPHERS)
|
||||
.nextState({ [cipherData.id]: cipherData } as Record<CipherId, CipherData>);
|
||||
|
||||
const decryptedView = new CipherView(encryptionContext.cipher);
|
||||
jest
|
||||
.spyOn(cipherService as any, "getAllDecryptedIncludingRestricted")
|
||||
.mockResolvedValue([decryptedView]);
|
||||
|
||||
const sendSpy = jest.spyOn(messageSender, "send");
|
||||
|
||||
await firstValueFrom(
|
||||
cipherService
|
||||
.cipherViews$(mockUserId)
|
||||
.pipe(filter((cipherViews): cipherViews is CipherView[] => cipherViews != null)),
|
||||
);
|
||||
expect(sendSpy).toHaveBeenCalledWith("updateOverlayCiphers");
|
||||
expect(sendSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("decrypt", () => {
|
||||
|
||||
@@ -30,7 +30,6 @@ import { I18nService } from "../../platform/abstractions/i18n.service";
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { FileUploadType } from "../../platform/enums";
|
||||
import { MessageSender } from "../../platform/messaging";
|
||||
import { StateProvider } from "../../platform/state";
|
||||
import { CipherId, CollectionId, OrganizationId, UserId } from "../../types/guid";
|
||||
import { OrgKey, UserKey } from "../../types/key";
|
||||
@@ -97,7 +96,6 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
private accountService: AccountService,
|
||||
private logService: LogService,
|
||||
private cipherEncryptionService: CipherEncryptionService,
|
||||
private messageSender: MessageSender,
|
||||
private cipherSdkService: CipherSdkService,
|
||||
) {}
|
||||
|
||||
@@ -114,8 +112,8 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
|
||||
/**
|
||||
* Decrypted views including restricted ciphers, for derived streams to keep or drop.
|
||||
* Keep this the only full-view decrypt subscription so decryption, the decrypted-cipher cache
|
||||
* and the overlay refresh run once.
|
||||
* Keep this the only full-view decrypt subscription so decryption and the decrypted-cipher cache
|
||||
* run once.
|
||||
*/
|
||||
private cipherViewsIncludingRestricted$ = perUserCache$(
|
||||
(userId: UserId): Observable<CipherView[] | null> => {
|
||||
@@ -126,9 +124,6 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
]).pipe(
|
||||
filter(([ciphers, _, keys]) => ciphers != null && keys != null), // Skip if ciphers haven't been loaded yor synced yet
|
||||
switchMap(() => this.getAllDecryptedIncludingRestricted(userId)),
|
||||
tap(() => {
|
||||
this.messageSender.send("updateOverlayCiphers");
|
||||
}),
|
||||
);
|
||||
},
|
||||
this.clearCipherViewsForUser$,
|
||||
|
||||
Reference in New Issue
Block a user