From 24719a77b1051b37e7896565d778c7ad8bcb0d9b Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 26 Nov 2026 17:06:11 +0530 Subject: [PATCH 01/14] test(api): drop api_035, DataSpaceFrontend#567 removed /api/website-title --- tests/api/smoke/test_api_035_website_title.py | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 tests/api/smoke/test_api_035_website_title.py diff --git a/tests/api/smoke/test_api_035_website_title.py b/tests/api/smoke/test_api_035_website_title.py deleted file mode 100644 index 88c0d165..00000000 --- a/tests/api/smoke/test_api_035_website_title.py +++ /dev/null @@ -1,55 +0,0 @@ -# tests/api/smoke/test_api_035_website_title.py -# -# DataSpaceFrontend#470 ("Provider Flow Update") added a new, unauthenticated -# API route, GET /api/website-title?url=, that fetches an arbitrary -# caller-supplied URL server-side and returns its . It validates the -# `url` param (present, http/https only) before fetching. -# -# The two validation tests are `readonly`: `deployed_pr` skips them on any site -# whose X-Git-Sha doesn't include #470, so they sit in the prod gate safely and -# switch on once #470 ships. The title fetch stays out of the prod gate: it -# depends on example.com being reachable from the server. - -import pytest - -pytestmark = [pytest.mark.api, pytest.mark.smoke] - - -@pytest.mark.readonly -@pytest.mark.deployed_pr("DataSpaceFrontend#470", site="HOME_URL_DEV") -def test_website_title_rejects_missing_url(dev_frontend_client): - """No `url` param must 400, not 500 or a silent null-title 200.""" - resp = dev_frontend_client.get("/api/website-title") - assert resp.status_code == 400, ( - f"expected 400 for a missing url param, got {resp.status_code}: {resp.text}" - ) - assert resp.json().get("title") is None - - -@pytest.mark.readonly -@pytest.mark.deployed_pr("DataSpaceFrontend#470", site="HOME_URL_DEV") -def test_website_title_rejects_non_http_protocol(dev_frontend_client): - """A non-http(s) URL (e.g. javascript:) must 400, confirming the protocol check runs.""" - resp = dev_frontend_client.get( - "/api/website-title", params={"url": "javascript:alert(1)"} - ) - assert resp.status_code == 400, ( - f"expected 400 for a non-http(s) url, got {resp.status_code}: {resp.text}" - ) - assert resp.json().get("title") is None - - -@pytest.mark.deployed_pr("DataSpaceFrontend#470", site="HOME_URL_DEV") -def test_website_title_fetches_a_real_page_title(dev_frontend_client): - """A valid http(s) URL must 200 with the target page's actual <title>. - - This is the path that didn't exist before #470: proven red (404) against - the pre-merge commit locally, see the PR body for both runs. - """ - resp = dev_frontend_client.get( - "/api/website-title", params={"url": "https://example.com"} - ) - assert resp.status_code == 200, f"expected 200, got {resp.status_code}: {resp.text}" - assert resp.json().get("title") == "Example Domain", ( - f"expected the fetched page's real title, got {resp.json()!r}" - ) From 53abd81b759fbafed41137f5775885d761772bf6 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:02:12 +0530 Subject: [PATCH 02/14] test: drop the auth-page known failures fixed by DataSpaceKeycloakTheme#46 --- known_failures.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/known_failures.txt b/known_failures.txt index d07dbbf3..d9cc75ee 100644 --- a/known_failures.txt +++ b/known_failures.txt @@ -7,18 +7,6 @@ tests/api/smoke/test_api_067_org_member_permissions.py::test_api_067_only_an_adm tests/api/smoke/test_api_072_user_lookup_privacy.py::test_api_072_anonymous_user_lookup_hides_the_email # GHSA-v29h-63vw-gw4f tests/accessibility/test_a11y_008_public_layout.py::test_public_page_does_not_scroll_sideways[home-tablet] # home scrolls sideways at 768px tests/provider/smoke/test_prv_026_stored_description_html.py::test_description_html_is_not_run_on_the_public_page # stored description HTML runs on the public page -tests/consumer/smoke/test_con_auth_pages.py::TestErrorPage::test_bad_redirect_uri_is_not_blamed_on_google # DataSpaceKeycloakTheme#32 -tests/consumer/smoke/test_con_auth_pages.py::TestErrorPage::test_unknown_client_is_not_blamed_on_google # DataSpaceKeycloakTheme#32 -tests/consumer/smoke/test_con_auth_pages.py::TestForgotPasswordPage::test_email_carries_over_from_sign_in # DataSpaceKeycloakTheme#40 -tests/consumer/smoke/test_con_auth_pages.py::TestForgotPasswordPage::test_empty_request_message_matches_design # DataSpaceKeycloakTheme#40 -tests/consumer/smoke/test_con_auth_pages.py::TestForgotPasswordPage::test_request_shows_check_your_email # DataSpaceKeycloakTheme#33 -tests/consumer/smoke/test_con_auth_pages.py::TestLegalLinks::test_footer_has_privacy_terms_legal # DataSpaceKeycloakTheme#43 -tests/consumer/smoke/test_con_auth_pages.py::TestLegalLinks::test_mobile_shows_legal_links # DataSpaceKeycloakTheme#43 -tests/consumer/smoke/test_con_auth_pages.py::TestRegistrationPage::test_consent_covers_terms_and_privacy # DataSpaceKeycloakTheme#42 -tests/consumer/smoke/test_con_auth_pages.py::TestRegistrationPage::test_password_requirements_are_shown # DataSpaceKeycloakTheme#41 -tests/consumer/smoke/test_con_auth_pages.py::TestRegistrationPage::test_registration_form_renders_design_fields # DataSpaceKeycloakTheme#44 -tests/consumer/smoke/test_con_auth_pages.py::TestSignInPage::test_empty_sign_in_is_validated_inline # DataSpaceKeycloakTheme#39 -tests/consumer/smoke/test_con_auth_pages.py::TestSignInPage::test_wrong_credentials_message_matches_design # DataSpaceKeycloakTheme#39 tests/api/smoke/test_api_073_anonymous_mutations.py::test_api_073_anonymous_caller_is_refused[update-sector] # GHSA-jcj9-qw6c-98h3 tests/api/smoke/test_api_073_anonymous_mutations.py::test_api_073_anonymous_caller_is_refused[delete-sector] # GHSA-jcj9-qw6c-98h3 tests/api/smoke/test_api_073_anonymous_mutations.py::test_api_073_anonymous_caller_is_refused[update-sdg] # GHSA-jcj9-qw6c-98h3 From bec05d8007e12e346e2a75fda386f9b538cc6ca3 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:02:30 +0530 Subject: [PATCH 03/14] test(keycloak): the auth footer links only to Privacy, which covers Terms and Legal --- tests/consumer/smoke/test_con_auth_pages.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/consumer/smoke/test_con_auth_pages.py b/tests/consumer/smoke/test_con_auth_pages.py index a502edb1..bde528e1 100644 --- a/tests/consumer/smoke/test_con_auth_pages.py +++ b/tests/consumer/smoke/test_con_auth_pages.py @@ -233,8 +233,9 @@ def test_unknown_client_is_not_blamed_on_google(self, driver): class TestLegalLinks: - def test_footer_has_privacy_terms_legal(self, login_page): - assert login_page.legal_link_texts() == ["Privacy", "Terms", "Legal"] + def test_footer_has_privacy_link(self, login_page): + """Terms & Conditions and Legal are covered by the Privacy page, so it is the only link.""" + assert login_page.legal_link_texts() == ["Privacy"] @pytest.mark.mobile def test_mobile_sign_in_has_no_horizontal_scroll(self, login_page): @@ -244,4 +245,4 @@ def test_mobile_sign_in_has_no_horizontal_scroll(self, login_page): @pytest.mark.mobile def test_mobile_shows_legal_links(self, login_page): login_page.use_mobile_viewport() - assert login_page.visible_legal_link_texts(), "No Privacy/Terms/Legal link visible at 390px" + assert "Privacy" in login_page.visible_legal_link_texts(), "No Privacy link visible at 390px" From 1cc0c636928bd1af686606fbb8a112e926472e63 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:02:38 +0530 Subject: [PATCH 04/14] test(keycloak): register consent names the Privacy Policy, which covers Terms --- tests/consumer/smoke/test_con_auth_pages.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/consumer/smoke/test_con_auth_pages.py b/tests/consumer/smoke/test_con_auth_pages.py index bde528e1..e532d00a 100644 --- a/tests/consumer/smoke/test_con_auth_pages.py +++ b/tests/consumer/smoke/test_con_auth_pages.py @@ -217,9 +217,10 @@ def test_password_requirements_are_shown(self, register_page): for line in ("Password must contain", "At least 8 characters", "One uppercase letter", "One number"): assert line in text, f"{line!r} not shown while typing a password" - def test_consent_covers_terms_and_privacy(self, register_page): + def test_consent_names_the_privacy_policy(self, register_page): + """Terms & Conditions are covered by the Privacy Policy, so consent names only that.""" text = register_page.terms_text() - assert "Terms & Conditions" in text and "Privacy Policy" in text, text + assert "Privacy Policy" in text, text class TestErrorPage: From dd3aaed942bf322ffde84a897ea66367ccbfe73d Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:02:53 +0530 Subject: [PATCH 05/14] test(keycloak): register keeps first and last name; password checks wait on the realm --- tests/consumer/smoke/test_con_auth_pages.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/consumer/smoke/test_con_auth_pages.py b/tests/consumer/smoke/test_con_auth_pages.py index e532d00a..5f25f1c0 100644 --- a/tests/consumer/smoke/test_con_auth_pages.py +++ b/tests/consumer/smoke/test_con_auth_pages.py @@ -39,7 +39,15 @@ BASE_URL = os.getenv("HOME_URL_DEV", "https://dev.civicdataspace.in") -DESIGN_REGISTER_FIELDS = ("email", "password", "password-confirm") +# First and last name stay on the form: the dashboard builds its links from the first name. +DESIGN_REGISTER_FIELDS = ("email", "firstName", "lastName", "password", "password-confirm") + +# The theme renders the password fields only when the realm's registration flow asks for a +# password, so these wait on the realm change, not on the theme. Remove once the realm has it. +AWAITS_REALM_PASSWORD = pytest.mark.xfail( + strict=True, + reason="Realm has no password on register or password policy yet (DataSpaceKeycloakTheme#44, #41)", +) def no_account_email(): @@ -202,15 +210,13 @@ def test_consent_is_enforced_in_the_browser(self, register_page): ) assert register_page.terms_error_text(), "No error shown for missing consent" + @AWAITS_REALM_PASSWORD def test_registration_form_renders_design_fields(self, register_page): names = register_page.field_names() missing = [f for f in DESIGN_REGISTER_FIELDS if f not in names] - extra = [f for f in ("firstName", "lastName") if f in names] - assert not missing and not extra, ( - f"Register form fields differ from the design. Missing {missing}, " - f"not in design {extra}. Present: {names}" - ) + assert not missing, f"Register form is missing {missing}. Present: {names}" + @AWAITS_REALM_PASSWORD def test_password_requirements_are_shown(self, register_page): assert register_page.type_password("abc"), "No password field on the register form" text = register_page.card_text() From 1557888338234110c178661f9f2781180c5dc6dc Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:03:15 +0530 Subject: [PATCH 06/14] test(keycloak): registration types a password when the realm asks for one --- locators/consumer/keycloak_auth_locators.py | 1 + pages/consumer/keycloak_auth_page.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/locators/consumer/keycloak_auth_locators.py b/locators/consumer/keycloak_auth_locators.py index 6b73ec89..e380e83d 100644 --- a/locators/consumer/keycloak_auth_locators.py +++ b/locators/consumer/keycloak_auth_locators.py @@ -55,6 +55,7 @@ class KeycloakRegisterLocators: FIRST_NAME = (By.ID, "firstName") LAST_NAME = (By.ID, "lastName") PASSWORD = (By.ID, "password") + PASSWORD_CONFIRM = (By.ID, "password-confirm") SIGN_IN_PROMPT = (By.ID, "kc-registration") GOOGLE_BROKER_LINK = (By.CSS_SELECTOR, "a[href*='/broker/google/login']") TERMS_ROW = (By.CSS_SELECTOR, ".civic-terms") diff --git a/pages/consumer/keycloak_auth_page.py b/pages/consumer/keycloak_auth_page.py index 0ac04864..b7df0012 100644 --- a/pages/consumer/keycloak_auth_page.py +++ b/pages/consumer/keycloak_auth_page.py @@ -21,6 +21,8 @@ VERIFY_EMAIL_MARKER = "VERIFY_EMAIL" REGISTRATION_PATH = "registrations" +# Meets the realm policy planned for #41: 8+ characters, an uppercase letter and a digit. +REGISTER_PASSWORD = "QaAuto-Register-2026" def _kc_settings(): @@ -285,10 +287,15 @@ def has_terms_checkbox(self): def privacy_hrefs(self): return [e.get_attribute("href") for e in self.driver.find_elements(*KeycloakRegisterLocators.PRIVACY_LINK)] - def fill(self, email, first_name="QA", last_name="Automation"): + def fill(self, email, first_name="QA", last_name="Automation", password=REGISTER_PASSWORD): self._find(KeycloakRegisterLocators.EMAIL).send_keys(email) self._find(KeycloakRegisterLocators.FIRST_NAME).send_keys(first_name) self._find(KeycloakRegisterLocators.LAST_NAME).send_keys(last_name) + # The realm decides whether register asks for a password; fill it only when shown. + for locator in (KeycloakRegisterLocators.PASSWORD, KeycloakRegisterLocators.PASSWORD_CONFIRM): + el = self._find(locator) + if el is not None: + el.send_keys(password) return self def accept_terms(self): From 30aeef186df931135c886269cd690f1053653c33 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:22:36 +0530 Subject: [PATCH 07/14] test(keycloak): wait for the reset request to load the next page before reading it --- pages/consumer/keycloak_auth_page.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pages/consumer/keycloak_auth_page.py b/pages/consumer/keycloak_auth_page.py index b7df0012..a1bd0fe5 100644 --- a/pages/consumer/keycloak_auth_page.py +++ b/pages/consumer/keycloak_auth_page.py @@ -247,6 +247,9 @@ def request_reset(self, email): el.send_keys(email) self.mark_document() self._find(KeycloakResetLocators.SUBMIT).click() + if email: + # A filled form goes to the server; without this wait the old page's heading is read. + WebDriverWait(self.driver, 20).until(lambda d: self.document_was_replaced()) self._wait_ready() self._await(KeycloakShellLocators.HEADING) return self From c60cf3300c77e2c7fbc3a4611a0ddc42df94bfe8 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 17:45:27 +0530 Subject: [PATCH 08/14] test(keycloak): register password checks pass now the realm asks for a password --- tests/consumer/smoke/test_con_auth_pages.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/consumer/smoke/test_con_auth_pages.py b/tests/consumer/smoke/test_con_auth_pages.py index 5f25f1c0..6d162aba 100644 --- a/tests/consumer/smoke/test_con_auth_pages.py +++ b/tests/consumer/smoke/test_con_auth_pages.py @@ -42,13 +42,6 @@ # First and last name stay on the form: the dashboard builds its links from the first name. DESIGN_REGISTER_FIELDS = ("email", "firstName", "lastName", "password", "password-confirm") -# The theme renders the password fields only when the realm's registration flow asks for a -# password, so these wait on the realm change, not on the theme. Remove once the realm has it. -AWAITS_REALM_PASSWORD = pytest.mark.xfail( - strict=True, - reason="Realm has no password on register or password policy yet (DataSpaceKeycloakTheme#44, #41)", -) - def no_account_email(): return f"qa-no-account-{uuid.uuid4().hex[:12]}@example.invalid" @@ -210,13 +203,11 @@ def test_consent_is_enforced_in_the_browser(self, register_page): ) assert register_page.terms_error_text(), "No error shown for missing consent" - @AWAITS_REALM_PASSWORD def test_registration_form_renders_design_fields(self, register_page): names = register_page.field_names() missing = [f for f in DESIGN_REGISTER_FIELDS if f not in names] assert not missing, f"Register form is missing {missing}. Present: {names}" - @AWAITS_REALM_PASSWORD def test_password_requirements_are_shown(self, register_page): assert register_page.type_password("abc"), "No password field on the register form" text = register_page.card_text() From b7a40fc18708756d2f39de3da9e25bf3e633c3cd Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:07:35 +0530 Subject: [PATCH 09/14] test(utils): Keycloak admin can create a throwaway user and read its attributes --- utils/keycloak_admin.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/utils/keycloak_admin.py b/utils/keycloak_admin.py index 6fd7c7cf..d231bac3 100644 --- a/utils/keycloak_admin.py +++ b/utils/keycloak_admin.py @@ -76,6 +76,30 @@ def find_users_by_email(self, email): def user_exists(self, email): return len(self.find_users_by_email(email)) > 0 + def user_attributes(self, email): + """Custom attributes of the user with this email, or None when there is no such user.""" + users = self.find_users_by_email(email) + return (users[0].get("attributes") or {}) if users else None + + def create_user(self, email, password, email_verified=True, required_actions=()): + """Create a signed-in-able user. The caller must delete it (delete_user_by_email).""" + resp = requests.post( + f"{self.base_url}/admin/realms/{self.realm}/users", + headers=self._headers(), + json={ + "username": email, + "email": email, + "firstName": "QA", + "lastName": "Automation", + "enabled": True, + "emailVerified": email_verified, + "requiredActions": list(required_actions), + "credentials": [{"type": "password", "value": password, "temporary": False}], + }, + timeout=TIMEOUT, + ) + return resp.status_code == 201 + def delete_user_by_email(self, email): """Delete every user matching the email. Returns how many were removed. From 9fef4f23b03516dad8a2263aff4ff7a001582306 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:08:33 +0530 Subject: [PATCH 10/14] test(locators): password checklist, existing-email sign-in link and update-password form --- locators/consumer/keycloak_auth_locators.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/locators/consumer/keycloak_auth_locators.py b/locators/consumer/keycloak_auth_locators.py index e380e83d..bd60425a 100644 --- a/locators/consumer/keycloak_auth_locators.py +++ b/locators/consumer/keycloak_auth_locators.py @@ -18,6 +18,7 @@ class KeycloakShellLocators: LEGAL_LINKS = (By.CSS_SELECTOR, ".civic-legal-links a") ALERT = (By.CSS_SELECTOR, ".pf-c-alert") FIELD_ERROR = (By.CSS_SELECTOR, ".civic-field-error") + PASSWORD_RULES = (By.CSS_SELECTOR, "#password-requirements li") ANY_LINK = (By.TAG_NAME, "a") @@ -60,6 +61,7 @@ class KeycloakRegisterLocators: GOOGLE_BROKER_LINK = (By.CSS_SELECTOR, "a[href*='/broker/google/login']") TERMS_ROW = (By.CSS_SELECTOR, ".civic-terms") TERMS_ERROR = (By.ID, "input-error-termsAccepted") + EMAIL_ERROR_SIGN_IN_LINK = (By.CSS_SELECTOR, "#input-error-email a") # The privacy consent checkbox. Note it carries required=false in the DOM, # so nothing about the markup guarantees consent is enforced - the tests @@ -69,3 +71,9 @@ class KeycloakRegisterLocators: SUBMIT = (By.CSS_SELECTOR, "input[type=submit], button[type=submit]") PRIVACY_LINK = (By.CSS_SELECTOR, "a[href*='/privacy']") BACK_TO_LOGIN = (By.CSS_SELECTOR, "a[href*='login-actions'], a[href*='protocol/openid-connect/auth']") + + +class KeycloakUpdatePasswordLocators: + NEW_PASSWORD = (By.ID, "password-new") + CONFIRM = (By.ID, "password-confirm") + SUBMIT = (By.CSS_SELECTOR, "#kc-passwd-update-form [type=submit]:not([name=cancel-aia])") From b7756ae6c663896584867c71301f77f275de6a5d Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:08:33 +0530 Subject: [PATCH 11/14] test(pages): Keycloak checklist, field errors, real sign-in and the update-password page --- pages/consumer/keycloak_auth_page.py | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/pages/consumer/keycloak_auth_page.py b/pages/consumer/keycloak_auth_page.py index a1bd0fe5..e76225a7 100644 --- a/pages/consumer/keycloak_auth_page.py +++ b/pages/consumer/keycloak_auth_page.py @@ -2,6 +2,7 @@ import os from selenium.common.exceptions import TimeoutException +from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait @@ -11,6 +12,7 @@ KeycloakRegisterLocators, KeycloakResetLocators, KeycloakShellLocators, + KeycloakUpdatePasswordLocators, ) from pages.base_page import BasePage @@ -79,6 +81,39 @@ def field_errors(self): if _squash(e.text) ] + def field_error(self, field): + """The inline error under one field, or "" when it has none.""" + return self._text((By.ID, f"input-error-{field}")) + + def password_rules(self): + """The "Password must contain" checklist as (label, state); state is met, invalid or "".""" + rules = [] + for li in self.driver.find_elements(*KeycloakShellLocators.PASSWORD_RULES): + label = _squash(li.text).replace("Not met: ", "").replace("Met: ", "") + classes = (li.get_attribute("class") or "").split() + state = "met" if "is-met" in classes else "invalid" if "is-invalid" in classes else "" + rules.append((label, state)) + return rules + + def _retype(self, locator, text): + el = self._find(locator) + el.clear() + el.send_keys(text) + + def submit_in_browser(self, submit_locator): + """Click submit; True when the theme kept the form in the browser (nothing was posted).""" + self.mark_document() + self._find(submit_locator).click() + self._wait_ready() + return not self.document_was_replaced() + + def wait_until_url_contains(self, fragment, timeout=20): + try: + WebDriverWait(self.driver, timeout).until(lambda d: fragment in d.current_url) + return True + except TimeoutException: + return False + def alert_text(self): return self._text(KeycloakShellLocators.ALERT) @@ -205,6 +240,16 @@ def submit(self): self._await(KeycloakLoginLocators.USERNAME) return self + def sign_in_as(self, email, password): + """Sign in as a real (throwaway) account. Waits for Keycloak to move on from the form.""" + self.type_email(email) + self._find(KeycloakLoginLocators.PASSWORD).send_keys(password) + url_before = self.driver.current_url + self._find(KeycloakLoginLocators.SUBMIT).click() + WebDriverWait(self.driver, 20).until(lambda d: d.current_url != url_before) + self._wait_ready() + return self + def go_to_forgot_password(self): self._find(KeycloakLoginLocators.FORGOT_LINK).click() WebDriverWait(self.driver, 20).until(lambda d: "reset-credentials" in d.current_url) @@ -390,9 +435,54 @@ def type_password(self, text): el.send_keys(text) return True + def type_register_email(self, text): + self._retype(KeycloakRegisterLocators.EMAIL, text) + return self + + def retype_password(self, text): + self._retype(KeycloakRegisterLocators.PASSWORD, text) + return self + + def type_confirm(self, text): + self._retype(KeycloakRegisterLocators.PASSWORD_CONFIRM, text) + return self + + def submit_stays_in_browser(self): + return self.submit_in_browser(KeycloakRegisterLocators.SUBMIT) + + def email_error_sign_in_href(self): + el = self._find(KeycloakRegisterLocators.EMAIL_ERROR_SIGN_IN_LINK) + return el.get_attribute("href") if el else None + def submit_without_consent(self): """Click Create Account with consent unticked; the theme should block it.""" self.mark_document() self._find(KeycloakRegisterLocators.SUBMIT).click() self._wait_ready() return self + + +class KeycloakUpdatePasswordPage(_KeycloakPage): + """login-update-password.ftl, shown when an account has the UPDATE_PASSWORD action.""" + + def wait_loaded(self): + self._await(KeycloakUpdatePasswordLocators.NEW_PASSWORD) + return self + + def type_new(self, text): + self._retype(KeycloakUpdatePasswordLocators.NEW_PASSWORD, text) + return self + + def type_confirm(self, text): + self._retype(KeycloakUpdatePasswordLocators.CONFIRM, text) + return self + + def submit_stays_in_browser(self): + return self.submit_in_browser(KeycloakUpdatePasswordLocators.SUBMIT) + + def submit(self): + url_before = self.driver.current_url + self._find(KeycloakUpdatePasswordLocators.SUBMIT).click() + WebDriverWait(self.driver, 20).until(lambda d: d.current_url != url_before) + self._wait_ready() + return self From 6c1645a432179d02e7601689bf045305e40e5eef Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:09:13 +0530 Subject: [PATCH 12/14] test(pages): sign-in can report a submit the theme kept in the browser --- pages/consumer/keycloak_auth_page.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pages/consumer/keycloak_auth_page.py b/pages/consumer/keycloak_auth_page.py index e76225a7..18088f55 100644 --- a/pages/consumer/keycloak_auth_page.py +++ b/pages/consumer/keycloak_auth_page.py @@ -240,6 +240,9 @@ def submit(self): self._await(KeycloakLoginLocators.USERNAME) return self + def submit_stays_in_browser(self): + return self.submit_in_browser(KeycloakLoginLocators.SUBMIT) + def sign_in_as(self, email, password): """Sign in as a real (throwaway) account. Waits for Keycloak to move on from the form.""" self.type_email(email) From 22e60e7132462e84ffa8380917c88499975ec0a3 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:13:42 +0530 Subject: [PATCH 13/14] test(utils): Keycloak admin reads a user's sessions and pending required actions --- utils/keycloak_admin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils/keycloak_admin.py b/utils/keycloak_admin.py index d231bac3..33be940a 100644 --- a/utils/keycloak_admin.py +++ b/utils/keycloak_admin.py @@ -81,6 +81,22 @@ def user_attributes(self, email): users = self.find_users_by_email(email) return (users[0].get("attributes") or {}) if users else None + def user_session_count(self, email): + """Active sessions of the user with this email: proof that a sign-in went through.""" + users = self.find_users_by_email(email) + if not users: + return 0 + resp = requests.get( + f"{self.base_url}/admin/realms/{self.realm}/users/{users[0]['id']}/sessions", + headers=self._headers(), + timeout=TIMEOUT, + ) + return len(resp.json()) if resp.status_code == 200 else 0 + + def required_actions(self, email): + users = self.find_users_by_email(email) + return users[0].get("requiredActions", []) if users else None + def create_user(self, email, password, email_verified=True, required_actions=()): """Create a signed-in-able user. The caller must delete it (delete_user_by_email).""" resp = requests.post( From ce17ddff64864faaad8e5185b627dda8dbc28175 Mon Sep 17 00:00:00 2001 From: Saqib <saqibmanan6@gmail.com> Date: Thu, 26 Nov 2026 18:13:42 +0530 Subject: [PATCH 14/14] test(keycloak): auth flows on the redesigned pages: register, sign-in and update password --- .../functional/test_con_auth_flows.py | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 tests/consumer/functional/test_con_auth_flows.py diff --git a/tests/consumer/functional/test_con_auth_flows.py b/tests/consumer/functional/test_con_auth_flows.py new file mode 100644 index 00000000..4f995b21 --- /dev/null +++ b/tests/consumer/functional/test_con_auth_flows.py @@ -0,0 +1,195 @@ +# tests/consumer/functional/test_con_auth_flows.py +# +# End-to-end auth flows on the redesigned Keycloak pages (DataSpaceKeycloakTheme#46), +# against the realm as configured for the release: password on the register form, +# policy of 8 characters + 1 uppercase + 1 digit, and a user-writable termsAccepted. +# +# Two kinds of test live here: +# +# - TestRegisterValidation / TestSignInValidation are readonly: they type into the +# forms and submit only what the theme blocks in the browser, so nothing reaches +# the server. Safe against production. +# - The rest create throwaway qa-auto-*@example.invalid accounts in the realm dev and +# prod share. They depend on `keycloak_admin`, which skips without a service account, +# and every account is deleted in teardown whether the test passed or not. +# +# Google sign-in, linking and review profile need a real Google account and are not +# automated here. + +import os +import uuid + +import pytest + +from pages.consumer.keycloak_auth_page import ( + REGISTER_PASSWORD, + KeycloakLoginPage, + KeycloakRegisterPage, + KeycloakUpdatePasswordPage, +) +from utils.keycloak_admin import KeycloakAdmin + +pytestmark = [pytest.mark.functional, pytest.mark.regression] + +BASE_URL = os.getenv("HOME_URL_DEV", "https://dev.civicdataspace.in") + +RULES = ("At least 8 characters", "One uppercase letter", "One number") + + +def assert_handed_to_app(driver, keycloak_admin, email): + """Keycloak signed the account in and sent the browser back to the app. + + The app's NextAuth callback then rejects the code, because these tests start the flow + with their own state, so the final URL is the app's sign-in page. The session is the proof. + """ + host = driver.current_url.split("/")[2] + assert host == BASE_URL.split("/")[2], f"Still on {driver.current_url!r}, not back at the app" + assert keycloak_admin.user_session_count(email) >= 1, f"No Keycloak session for {email}" + + +@pytest.fixture +def keycloak_admin(): + if os.getenv("REGISTRATION_TESTS") == "off": + pytest.skip("REGISTRATION_TESTS=off: no accounts created in the realm dev and prod share") + admin = KeycloakAdmin() + if not admin.available(): + pytest.skip("No Keycloak service-account access: skipped rather than risk undeletable accounts") + return admin + + +@pytest.fixture +def throwaway_email(keycloak_admin): + email = f"qa-auto-{uuid.uuid4().hex[:12]}@example.invalid" + yield email + keycloak_admin.delete_user_by_email(email) + + +@pytest.fixture +def register_page(driver): + return KeycloakRegisterPage(driver).load(BASE_URL) + + +@pytest.fixture +def login_page(driver): + return KeycloakLoginPage(driver).load(BASE_URL) + + +@pytest.mark.readonly +class TestRegisterValidation: + @pytest.mark.parametrize( + "password, met", + [ + ("abc", ()), + ("abcdefgh", ("At least 8 characters",)), + ("Abcdefgh", ("At least 8 characters", "One uppercase letter")), + ("Abcdefg1", RULES), + ], + ids=["short", "length-only", "length-and-upper", "all-rules"], + ) + def test_checklist_ticks_each_rule_as_it_is_met(self, register_page, password, met): + register_page.type_password(password) + rules = dict(register_page.password_rules()) + assert tuple(rules) == RULES, f"Checklist shows {list(rules)}, realm policy is {RULES}" + ticked = tuple(label for label, state in rules.items() if state == "met") + assert ticked == met, f"For {password!r} the checklist ticks {ticked}, expected {met}" + + def test_weak_password_is_stopped_in_the_browser(self, register_page): + register_page.fill(f"qa-no-account-{uuid.uuid4().hex[:8]}@example.invalid", password="abcdefgh") + register_page.accept_terms() + assert register_page.submit_stays_in_browser(), "A password that fails the checklist was posted" + assert register_page.field_error("password") == "Password does not meet all requirements." + unmet = [label for label, state in register_page.password_rules() if state == "invalid"] + assert unmet == ["One uppercase letter", "One number"], unmet + + def test_mismatched_confirmation_is_stopped_in_the_browser(self, register_page): + register_page.fill(f"qa-no-account-{uuid.uuid4().hex[:8]}@example.invalid") + register_page.type_confirm(REGISTER_PASSWORD + "x") + register_page.accept_terms() + assert register_page.submit_stays_in_browser(), "Mismatched passwords were posted" + assert register_page.field_error("password-confirm") == "Passwords do not match." + + def test_invalid_email_is_stopped_in_the_browser(self, register_page): + register_page.fill("not-an-email") + register_page.accept_terms() + assert register_page.submit_stays_in_browser(), "An invalid email was posted" + assert register_page.field_error("email"), "No error under an invalid email" + + def test_empty_form_flags_every_field(self, register_page): + assert register_page.submit_stays_in_browser(), "An empty form was posted" + for field in ("email", "firstName", "lastName", "password", "password-confirm", "termsAccepted"): + assert register_page.field_error(field), f"No error under {field} on an empty submit" + + +@pytest.mark.readonly +class TestSignInValidation: + def test_invalid_email_is_stopped_in_the_browser(self, login_page): + login_page.type_email("not-an-email") + assert login_page.submit_stays_in_browser(), "An invalid email was posted" + assert login_page.field_error("username") == "Enter a valid email address." + + +class TestRegistration: + def test_consent_is_recorded_on_the_account(self, register_page, throwaway_email, keycloak_admin): + register_page.fill(throwaway_email).accept_terms().submit() + attributes = keycloak_admin.user_attributes(throwaway_email) + assert attributes is not None, f"No account created. Landed at {register_page.driver.current_url!r}" + assert attributes.get("termsAccepted") == ["on"], ( + f"Consent was ticked but the account has termsAccepted={attributes.get('termsAccepted')!r}. " + "The realm attribute must be editable by users or Keycloak drops it on registration." + ) + + def test_existing_email_offers_sign_in(self, register_page, throwaway_email, keycloak_admin): + assert keycloak_admin.create_user(throwaway_email, REGISTER_PASSWORD), "Could not seed the account" + register_page.fill(throwaway_email).accept_terms().submit() + assert "already exists" in register_page.field_error("email"), register_page.field_error("email") + href = register_page.email_error_sign_in_href() or "" + assert "/protocol/openid-connect/auth" in href or "login-actions/authenticate" in href, href + + +class TestSignIn: + def test_verified_account_reaches_the_app(self, login_page, throwaway_email, keycloak_admin): + assert keycloak_admin.create_user(throwaway_email, REGISTER_PASSWORD), "Could not seed the account" + login_page.sign_in_as(throwaway_email, REGISTER_PASSWORD) + assert_handed_to_app(login_page.driver, keycloak_admin, throwaway_email) + + def test_unverified_account_is_asked_to_verify(self, login_page, throwaway_email, keycloak_admin): + assert keycloak_admin.create_user( + throwaway_email, REGISTER_PASSWORD, email_verified=False, required_actions=["VERIFY_EMAIL"] + ), "Could not seed the account" + login_page.sign_in_as(throwaway_email, REGISTER_PASSWORD) + assert login_page.wait_until_url_contains("VERIFY_EMAIL"), ( + f"An unverified account was not sent to Verify email: {login_page.driver.current_url!r}" + ) + + +class TestUpdatePassword: + """The custom update-password page, reached through the UPDATE_PASSWORD required action.""" + + @pytest.fixture + def update_page(self, login_page, throwaway_email, keycloak_admin): + assert keycloak_admin.create_user( + throwaway_email, REGISTER_PASSWORD, required_actions=["UPDATE_PASSWORD"] + ), "Could not seed the account" + login_page.sign_in_as(throwaway_email, REGISTER_PASSWORD) + return KeycloakUpdatePasswordPage(login_page.driver).wait_loaded() + + def test_page_matches_design(self, update_page): + assert update_page.heading() == "Update your password" + assert update_page.subtitle() == "Choose a new password for your CivicDataSpace account." + + def test_weak_password_is_stopped_in_the_browser(self, update_page): + update_page.type_new("abcdefgh").type_confirm("abcdefgh") + assert update_page.submit_stays_in_browser(), "A password that fails the checklist was posted" + assert update_page.field_error("password-new") == "Password does not meet all requirements." + unmet = [label for label, state in update_page.password_rules() if state == "invalid"] + assert unmet == ["One uppercase letter", "One number"], unmet + + def test_mismatch_is_stopped_in_the_browser(self, update_page): + update_page.type_new("Abcdefg1").type_confirm("Abcdefg2") + assert update_page.submit_stays_in_browser(), "Mismatched passwords were posted" + assert update_page.field_error("password-confirm") == "Passwords do not match." + + def test_valid_password_continues_to_the_app(self, update_page, throwaway_email, keycloak_admin): + update_page.type_new("Newpass-2026A").type_confirm("Newpass-2026A").submit() + assert keycloak_admin.required_actions(throwaway_email) == [], "UPDATE_PASSWORD is still pending" + assert_handed_to_app(update_page.driver, keycloak_admin, throwaway_email)