Skip to content

Migrate KcOidcBrokerPassMaxAgeTest and port TestKeycloakOidcIdentityProviderFactory - #52390

Merged
pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:52249-broker-oidc-pass-max-age
Sep 4, 2026
Merged

pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:52249-broker-oidc-pass-max-age

Conversation

@sguilhen

@sguilhen sguilhen commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Migrates KcOidcBrokerPassMaxAgeTest to the new JUnit 5 framework, landing in tests/base/.../broker/oidc/. Tests propagation of the max_age parameter for brokered logins using a custom OIDC IdP factory.

Two commits, following the project's move-then-adapt pattern.

Ports TestKeycloakOidcIdentityProviderFactory to tests/custom-providers. The legacy original is kept in place (not removed) - it's still used by other, not-yet-migrated legacy tests (KcCustomOidcBrokerTest, KcOidcFirstBrokerLoginTest, PasskeysKcOidcFirstBrokerLoginTest), confirmed via grep. No dependency on #52383/#52387 (the other custom-provider migrations) - this provider is never removed from legacy, so there's nothing to coordinate.

Adaptation note: the concrete class extends AbstractKcOidcBrokerTest for the shared infra. testLogInAsUserInIDP is overridden and @Disabled - legacy @Ignores the same inherited test for this exact configuration (no client-forwarded prompt, custom provider factory). testLoginWithExistingUser is overridden with real max_age-specific login logic instead of being disabled, mirroring legacy's own override of that method - so this class has exactly one disabled test, matching legacy 1-for-1. testEnforceReAuthenticationWhenMaxAgeIsSet is a new, independent test exercising the ignore-max-age error path.

Carries forward the fixes from #52372/#52376/#52379/#52382/#52383/#52387/#52388 (independently re-derived per batch, this branch is off upstream/main): visibility widening, configureBrokerEndpoints() placeholder-matching fix, enableUnmanagedAttributes(), disableUpdateProfileOnFirstLogin(), and assertUserCreatedInConsumerRealm().

