-
Notifications
You must be signed in to change notification settings - Fork 9
fix(website): correct link to account edit if Keycloak has subpath #5797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Code ReviewThank you for fixing this bug! The approach of extracting the base URL from the authorization URL is sound. Here are my findings: Code Quality & Best Practices ✅Positive aspects:
Issues Found 🔍1. Critical: Leftover debug console.log (website/src/components/User/UserPage.astro:22)There is a console.log statement on line 22 that should be removed before merging 2. Missing test coverage
|
a73b160 to
edbd100
Compare
This fixes a bug that the link to the account edit page on Keycloak was wrong if the Keycloak instance is not at the root path but under a different pathname.
edbd100 to
911468a
Compare
Code ReviewSummaryThis PR fixes a bug where the Keycloak account edit page link was incorrect when Keycloak is hosted at a subpath (e.g., Positive Aspects✅ Root Cause Fix: The solution addresses the core issue by reusing ✅ Code Consolidation: Removing the separate ✅ Consistency: The new implementation aligns with how the codebase handles Keycloak URLs elsewhere (see ✅ Manual Testing: The author tested on a VM with Keycloak at Issues & Concerns🔴 Missing Test Coverage (Important)The PR removes the unit tests (
Recommendation: Add unit tests for describe('getUrlForKeycloakAccountPage', () => {
test('handles Keycloak at root path', async () => {
// Mock getAuthBaseUrl to return 'https://kc.example.com'
expect(await getUrlForKeycloakAccountPage()).toBe('https://kc.example.com/realms/loculus/account');
});
test('handles Keycloak at subpath', async () => {
// Mock getAuthBaseUrl to return 'https://kc.example.com/auth'
expect(await getUrlForKeycloakAccountPage()).toBe('https://kc.example.com/auth/realms/loculus/account');
});
});🟡 Missing Null Check (Medium Priority)In Current code: export const getUrlForKeycloakAccountPage = async () => {
const baseUrl = await getAuthBaseUrl();
return `${baseUrl}${realmPath}/account`; // baseUrl could be null
};Recommendation: Add null handling: export const getUrlForKeycloakAccountPage = async () => {
const baseUrl = await getAuthBaseUrl();
if (baseUrl === null) {
return null; // or throw an error, depending on desired behavior
}
return `${baseUrl}${realmPath}/account`;
};Then update the calling code to handle the null case appropriately (or document why it can't happen in practice). 🟡 File Extension Inconsistency (Minor)In the imports,
While this works, the codebase generally omits import { getUrlForKeycloakAccountPage } from '../../utils/getAuthUrl';Security & Performance✅ No security concerns identified Suggested Checklist (from website/AGENTS.md)Before merging, please ensure:
VerdictThe core fix is solid and correct 👍. However, the missing test coverage is a significant gap that should be addressed before merging to prevent future regressions. The null check is also important for robustness. Recommendation: Add unit tests and null handling, then this is good to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be unit tested and now isn't anymore unless I missed something. It's quite a trivial change but still.
Do we maybe have an integration test for going to account page? Otherwise might be worth adding to improve coverage rather than reduce.
|
Fwiw the unit test looks to have been added by codex while AI coding for me, and wasn't something I actively decided we needed. I don't really think we need it (no strong feelings). |
theosanderson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks (obvs if cornelius feels anything is blocking, do flag)
|
Thanks for the reviews! I'll propose a few tests in a separate PR (not doing it here because they will be more about |
Based on @corneliusroemer's suggestion in #5797 (review), this adds integration tests to check that the "Edit account information" button redirects to Keycloak. (Unfortunately, it's not that easy to actually test the case that #5797 resolves with the integration tests as it requires a different set of configs. I'll propose a few unit tests later in a separate PR.)
resolves #5796
This fixes a bug that the link to the account edit page on Keycloak was wrong if the Keycloak instance is not at the root path but under a different pathname.
PR Checklist
[ ] All necessary documentation has been adapted.[ ] The implemented feature is covered by appropriate, automated tests./auth🚀 Preview: https://fix-edit-account-link.loculus.org