Auth/PM-13945 - Extension - Fix TDE User with MP can't navigate to Lock Screen (#11700)

* PM-13945 - Extension Refresh redirects should persist query params as we use query params to execute guard logic (e.g., lockGuard). The loss of the from: login-initiated query param prevented navigation to the lock screen.

* PM-13945 - Test updated
This commit is contained in:
Jared Snider 2024-10-25 11:29:48 -04:00 committed by GitHub
parent 3b82a82416
commit fa537638bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { TestBed } from "@angular/core/testing";
import { Router, UrlTree } from "@angular/router";
import { Navigation, Router, UrlTree } from "@angular/router";
import { mock, MockProxy } from "jest-mock-extended";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
@ -37,19 +37,29 @@ describe("unauthUiRefreshRedirect", () => {
expect(router.parseUrl).not.toHaveBeenCalled();
});
it("returns UrlTree when UnauthenticatedExtensionUIRefresh flag is enabled", async () => {
const mockUrlTree = mock<UrlTree>();
it("returns UrlTree when UnauthenticatedExtensionUIRefresh flag is enabled and preserves query params", async () => {
configService.getFeatureFlag.mockResolvedValue(true);
router.parseUrl.mockReturnValue(mockUrlTree);
const result = await TestBed.runInInjectionContext(() =>
unauthUiRefreshRedirect("/redirect")(),
);
const queryParams = { test: "test" };
const navigation: Navigation = {
extras: {
queryParams: queryParams,
},
id: 0,
initialUrl: new UrlTree(),
extractedUrl: new UrlTree(),
trigger: "imperative",
previousNavigation: undefined,
};
router.getCurrentNavigation.mockReturnValue(navigation);
await TestBed.runInInjectionContext(() => unauthUiRefreshRedirect("/redirect")());
expect(result).toBe(mockUrlTree);
expect(configService.getFeatureFlag).toHaveBeenCalledWith(
FeatureFlag.UnauthenticatedExtensionUIRefresh,
);
expect(router.parseUrl).toHaveBeenCalledWith("/redirect");
expect(router.createUrlTree).toHaveBeenCalledWith(["/redirect"], { queryParams });
});
});

View File

@ -16,7 +16,12 @@ export function unauthUiRefreshRedirect(redirectUrl: string): () => Promise<bool
FeatureFlag.UnauthenticatedExtensionUIRefresh,
);
if (shouldRedirect) {
return router.parseUrl(redirectUrl);
const currentNavigation = router.getCurrentNavigation();
const queryParams = currentNavigation?.extras?.queryParams || {};
// Preserve query params when redirecting as it is likely that the refreshed component
// will be consuming the same query params.
return router.createUrlTree([redirectUrl], { queryParams });
} else {
return true;
}

View File

@ -12,9 +12,15 @@ export function extensionRefreshRedirect(redirectUrl: string): () => Promise<boo
return async () => {
const configService = inject(ConfigService);
const router = inject(Router);
const shouldRedirect = await configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
if (shouldRedirect) {
return router.parseUrl(redirectUrl);
const currentNavigation = router.getCurrentNavigation();
const queryParams = currentNavigation?.extras?.queryParams || {};
// Preserve query params when redirecting as it is likely that the refreshed component
// will be consuming the same query params.
return router.createUrlTree([redirectUrl], { queryParams });
} else {
return true;
}