Honor baseUrl when generating the client home URL in the Admin Console (#34016)

Closes #34015

Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
This commit is contained in:
Thomas Darimont 2024-10-18 12:22:07 +02:00 committed by GitHub
parent ac6def6197
commit c7bcb26949
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 5 deletions

View file

@ -1278,6 +1278,25 @@ describe("Clients test", () => {
}); });
}); });
describe("Generated home URLs for built-in clients", () => {
beforeEach(() => {
loginPage.logIn();
keycloakBefore();
commonPage.sidebar().goToRealm(realmName);
commonPage.sidebar().goToClients();
});
it("Check account-console Home URL", () => {
cy.findByTestId("client-home-url-account-console").contains("/account/");
});
it("Check security-admin-console Home URL", () => {
cy.findByTestId("client-home-url-security-admin-console").contains(
"/console/",
);
});
});
describe("Accessibility tests for clients", () => { describe("Accessibility tests for clients", () => {
const clientId = "a11y-client"; const clientId = "a11y-client";

View file

@ -92,7 +92,12 @@ const ClientHomeLink = (client: ClientRepresentation) => {
return "—"; return "—";
} }
return <FormattedLink href={href} />; return (
<FormattedLink
href={href}
data-testid={`client-home-url-${client.clientId}`}
/>
);
}; };
const ToolbarItems = () => { const ToolbarItems = () => {

View file

@ -17,17 +17,17 @@ describe("convertClientToUrl", () => {
it("when root url constrains ${authAdminUrl}", () => { it("when root url constrains ${authAdminUrl}", () => {
//given //given
const rootUrl = "${authAdminUrl}"; const rootUrl = "${authAdminUrl}";
const adminUrl = "/else"; const baseUrl = "/else";
//when //when
const result = convertClientToUrl( const result = convertClientToUrl(
{ rootUrl, adminUrl }, { rootUrl, baseUrl },
//@ts-ignore //@ts-ignore
{ adminBaseUrl: "/admin" }, { adminBaseUrl: "/admin" },
); );
//then //then
expect(result).toBe("/admin"); expect(result).toBe("/admin/else");
}); });
it("when root url constrains ${authBaseUrl}", () => { it("when root url constrains ${authBaseUrl}", () => {

View file

@ -12,7 +12,10 @@ export const convertClientToUrl = (
} }
if (rootUrl === "${authAdminUrl}") { if (rootUrl === "${authAdminUrl}") {
return rootUrl.replace(/\$\{(authAdminUrl)\}/, environment.adminBaseUrl); return joinPath(
rootUrl.replace(/\$\{(authAdminUrl)\}/, environment.adminBaseUrl),
baseUrl || "",
);
} }
if (rootUrl === "${authBaseUrl}") { if (rootUrl === "${authBaseUrl}") {