Testing

  • mvn test -Dtest=KcOidcBrokerPassMaxAgeTest - 2/2 green, 1 intentionally @Disabled (matches legacy's single @Ignore)
  • Re-ran KcOidcBrokerTest, KcOidcBrokerClientSecretBasicAuthTest, KcSamlBrokerTest (phase-1 baseline) - 6/6 green
  • mvn spotless:check clean

Closes #52249

Copilot AI balanced review requested due to automatic review settings September 3, 2026 14:59
@sguilhen
sguilhen requested review from a team as code owners September 3, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Migrates the legacy KcOidcBrokerPassMaxAgeTest to the new JUnit 5 test framework and ports its custom OIDC IdP factory into tests/custom-providers so the migrated test can validate max_age propagation (and the negative “ignore max_age” path).

Changes:

  • Move/port KcOidcBrokerPassMaxAgeTest into tests/base/.../broker/oidc and adapt it to the new test framework (with two inherited tests intentionally disabled).
  • Add TestKeycloakOidcIdentityProviderFactory to tests/custom-providers and register it via META-INF/services.
  • Update shared broker test infrastructure (broker endpoints matching, user-profile handling, and shared post-login assertions).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcOidcBrokerPassMaxAgeTest.java Removes the legacy JUnit 4 test after migration.
tests/custom-providers/src/main/resources/META-INF/services/org.keycloak.broker.provider.IdentityProviderFactory Registers the ported custom OIDC IdP factory for ServiceLoader discovery.
tests/custom-providers/src/main/java/org/keycloak/tests/providers/broker/oidc/TestKeycloakOidcIdentityProviderFactory.java Adds the custom OIDC IdP factory implementation used by the migrated test.
tests/base/src/test/java/org/keycloak/tests/broker/oidc/KcOidcBrokerPassMaxAgeTest.java New JUnit 5 integration test covering max_age propagation and the enforced re-auth error path.
tests/base/src/test/java/org/keycloak/tests/broker/AbstractKcOidcBrokerTest.java Adjusts broker endpoint configuration matching and widens helper visibility for reuse.
tests/base/src/test/java/org/keycloak/tests/broker/AbstractBrokerTest.java Adds user-profile/first-broker-login flow helpers used by multiple broker tests.
tests/base/src/test/java/org/keycloak/tests/broker/AbstractBrokerLoginTest.java Extracts and reuses the “user created in consumer realm” assertion after broker login.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 3, 2026 15:24
@sguilhen
sguilhen force-pushed the 52249-broker-oidc-pass-max-age branch from ebe3c3c to 6f41402 Compare September 3, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

// Legacy KcOidcBrokerConfigurationWithPassMaxAge removed the "prompt" attribute so the
// broker does not force an interactive login; without this the provider always shows its
// login page and the ignore-max-age error path is never exercised.
.attribute("prompt", null));
Comment on lines +40 to +42
return new KeycloakOIDCIdentityProvider(session, new OIDCIdentityProviderConfig(model)) {

private static final Set<String> usernames = new HashSet<>();
}
return super.createAuthorizationUrl(request);
} finally {
authSession.setClientNote(OIDCLoginProtocol.MAX_AGE_PARAM, maxAge);
Copilot AI review requested due to automatic review settings September 4, 2026 11:54
@sguilhen
sguilhen force-pushed the 52249-broker-oidc-pass-max-age branch from 6f41402 to 0dd61f0 Compare September 4, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The migration preserves legacy behavior, adds focused coverage, and correctly integrates the custom provider.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@sguilhen
sguilhen force-pushed the 52249-broker-oidc-pass-max-age branch from 0dd61f0 to 7798db2 Compare September 4, 2026 12:20
Pure git rename of the legacy pass-max-age broker test into the new
testsuite oidc package. No content changes; the new-testsuite adaptation
follows in the next commit.

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
Copilot AI review requested due to automatic review settings September 4, 2026 15:58
@sguilhen
sguilhen force-pushed the 52249-broker-oidc-pass-max-age branch from 7798db2 to cfc88df Compare September 4, 2026 15:58
…roviderFactory

Tests propagation of the max_age parameter for brokered logins using the
TestKeycloakOidcIdentityProviderFactory custom provider. The IDP is created
with the test-keycloak-oidc providerId at realm setup time since providerId
is immutable after creation via the admin API.

Ports TestKeycloakOidcIdentityProviderFactory to tests/custom-providers.
The legacy original is kept in place (not removed) - it is still used by
other, not-yet-migrated legacy tests (KcCustomOidcBrokerTest,
KcOidcFirstBrokerLoginTest, PasskeysKcOidcFirstBrokerLoginTest), confirmed
via grep. No dependency on the other custom-provider migrations (keycloak#52383,
coordinate.

Adapted to the merged abstract-class baseline: extends AbstractKcOidcBrokerTest
for the shared infra (provider realm uses the default config, only consumer
is customized), but overrides and @Disables the two inherited login tests
(testLogInAsUserInIDP, testLoginWithExistingUser) - legacy explicitly
@ignore'd the same inherited test for this exact configuration (no
client-forwarded prompt, custom provider factory), so this mirrors that
rather than risk introducing untested, possibly-failing coverage. The two
real tests (loginWithExistingUser without the "test" prefix, and
testEnforceReAuthenticationWhenMaxAgeIsSet) are independent methods that
exercise the max_age-specific flows directly, matching the phase-2 branch
this content was sourced from.

The consumer IDP clears the prompt attribute set by the shared config so the
broker does not force an interactive login, mirroring the legacy
KcOidcBrokerConfigurationWithPassMaxAge; without it the ignore-max-age error
path is never exercised.

Carries forward the fixes from prior batches (independently re-derived per
batch since this branch is off upstream/main): visibility widening,
configureBrokerEndpoints() placeholder-matching fix, enableUnmanagedAttributes(),
disableUpdateProfileOnFirstLogin(), and the assertUserCreatedInConsumerRealm()
extraction.

Closes keycloak#52249

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
@sguilhen
sguilhen force-pushed the 52249-broker-oidc-pass-max-age branch from cfc88df to 876d20d Compare September 4, 2026 16:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pedroigor
pedroigor merged commit b68ffa1 into keycloak:main Sep 4, 2026
94 checks passed
@sguilhen
sguilhen deleted the 52249-broker-oidc-pass-max-age branch September 21, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate KcOidcBrokerPassMaxAgeTest and port TestKeycloakOidcIdentityProviderFactory

3 participants