mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-25 12:15:18 +01:00
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:
parent
3b82a82416
commit
fa537638bf
@ -1,5 +1,5 @@
|
|||||||
import { TestBed } from "@angular/core/testing";
|
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 { mock, MockProxy } from "jest-mock-extended";
|
||||||
|
|
||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
@ -37,19 +37,29 @@ describe("unauthUiRefreshRedirect", () => {
|
|||||||
expect(router.parseUrl).not.toHaveBeenCalled();
|
expect(router.parseUrl).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns UrlTree when UnauthenticatedExtensionUIRefresh flag is enabled", async () => {
|
it("returns UrlTree when UnauthenticatedExtensionUIRefresh flag is enabled and preserves query params", async () => {
|
||||||
const mockUrlTree = mock<UrlTree>();
|
|
||||||
configService.getFeatureFlag.mockResolvedValue(true);
|
configService.getFeatureFlag.mockResolvedValue(true);
|
||||||
router.parseUrl.mockReturnValue(mockUrlTree);
|
|
||||||
|
|
||||||
const result = await TestBed.runInInjectionContext(() =>
|
const queryParams = { test: "test" };
|
||||||
unauthUiRefreshRedirect("/redirect")(),
|
|
||||||
);
|
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(
|
expect(configService.getFeatureFlag).toHaveBeenCalledWith(
|
||||||
FeatureFlag.UnauthenticatedExtensionUIRefresh,
|
FeatureFlag.UnauthenticatedExtensionUIRefresh,
|
||||||
);
|
);
|
||||||
expect(router.parseUrl).toHaveBeenCalledWith("/redirect");
|
expect(router.createUrlTree).toHaveBeenCalledWith(["/redirect"], { queryParams });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,12 @@ export function unauthUiRefreshRedirect(redirectUrl: string): () => Promise<bool
|
|||||||
FeatureFlag.UnauthenticatedExtensionUIRefresh,
|
FeatureFlag.UnauthenticatedExtensionUIRefresh,
|
||||||
);
|
);
|
||||||
if (shouldRedirect) {
|
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 {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,15 @@ export function extensionRefreshRedirect(redirectUrl: string): () => Promise<boo
|
|||||||
return async () => {
|
return async () => {
|
||||||
const configService = inject(ConfigService);
|
const configService = inject(ConfigService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
|
|
||||||
const shouldRedirect = await configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
|
const shouldRedirect = await configService.getFeatureFlag(FeatureFlag.ExtensionRefresh);
|
||||||
if (shouldRedirect) {
|
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 {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user