1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-26 17:43:22 +00:00

Revert "[PM-30319] [BLOCKER] phish cache freeze (#18157)" (#18245)

This reverts commit fcc2844a16.
This commit is contained in:
Tom
2026-01-07 14:25:10 -05:00
committed by GitHub
parent 196db093b2
commit 5832065e96
9 changed files with 124 additions and 543 deletions

View File

@@ -1,6 +1,5 @@
import { mock, MockProxy } from "jest-mock-extended";
import { BehaviorSubject, firstValueFrom, Subject } from "rxjs";
import { filter } from "rxjs/operators";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
@@ -98,32 +97,19 @@ describe("PhishingDetectionSettingsService", () => {
describe("enabled$", () => {
it("should default to true if an account is logged in", async () => {
activeAccountSubject.next(account);
featureFlagSubject.next(true);
premiumStatusSubject.next(true);
organizationsSubject.next([]);
const result = await firstValueFrom(service.enabled$);
expect(result).toBe(true);
});
it("should return the stored value", async () => {
activeAccountSubject.next(account);
featureFlagSubject.next(true);
premiumStatusSubject.next(true);
organizationsSubject.next([]);
// Wait for initial emission (startWith(true))
await firstValueFrom(service.enabled$);
await service.setEnabled(mockUserId, false);
// Wait for the next emission after state update
const resultDisabled = await firstValueFrom(
service.enabled$.pipe(filter((v) => v === false)),
);
const resultDisabled = await firstValueFrom(service.enabled$);
expect(resultDisabled).toBe(false);
await service.setEnabled(mockUserId, true);
// Wait for the next emission after state update
const resultEnabled = await firstValueFrom(service.enabled$.pipe(filter((v) => v === true)));
const resultEnabled = await firstValueFrom(service.enabled$);
expect(resultEnabled).toBe(true);
});
});
@@ -131,21 +117,12 @@ describe("PhishingDetectionSettingsService", () => {
describe("setEnabled", () => {
it("should update the stored value", async () => {
activeAccountSubject.next(account);
featureFlagSubject.next(true);
premiumStatusSubject.next(true);
organizationsSubject.next([]);
// Wait for initial emission (startWith(true))
await firstValueFrom(service.enabled$);
await service.setEnabled(mockUserId, false);
// Wait for the next emission after state update
let result = await firstValueFrom(service.enabled$.pipe(filter((v) => v === false)));
let result = await firstValueFrom(service.enabled$);
expect(result).toBe(false);
await service.setEnabled(mockUserId, true);
// Wait for the next emission after state update
result = await firstValueFrom(service.enabled$.pipe(filter((v) => v === true)));
result = await firstValueFrom(service.enabled$);
expect(result).toBe(true);
});
});

View File

@@ -1,5 +1,5 @@
import { combineLatest, Observable, of, switchMap } from "rxjs";
import { catchError, distinctUntilChanged, map, shareReplay, startWith } from "rxjs/operators";
import { catchError, distinctUntilChanged, map, shareReplay } from "rxjs/operators";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
@@ -18,9 +18,7 @@ const ENABLE_PHISHING_DETECTION = new UserKeyDefinition(
PHISHING_DETECTION_DISK,
"enablePhishingDetection",
{
deserializer: (value: boolean) => {
return value ?? true;
}, // Default: enabled
deserializer: (value: boolean) => value ?? true, // Default: enabled
clearOn: [],
},
);
@@ -99,11 +97,9 @@ export class PhishingDetectionSettingsService implements PhishingDetectionSettin
if (!account) {
return of(false);
}
return this.stateProvider.getUserState$(ENABLE_PHISHING_DETECTION, account.id).pipe(
startWith(true), // Default: enabled (matches deserializer default)
map((enabled) => enabled ?? true),
);
return this.stateProvider.getUserState$(ENABLE_PHISHING_DETECTION, account.id);
}),
map((enabled) => enabled ?? true),
);
}