mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
PM-23890 Update overlays when a cipher is deleted (#15800)
* PM-23890 WIP * add messaging service references * Revert "PM-19574 Browser Autofill overlay displays outdated data (#15624)" This reverts commit9eceaa3d4c. * add test * fix merge spacing * Revert "Revert "PM-19574 Browser Autofill overlay displays outdated data (#15624)"" This reverts commit0fc6ec4d0b.
This commit is contained in:
@@ -245,6 +245,7 @@ export type OverlayBackgroundExtensionMessageHandlers = {
|
|||||||
editedCipher: () => void;
|
editedCipher: () => void;
|
||||||
deletedCipher: () => void;
|
deletedCipher: () => void;
|
||||||
bgSaveCipher: () => void;
|
bgSaveCipher: () => void;
|
||||||
|
updateOverlayCiphers: () => void;
|
||||||
fido2AbortRequest: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
fido2AbortRequest: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
editedCipher: () => this.updateOverlayCiphers(),
|
editedCipher: () => this.updateOverlayCiphers(),
|
||||||
deletedCipher: () => this.updateOverlayCiphers(),
|
deletedCipher: () => this.updateOverlayCiphers(),
|
||||||
bgSaveCipher: () => this.updateOverlayCiphers(),
|
bgSaveCipher: () => this.updateOverlayCiphers(),
|
||||||
|
updateOverlayCiphers: () => this.updateOverlayCiphers(),
|
||||||
fido2AbortRequest: ({ sender }) => this.abortFido2ActiveRequest(sender.tab.id),
|
fido2AbortRequest: ({ sender }) => this.abortFido2ActiveRequest(sender.tab.id),
|
||||||
};
|
};
|
||||||
private readonly inlineMenuButtonPortMessageHandlers: InlineMenuButtonPortMessageHandlers = {
|
private readonly inlineMenuButtonPortMessageHandlers: InlineMenuButtonPortMessageHandlers = {
|
||||||
|
|||||||
@@ -898,6 +898,7 @@ export default class MainBackground {
|
|||||||
this.accountService,
|
this.accountService,
|
||||||
this.logService,
|
this.logService,
|
||||||
this.cipherEncryptionService,
|
this.cipherEncryptionService,
|
||||||
|
this.messagingService,
|
||||||
);
|
);
|
||||||
this.folderService = new FolderService(
|
this.folderService = new FolderService(
|
||||||
this.keyService,
|
this.keyService,
|
||||||
|
|||||||
@@ -723,6 +723,7 @@ export class ServiceContainer {
|
|||||||
this.accountService,
|
this.accountService,
|
||||||
this.logService,
|
this.logService,
|
||||||
this.cipherEncryptionService,
|
this.cipherEncryptionService,
|
||||||
|
this.messagingService,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.folderService = new FolderService(
|
this.folderService = new FolderService(
|
||||||
|
|||||||
@@ -537,6 +537,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
accountService: AccountServiceAbstraction,
|
accountService: AccountServiceAbstraction,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
cipherEncryptionService: CipherEncryptionService,
|
cipherEncryptionService: CipherEncryptionService,
|
||||||
|
messagingService: MessagingServiceAbstraction,
|
||||||
) =>
|
) =>
|
||||||
new CipherService(
|
new CipherService(
|
||||||
keyService,
|
keyService,
|
||||||
@@ -553,6 +554,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
accountService,
|
accountService,
|
||||||
logService,
|
logService,
|
||||||
cipherEncryptionService,
|
cipherEncryptionService,
|
||||||
|
messagingService,
|
||||||
),
|
),
|
||||||
deps: [
|
deps: [
|
||||||
KeyService,
|
KeyService,
|
||||||
@@ -569,6 +571,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
AccountServiceAbstraction,
|
AccountServiceAbstraction,
|
||||||
LogService,
|
LogService,
|
||||||
CipherEncryptionService,
|
CipherEncryptionService,
|
||||||
|
MessagingServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
import { BehaviorSubject, map, of } from "rxjs";
|
import { BehaviorSubject, filter, firstValueFrom, map, of } from "rxjs";
|
||||||
|
|
||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -7,6 +7,7 @@ import { CipherResponse } from "@bitwarden/common/vault/models/response/cipher.r
|
|||||||
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
|
// 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
|
// eslint-disable-next-line no-restricted-imports
|
||||||
import { CipherDecryptionKeys, KeyService } from "@bitwarden/key-management";
|
import { CipherDecryptionKeys, KeyService } from "@bitwarden/key-management";
|
||||||
|
import { MessageSender } from "@bitwarden/messaging";
|
||||||
|
|
||||||
import { FakeAccountService, mockAccountServiceWith } from "../../../spec/fake-account-service";
|
import { FakeAccountService, mockAccountServiceWith } from "../../../spec/fake-account-service";
|
||||||
import { FakeStateProvider } from "../../../spec/fake-state-provider";
|
import { FakeStateProvider } from "../../../spec/fake-state-provider";
|
||||||
@@ -106,6 +107,7 @@ describe("Cipher Service", () => {
|
|||||||
const logService = mock<LogService>();
|
const logService = mock<LogService>();
|
||||||
const stateProvider = new FakeStateProvider(accountService);
|
const stateProvider = new FakeStateProvider(accountService);
|
||||||
const cipherEncryptionService = mock<CipherEncryptionService>();
|
const cipherEncryptionService = mock<CipherEncryptionService>();
|
||||||
|
const messageSender = mock<MessageSender>();
|
||||||
|
|
||||||
const userId = "TestUserId" as UserId;
|
const userId = "TestUserId" as UserId;
|
||||||
const orgId = "4ff8c0b2-1d3e-4f8c-9b2d-1d3e4f8c0b2" as OrganizationId;
|
const orgId = "4ff8c0b2-1d3e-4f8c-9b2d-1d3e4f8c0b2" as OrganizationId;
|
||||||
@@ -134,6 +136,7 @@ describe("Cipher Service", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
logService,
|
logService,
|
||||||
cipherEncryptionService,
|
cipherEncryptionService,
|
||||||
|
messageSender,
|
||||||
);
|
);
|
||||||
|
|
||||||
encryptionContext = { cipher: new Cipher(cipherData), encryptedFor: userId };
|
encryptionContext = { cipher: new Cipher(cipherData), encryptedFor: userId };
|
||||||
@@ -551,6 +554,23 @@ describe("Cipher Service", () => {
|
|||||||
newUserKey,
|
newUserKey,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("sends overlay update when cipherViews$ emits", async () => {
|
||||||
|
(cipherService.cipherViews$ as jest.Mock)?.mockRestore();
|
||||||
|
|
||||||
|
const decryptedView = new CipherView(encryptionContext.cipher);
|
||||||
|
jest.spyOn(cipherService, "getAllDecrypted").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", () => {
|
describe("decrypt", () => {
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import { combineLatest, filter, firstValueFrom, map, Observable, Subject, switchMap } from "rxjs";
|
import {
|
||||||
|
combineLatest,
|
||||||
|
filter,
|
||||||
|
firstValueFrom,
|
||||||
|
map,
|
||||||
|
Observable,
|
||||||
|
Subject,
|
||||||
|
switchMap,
|
||||||
|
tap,
|
||||||
|
} from "rxjs";
|
||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
|
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
|
import { MessageSender } from "@bitwarden/common/platform/messaging";
|
||||||
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
|
// 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
|
// eslint-disable-next-line no-restricted-imports
|
||||||
import { KeyService } from "@bitwarden/key-management";
|
import { KeyService } from "@bitwarden/key-management";
|
||||||
@@ -109,6 +119,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private cipherEncryptionService: CipherEncryptionService,
|
private cipherEncryptionService: CipherEncryptionService,
|
||||||
|
private messageSender: MessageSender,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
localData$(userId: UserId): Observable<Record<CipherId, LocalData>> {
|
localData$(userId: UserId): Observable<Record<CipherId, LocalData>> {
|
||||||
@@ -174,6 +185,10 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
]).pipe(
|
]).pipe(
|
||||||
filter(([ciphers, _, keys]) => ciphers != null && keys != null), // Skip if ciphers haven't been loaded yor synced yet
|
filter(([ciphers, _, keys]) => ciphers != null && keys != null), // Skip if ciphers haven't been loaded yor synced yet
|
||||||
switchMap(() => this.getAllDecrypted(userId)),
|
switchMap(() => this.getAllDecrypted(userId)),
|
||||||
|
tap(async (decrypted) => {
|
||||||
|
await this.searchService.indexCiphers(userId, decrypted);
|
||||||
|
this.messageSender.send("updateOverlayCiphers");
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}, this.clearCipherViewsForUser$);
|
}, this.clearCipherViewsForUser$);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user