mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
[PM-17745] Catch network errors in new device notification guard (#13161)
* [PM-17745] Wrap new device guard applicability check in try/catch to prevent crashes from network errors * [PM-17745] Fix broken test
This commit is contained in:
@@ -36,7 +36,7 @@ describe("NewDeviceVerificationNoticeGuard", () => {
|
|||||||
|
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
});
|
});
|
||||||
const isSelfHost = jest.fn().mockResolvedValue(false);
|
const isSelfHost = jest.fn().mockReturnValue(false);
|
||||||
const getProfileTwoFactorEnabled = jest.fn().mockResolvedValue(false);
|
const getProfileTwoFactorEnabled = jest.fn().mockResolvedValue(false);
|
||||||
const policyAppliesToActiveUser$ = jest.fn().mockReturnValue(new BehaviorSubject<boolean>(false));
|
const policyAppliesToActiveUser$ = jest.fn().mockReturnValue(new BehaviorSubject<boolean>(false));
|
||||||
const noticeState$ = jest.fn().mockReturnValue(new BehaviorSubject(null));
|
const noticeState$ = jest.fn().mockReturnValue(new BehaviorSubject(null));
|
||||||
@@ -139,6 +139,12 @@ describe("NewDeviceVerificationNoticeGuard", () => {
|
|||||||
expect(await newDeviceGuard()).toBe(true);
|
expect(await newDeviceGuard()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns `true` when the profile service throws an error", async () => {
|
||||||
|
getProfileCreationDate.mockRejectedValueOnce(new Error("test"));
|
||||||
|
|
||||||
|
expect(await newDeviceGuard()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
describe("temp flag", () => {
|
describe("temp flag", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
getFeatureFlag.mockImplementation((key) => {
|
getFeatureFlag.mockImplementation((key) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { inject } from "@angular/core";
|
import { inject } from "@angular/core";
|
||||||
import { ActivatedRouteSnapshot, CanActivateFn, Router } from "@angular/router";
|
import { ActivatedRouteSnapshot, CanActivateFn, Router } from "@angular/router";
|
||||||
import { Observable, firstValueFrom } from "rxjs";
|
import { firstValueFrom, Observable } from "rxjs";
|
||||||
|
|
||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||||
@@ -47,9 +47,10 @@ export const NewDeviceVerificationNoticeGuard: CanActivateFn = async (
|
|||||||
return router.createUrlTree(["/login"]);
|
return router.createUrlTree(["/login"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const has2FAEnabled = await hasATwoFactorProviderEnabled(vaultProfileService, currentAcct.id);
|
try {
|
||||||
const isSelfHosted = await platformUtilsService.isSelfHost();
|
const isSelfHosted = platformUtilsService.isSelfHost();
|
||||||
const requiresSSO = await isSSORequired(policyService);
|
const requiresSSO = await isSSORequired(policyService);
|
||||||
|
const has2FAEnabled = await hasATwoFactorProviderEnabled(vaultProfileService, currentAcct.id);
|
||||||
const isProfileLessThanWeekOld = await profileIsLessThanWeekOld(
|
const isProfileLessThanWeekOld = await profileIsLessThanWeekOld(
|
||||||
vaultProfileService,
|
vaultProfileService,
|
||||||
currentAcct.id,
|
currentAcct.id,
|
||||||
@@ -60,6 +61,11 @@ export const NewDeviceVerificationNoticeGuard: CanActivateFn = async (
|
|||||||
if (has2FAEnabled || isSelfHosted || requiresSSO || isProfileLessThanWeekOld) {
|
if (has2FAEnabled || isSelfHosted || requiresSSO || isProfileLessThanWeekOld) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Skip showing the notice if there was a problem determining applicability
|
||||||
|
// The most likely problem to occur is the user not having a network connection
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const userItems$ = newDeviceVerificationNoticeService.noticeState$(currentAcct.id);
|
const userItems$ = newDeviceVerificationNoticeService.noticeState$(currentAcct.id);
|
||||||
const userItems = await firstValueFrom(userItems$);
|
const userItems = await firstValueFrom(userItems$);
|
||||||
|
|||||||
Reference in New Issue
Block a user