Skip to content

test: external-IdP e2e coverage (Keycloak OIDC + LDAP) behind auth-idp tag#24499

Merged
netroms merged 4 commits into
masterfrom
test/auth-idp-keycloak-e2e
Jul 21, 2026
Merged

test: external-IdP e2e coverage (Keycloak OIDC + LDAP) behind auth-idp tag#24499
netroms merged 4 commits into
masterfrom
test/auth-idp-keycloak-e2e

Conversation

@netroms

@netroms netroms commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

New auth-idp tagged e2e suite covering the external-IdP authentication paths, which had zero automated coverage. Excluded from the default profile; runs on every PR via a new workflow, plus nightly and manual dispatch. Part of the auth coverage initiative; companion to #24497.

  • Stack: docker-compose.e2e-auth.yml overlay (Keycloak 26 with imported realm, OpenLDAP with LDIF seed) + dedicated config/dhis2_home_auth/ so extra login providers never affect the default suite.
  • KeycloakOidcLoginTest: browser redirect flow (Selenium), email claim -> User.openId mapping, authorities from DHIS2 roles, unmapped IdP user fails to /login/?oidcFailure=true.
  • KeycloakJwtBearerTest: direct-access-grant tokens, issuer/audience validation, unmapped/garbage rejection, @RequiresAuthority 403 contract + superuser bypass over bearer.
  • LdapLoginTest: bind auth requires ldapId + externalAuth; (cn={0}) filter gets User.ldapId (fixtures differ from username to prove the rewrite); DB password never authenticates LDAP users; regular users unaffected.
  • CI: run-auth-idp-tests.yml runs on all PRs. For same-repo PRs it skips the Maven build and pulls the dhis2/core-pr:<number> image published by the "Run api tests" workflow (polling until the DHIS2_BUILD_REVISION label matches the PR head SHA, so both suites test the identical image). Fork/dependabot PRs, nightly and dispatch runs build the image locally as before. Test execution itself is ~40s; the job is off the PR critical path since the full e2e job takes longer.

Testing

Verified locally: full stack boot, 14/14 green (8 Keycloak + 6 LDAP).

AI Assisted

netroms added 2 commits July 19, 2026 16:22
…a Keycloak

Adds an 'auth-idp' tagged e2e suite covering the external-IdP code path
(DhisOidcProvider/DhisOidcUser/Dhis2JwtAuthenticationManagerResolver),
which had zero automated coverage:

- docker-compose.e2e-auth.yml overlay: Keycloak 26 with an imported
  realm (config/keycloak/realm-dhis2.json) and a dedicated DHIS2_HOME
  (config/dhis2_home_auth/) so the extra login provider never affects
  the default e2e suite.
- KeycloakOidcLoginTest: browser redirect flow via Selenium, email
  claim -> User.openId mapping, authorities from DHIS2 roles, unmapped
  IdP user fails to /login/?oidcFailure=true, loginConfig advertises
  the provider.
- KeycloakJwtBearerTest: direct-access-grant tokens against the API,
  issuer/audience validation, unmapped and garbage token rejection,
  and the @RequiresAuthority 403 message contract + superuser bypass
  over bearer auth.
- pom.xml: default profile now excludes 'auth-idp'; new auth-idp
  profile runs the tagged tests.
- run-auth-idp-tests.yml: runs the suite on PRs touching security
  paths, nightly on master, and on manual dispatch.

Verified locally: full stack boot + 8/8 tests green inside the compose
network.

AI Assisted
Extends the auth-idp e2e stack with an OpenLDAP container and LdapLoginTest,
covering CustomLdapAuthenticationProvider/DhisBindAuthenticator which had
zero automated coverage:

- osixia/openldap service in docker-compose.e2e-auth.yml, seeded from
  config/ldap/users.ldif; ldap.* block in config/dhis2_home_auth/dhis.conf.
- Pins: users route to LDAP only with ldapId + externalAuth=true; the
  (cn={0}) filter is filled with User.ldapId (fixtures make ldapId differ
  from the username to prove the rewrite); authorities come from DHIS2
  roles; the DHIS2-stored password never authenticates an LDAP user;
  LDAP-only entries without a DHIS2 user are rejected; regular users keep
  DB-password login while LDAP is enabled; @RequiresAuthority 403 message
  contract and superuser bypass hold over LDAP sessions.

Verified locally: full auth-idp stack boot, 14/14 green (8 Keycloak + 6 LDAP).

AI Assisted
@netroms
netroms requested a review from a team as a code owner July 19, 2026 08:23
@netroms
netroms marked this pull request as draft July 19, 2026 08:44
For same-repo PRs, pull the dhis2/core-pr:<number> image that the api
tests workflow pushes to Docker Hub (verified against the PR head SHA
via the DHIS2_BUILD_REVISION label) instead of rebuilding it. Fork and
dependabot PRs, nightly and manual runs still build the image locally.
@netroms
netroms marked this pull request as ready for review July 20, 2026 13:25
@sonarqubecloud

Copy link
Copy Markdown

@netroms
netroms merged commit cf62d34 into master Jul 21, 2026
25 checks passed
@netroms
netroms deleted the test/auth-idp-keycloak-e2e branch July 21, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants