8000 Migrate authz tests to new framework by edewit · Pull Request #51836 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Migrate authz tests to new framework - #51836

Open
edewit wants to merge 35 commits into
keycloak:mainfrom
edewit:migration-authz-50754
Open

edewit wants to merge 35 commits into
keycloak:mainfrom
edewit:migration-authz-50754

Conversation

@edewit
@edewit edewit commented Aug 19, 2026
Copy link
Copy Markdown
Contributor
  • Migrate authz package tests to the new testsuite (part 1)
  • Migrate authz admin AuthorizationTest to the new testsuite

fixes: #50754

Copilot AI balanced review requested due to automatic review settings August 19, 2026 06:58
@edewit
edewit requested review from a team as code owners August 19, 2026 06:58
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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Migrates Keycloak authorization tests toward the newer test framework by switching to JUnit Jupiter and introducing testframework injections (realm/events/run-on-server/OAuth), along with a package rename from org.keycloak.testsuite.* to org.keycloak.tests.*.

Changes:

  • Renamed test packages from org.keycloak.testsuite.authz... to org.keycloak.tests.authz....
  • Switched many tests from JUnit 4 annotations (@Test, @Before, @After) to JUnit Jupiter equivalents, and introduced @KeycloakIntegrationTest.
  • Replaced direct testRealmResource() / testingClient.server().run(...) usage with ManagedRealm / RunOnServerClient injections in several tests.

Reviewed changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/UserPolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/TimePolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ScopePermissionManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ScopeManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/RolePolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ResourceServerManagementTest.java Package rename + ManagedRealm admin access
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ResourcePermissionManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ResourceManagementWithAuthzClientTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ResourceManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/JSPolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ImportAuthorizationSettingsTest.java JUnit Jupiter lifecycle + ManagedRealm usage
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/GroupPolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/GenericPolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/GenericPolicyManagementAdminEventTest.java Package rename + ManagedRealm update usage
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ExportAuthorizationSettingsTest.java ManagedRealm admin access for clients/roles
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/ClientPolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/AuthorizationTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/AuthorizationDisabledInPreviewTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/AggregatePolicyManagementTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/AbstractPolicyManagementTest.java Base class migration to testframework/JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/admin/AbstractAuthorizationTest.java Base class migration to testframework/JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedPermissionServiceTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedAccessTest.java Events/run-on-server migration + JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaResourceTypeRepresentationTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaPermissionTicketPushedClaimsTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaGrantTypeTest.java OAuth/timeoffset injection + JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UmaDiscoveryDocumentTest.java Migratio 8000 n off testsuite base + OAuth injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/ScriptCacheTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/RolePolicyTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/RegexPolicyTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/ProtectionResourceTest.java JUnit Jupiter assertions/lifecycle migration
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/PolicyEvaluationTest.java run-on-server migration + JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/PolicyEvaluationCompositeRoleTest.java run-on-server migration + JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/PermissionManagementTest.java run-on-server migration + JUnit Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/PermissionEqualsTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/PermissionClaimTest.java OAuth injection + JUnit Jupiter lifecycle
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/GroupPathWithoutGroupClaimPolicyTest.java Package rename + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/GroupPathPolicyTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/GroupNamePolicyTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/EntitlementAPITest.java Events/OAuth/timeoffset migration + Jupiter
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/ConflictingScopePermissionTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/ClientScopePolicyTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AuthzClientTest.java Package rename + Jupiter + env rule retained
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AuthzClientCredentialsTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AuthorizationTest.java JUnit Jupiter lifecycle + testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AuthorizationAPITest.java OAuth injection + JUnit Jupiter lifecycle
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AttributeTest.java Package rename + JUnit Jupiter/testframework injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AbstractResourceServerTest.java Base class annotation + injection
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AbstractAuthzTest.java Base class migration to testframework/JUnit Jupiter

💡 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 August 19, 2026 13:10
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.

Pull request overview

Copilot reviewed 51 out of 51 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/AbstractAuthzTest.java:1

  • There are now two AbstractAuthzTest base classes (this one in org.keycloak.testsuite.authz and a new one in org.keycloak.tests.authz), and they are using different test engines (this one still imports JUnit 4 @BeforeClass). This duplication + mixed lifecycle annotations increases the risk of divergence and confusion when migrating the remaining tests. Consider consolidating to a single base implementation and aligning lifecycle annotations with the chosen test engine (Jupiter) to reduce maintenance overhead.

Copilot AI review requested due to automatic review settings August 24, 2026 08:02
@edewit
edewit force-pushed the migration-authz-50754 branch from e22a8f2 to 4626439 Compare August 24, 2026 08:02
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.

Pull request overview

Copilot reviewed 51 out of 51 changed files in this pull request and generated 1 comment.

Suppressed comments (15)

tests/base/src/test/java/org/keycloak/tests/authz/AbstractResourceServerTest.java:60

  • A bare @InjectRealm creates an empty, generated-name realm, while these tests require the authz-test realm, users, roles, and clients built in addTestRealms. The new framework never calls that legacy hook, so provide a RealmConfig here (or per subclass) that reproduces this setup.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractAuthorizationTest.java:55
  • This class still relies on the Arquillian AbstractClientTest lifecycle and its adminClient/page resources, but Jupiter does not invoke the inherited JUnit 4 setup. The injected realm also uses the empty default configuration rather than createTestRealm(), leaving the admin authorization tests without their expected realm and client.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractPolicyManagementTest.java:17
  • Moving this base into tests/base does not migrate its setup: addTestRealms, JUnit 4 @BeforeClass, and JUnit 4 @Before are not invoked for the Jupiter subclasses. Consequently the policy fixtures are never imported or configured; convert this base to the new realm/configuration and Jupiter lifecycle APIs.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaDiscoveryDocumentTest.java:17
  • This test was only repackaged and still uses the Arquillian base, @ArquillianResource, and JUnit 4 @Test; it has no new-framework integration or injected OAuth client/realm. It therefore remains on the old runner rather than being executable as a migrated tests/base test.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ScopeManagementTest.java:45
  • The methods in this class still use org.junit.Test, so they run on the JUnit 4 engine and the Jupiter @KeycloakIntegrationTest extension does not initialize managedRealm. Switch the test annotation import to Jupiter.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ResourceManagementTest.java:56
  • The methods in this class still use org.junit.Test, so they run on the JUnit 4 engine and the Jupiter @KeycloakIntegrationTest extension does not initialize managedRealm. Switch the test annotation import to Jupiter.
    tests/base/src/test/java/org/keycloak/tests/authz/AuthzClientTest.java:15
  • After switching this class to Jupiter, the JUnit 4 @Rule is ignored. envVars.set(...) still mutates the process environment, but the rule no longer restores it after the test, so later tests can observe these values; replace it with a Jupiter-compatible environment extension or explicit restoration.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:106
  • Jupiter does not apply the retained JUnit 4 ExpectedException rule. The two tests that configure expectedException will let their expected AuthorizationDeniedException escape and fail; migrate those assertions to assertThrows and assert the cause/message explicitly.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:124
  • This Jupiter test still expects Arquillian to inject ContainerController, which the new extension does not do. testServerRestart dereferences this field at lines 1969-1970, so it will fail with a null controller; migrate the restart scenario to a new-framework server control facility.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AuthorizationDisabledInPreviewTest.java:40
  • @KeycloakIntegrationTest runs this class with Jupiter, so the JUnit 4 @BeforeClass method is ignored. The feature-disabled assumption is never applied, and the default server configuration does not disable authorization; use a custom KeycloakServerConfig with featuresDisabled(AUTHORIZATION) and a Jupiter lifecycle hook if the assumption is still needed.
    tests/base/src/test/java/org/keycloak/tests/authz/UserManagedPermissionServiceTest.java:86
  • The new framework does not process the Arquillian @EnableFeature, and its default server config does not enable the preview SCRIPTS feature. Configure @KeycloakIntegrationTest with a server config that calls features(Feature.SCRIPTS) or script-policy creation will fail.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaPermissionTicketPushedClaimsTest.java:52
  • The new framework does not process the Arquillian @EnableFeature, and its default server config does not enable the preview SCRIPTS feature. Configure @KeycloakIntegrationTest with a server config that calls features(Feature.SCRIPTS) or script-policy creation will fail.
    tests/base/src/test/java/org/keycloak/tests/authz/PermissionClaimTest.java:74
  • The new framework does not process the Arquillian @EnableFeature, and its default server config does not enable the preview SCRIPTS feature. Configure @KeycloakIntegrationTest with a server config that calls features(Feature.SCRIPTS) or script-policy creation will fail.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/JSPolicyManagementTest.java:45
  • The new framework does not process the Arquillian @EnableFeature, and its default server config does not enable the preview SCRIPTS feature. Configure @KeycloakIntegrationTest with a server config that calls features(Feature.SCRIPTS) or script-policy creation will fail.
    tests/base/src/test/java/org/keycloak/tests/authz/PolicyEvaluationTest.java:95
  • The new framework does not process the Arquillian @EnableFeature, and its default server config does not enable the preview SCRIPTS feature. Configure @KeycloakIntegrationTest with a server config that calls features(Feature.SCRIPTS) or script-policy creation will fail.

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.

Pull request overview

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

Suppressed comments (16)

Previously missed (3) — in code that hasn't changed since the last review.

tests/base/src/test/java/org/keycloak/tests/authz/PermissionEqualsTest.java:41

  • This is a pure value-object unit test and never uses the injected realm or server. Marking it as an integration test creates a realm and starts framework resources unnecessarily; keep only the Jupiter @Test methods and remove the integration annotation/injection.
    tests/base/src/test/java/org/keycloak/tests/authz/AttributeTest.java:47
  • This test only exercises an in-memory Attributes object and does not use Keycloak or managedRealm. Registering it as an integration test adds avoidable server/realm setup; migrate it as a plain Jupiter unit test instead.
    tests/base/src/test/java/org/keycloak/tests/authz/ScriptCacheTest.java:45
  • The test operates entirely on a local ScriptCache and never uses the injected realm. Running it through @KeycloakIntegrationTest adds unnecessary server and realm lifecycle overhead; leave it as a plain Jupiter test.

tests/base/src/test/java/org/keycloak/tests/authz/AbstractResourceServerTest.java:60

  • This injection creates an empty generated realm, while the unchanged addTestRealms method is a legacy JUnit/Arquillian hook and is never called by the new extension. Every resource-server test therefore looks up the nonexistent authz-test realm and resource-server-test client; provide an @InjectRealm(config = ...) configuration containing this setup.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractAuthorizationTest.java:52
  • The new framework creates only the default empty managed realm here; the legacy addTestRealms hook below is not executed. The admin tests immediately search this realm for resource-server-test, so they fail before exercising their assertions unless createTestRealm() is supplied through an @InjectRealm RealmConfig.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractPolicyManagementTest.java:77
  • Changing this lifecycle method to Jupiter does not provision the realm built by addTestRealms; that legacy hook is no longer invoked. Concrete subclasses inject the default empty realm, while this setup accesses authz-test and resource-server-test, so convert createTestRealm() into the RealmConfig used by their @InjectRealm fields.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ScopeManagementTest.java:45
  • This class still uses JUnit 4 org.junit.Test methods. tests/base has no Vintage engine, so adding the Jupiter integration annotation does not make any of these tests discoverable; migrate all test annotations to org.junit.jupiter.api.Test.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ResourceManagementTest.java:56
  • This class still uses JUnit 4 org.junit.Test methods. tests/base has no Vintage engine, so the Jupiter suite will not discover them despite @KeycloakIntegrationTest; migrate every test annotation in this file to JUnit Jupiter.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaDiscoveryDocumentTest.java:18
  • Only the package was moved: this test still uses JUnit 4 plus Arquillian injection and has no @KeycloakIntegrationTest. Since tests/base does not include the Vintage engine, the test is no longer discovered; migrate its runner resources and test annotations to the new framework.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:1969
  • Under the new framework these Arquillian fields are never injected, so this condition is always false and the server restart is silently skipped. That removes the core persistence check from testOfflineRequestingPartyToken; use the new framework's server lifecycle support or explicitly disable the test until restart is supported.
    tests/base/src/test/java/org/keycloak/tests/authz/PermissionClaimTest.java:74
  • The legacy @EnableFeature annotation is not processed by KeycloakIntegrationTestExtension, and the default server config does not enable SCRIPTS. This class creates JavaScript policies, so configure the new framework with the existing script-enabled server config.
    tests/base/src/test/java/org/keycloak/tests/authz/PolicyEvaluationTest.java:95
  • The legacy @EnableFeature annotation is not processed by the new test extension, leaving SCRIPTS disabled under the default server config. Configure this migrated test with the existing script-enabled server config.
    tests/base/src/test/java/org/keycloak/tests/authz/UserManagedPermissionServiceTest.java:86
  • The new test extension ignores the retained Arquillian @EnableFeature, so SCRIPTS remains disabled and the script-policy scenarios cannot run. Use the existing script-enabled new-framework server config.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaPermissionTicketPushedClaimsTest.java:52
  • The retained Arquillian @EnableFeature does not configure the new test server, whose default config leaves SCRIPTS disabled. Point this class at the existing script-enabled server config.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/JSPolicyManagementTest.java:45
  • @EnableFeature is an Arquillian annotation and is ignored by the new framework, so this test starts a server without SCRIPTS and cannot create JavaScript policies. Configure @KeycloakIntegrationTest with the existing script-enabled server config.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AuthorizationDisabledInPreviewTest.java:37
  • This test no longer starts a server with AUTHORIZATION disabled; the default new-framework config enables it, and the method merely aborts after making a successful request. Add a KeycloakServerConfig that disables Profile.Feature.AUTHORIZATION so the disabled-feature behavior is actually exercised.

Copilot AI review requested due to automatic review settings August 24, 2026 13:12
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.

Pull request overview

Copilot reviewed 54 out of 54 changed files in this pull request and generated 1 comment.

Suppressed comments (12)

Previously missed (1) — in code that hasn't changed since the last review.

tests/base/src/test/java/org/keycloak/tests/authz/admin/GenericPolicyManagementAdminEventTest.java:41

  • This remains a legacy hook rather than a Jupiter lifecycle callback, and the migrated hierarchy never invokes it. As a result admin events are not enabled for this test class; make this setup an explicit @BeforeEach callback (after the managed realm migration).

tests/base/src/test/java/org/keycloak/tests/authz/admin/ScopeManagementTest.java:45

  • This class still imports JUnit 4's org.junit.Test; the Jupiter engine that applies @KeycloakIntegrationTest will therefore not discover its test methods. Switch the import to JUnit Jupiter.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ResourceManagementTest.java:56
  • This class still imports JUnit 4's org.junit.Test; the Jupiter engine that applies @KeycloakIntegrationTest will therefore omit these methods, including inherited coverage in ResourceManagementWithAuthzClientTest. Switch the import to JUnit Jupiter.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaDiscoveryDocumentTest.java:17
  • Only the package was moved here: the class still uses JUnit 4, Arquillian injection, and lacks @KeycloakIntegrationTest. It will not run under the new test framework, so this test needs a full Jupiter/framework migration rather than just relocation.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:1969
  • In the new framework both Arquillian fields are null, so this guard always skips the server restart and testOfflineRequestingPartyToken merely introspects against the same process. Use the new framework's restart mechanism so the test continues to verify token persistence across a restart.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AuthorizationDisabledInPreviewTest.java:53
  • Base2TestSuite now always enables AUTHORIZATION, so this branch aborts the test on every suite run and the disabled-feature behavior is never exercised. Move this test to a server configuration with AUTHORIZATION disabled instead of converting success into an assumption failure.
    tests/base/src/test/java/org/keycloak/tests/authz/AuthzClientTest.java:18
  • This replaces the process-wide crypto provider and never restores it. Because this test now runs in the shared Base2 JVM and AuthzClientCryptoProvider leaves many operations unsupported, later tests become order-dependent; preserve and restore the prior provider in a finally block.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractAuthorizationTest.java:52
  • This injection creates a separate default realm, while addTestRealms describes authz-test; JUnit 5 does not execute AbstractKeycloakTest's JUnit 4 import lifecycle. Consequently findClientResource searches the default realm, where resource-server-test does not exist, and the admin tests fail during setup. Configure the managed realm from createTestRealm() and use it consistently instead of retaining the legacy import contract.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractPolicyManagementTest.java:76
  • After changing this to @BeforeEach, setup runs under Jupiter, but nothing invokes addTestRealms; the inherited importer is a JUnit 4 lifecycle method. The injected realms in concrete subclasses use the default configuration, so authz-test and resource-server-test are absent and this setup fails. Migrate createTestRealm() into a RealmConfig-backed @InjectRealm and use that managed realm here.
    tests/base/src/test/java/org/keycloak/tests/authz/AbstractAuthzTest.java:45
  • This reimplements realm import instead of calling the polymorphic importTestRealms(). As a result AbstractResourceServerTest.importTestRealms() never initializes koloId/martaId; additionally, AuthorizationAPITest.addTestRealms() dereferences testingClient before it is initialized. Initialize the testing client and invoke the existing import method, then record the imported names for cleanup.
        testRealmReps = new ArrayList<>();
        addTestRealms(testRealmReps);
        for (RealmRepresentation realmRepresentation : testRealmReps) {
            importRealm(realmRepresentation);
            importedRealmNames.add(realmRepresentation.getRealm());
        }

tests/base/src/test/java/org/keycloak/tests/authz/UserManagedAccessTest.java:88

  • Events is bound to the injected default ManagedRealm, but this test performs logins in the separately imported authz-test realm. Calls such as events.poll() therefore query the wrong realm and cannot observe the asserted permission events. Make authz-test the framework-managed realm (or otherwise bind InjectEvents to that managed instance).
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:146
  • Events depends on the default injected ManagedRealm, while all authorization requests in this class target the separately imported authz-test realm. The migrated event assertions will poll the wrong realm; configure authz-test as the managed realm and bind Events to it.

Copilot AI review requested due to automatic review settings August 25, 2026 07:08
@edewit
edewit force-pushed the migration-authz-50754 branch from 5edfeb1 to e341f11 Compare August 25, 2026 07:08
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.

Pull request overview

Copilot reviewed 54 out of 54 changed files in this pull request and generated 1 comment.

Suppressed comments (9)

tests/base/src/test/java/org/keycloak/tests/authz/AbstractAuthzTest.java:48

  • Calling importRealm directly bypasses overrides of importTestRealms; for example, AbstractResourceServerTest.importTestRealms() initializes koloId and martaId, so the migrated event assertions currently compare against null. Invoke the lifecycle method and only record the imported names afterward.
        addTestRealms(testRealmReps);
        for (RealmRepresentation realmRepresentation : testRealmReps) {
            importRealm(realmRepresentation);
            importedRealmNames.add(realmRepresentation.getRealm());

tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractAuthorizationTest.java:52

  • This default @InjectRealm creates an empty, generated realm; the Jupiter extension does not invoke the legacy addTestRealms, so resource-server-test is absent and getClientResource() returns null. Provision createTestRealm() through a new-framework realm config (or explicitly import/remove it in Jupiter lifecycle methods).
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractPolicyManagementTest.java:57
  • Injecting only the admin client does not create authz-test; under Jupiter the legacy beforeAbstractKeycloakTest that calls addTestRealms is not executed, so configureAuthorization() targets a nonexistent realm. Migrate this hierarchy's realm setup to @InjectRealm(config = ...) or an explicit Jupiter setup/cleanup bridge.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ScopeManagementTest.java:45
  • The methods in this migrated class still use JUnit 4's @Test, so they run through the inherited Arquillian runner (or are skipped) instead of the new Jupiter extension. Use the Jupiter annotation as in the other migrated classes.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ResourceManagementTest.java:56
  • The methods in this migrated class still use JUnit 4's @Test, so they run through the inherited Arquillian runner (or are skipped) instead of the new Jupiter extension. Use the Jupiter annotation as in the other migrated classes.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaDiscoveryDocumentTest.java:18
  • Moving this class into the selected org.keycloak.tests.authz package without converting it leaves it entirely on JUnit 4/Arquillian (@ArquillianResource, legacy OAuth client, and no @KeycloakIntegrationTest). It will not execute with the intended new-framework lifecycle; migrate those dependencies before including it in Base2.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:1969
  • In the Jupiter framework these Arquillian resources are not injected, so this condition is always false and the offline-token test no longer restarts the server—the behavior it is intended to cover. Replace the conditional with the new framework's server restart facility and reconnect any clients as required.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/GenericPolicyManagementAdminEventTest.java:41
  • This override is only called from the legacy JUnit 4 beforeAbstractKeycloakTest lifecycle, which is not executed by @KeycloakIntegrationTest; consequently admin events are never enabled for this subclass. Move this setup to a Jupiter @BeforeEach method (after the managed realm has been provisioned).
    tests/base/src/test/java/org/keycloak/tests/authz/AbstractResourceServerTest.java:59
  • This injected realm is a separate default realm from the manually imported authz-test. New-framework resources such as @InjectEvents bind to this managed realm, so UserManagedAccessTest and EntitlementAPITest poll the wrong realm (and the events interceptor enables events on the wrong realm). Provision authz-test through this managed realm instead of maintaining two realm lifecycles.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.federation.ldap.LDAPGroupMapperTest#test01_ldapOnlyGroupMappings

Keycloak CI - Base IT (5)

org.opentest4j.AssertionFailedError: expected: <4> but was: <2>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
...

Report flaky test

Copilot AI review requested due to automatic review settings August 26, 2026 10:19
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.

Pull request overview

Copilot reviewed 57 out of 57 changed files in this pull request and generated 2 comments.

Suppressed comments (12)

Previously missed (4) — in code that hasn't changed since the last review.

tests/base/src/test/java/org/keycloak/tests/authz/admin/AuthorizationDisabledInPreviewTest.java:54

  • The Base2 suite explicitly enables AUTHORIZATION, so the new-framework path always reaches this assumption and aborts the test instead of testing the disabled-feature response. Give this class a server config that disables Profile.Feature.AUTHORIZATION and retain the failure assertion rather than converting success into a skipped test.
    tests/base/src/test/java/org/keycloak/tests/authz/EntitlementAPITest.java:1969
  • Under the new framework both Arquillian fields are null, so this guard permanently skips the server restart and the test no longer verifies that an offline RPT survives a restart. Migrate this step to a new-framework restart mechanism rather than silently omitting the core operation.
    tests/base/src/test/java/org/keycloak/tests/authz/ProtectionResourceTest.java:47
  • This cleanup is registered on the unrelated injected realm. Framework cleanup runs after user @AfterEach methods, but AbstractAuthzTest.afterAuthzTest() has already deleted authz-test, so this callback attempts to update a removed authorization resource and can fail cleanup with 404. Restore this setting before the manual realm teardown (or make authz-test the managed realm).
    tests/base/src/test/java/org/keycloak/tests/authz/RolePolicyTest.java:181
  • This callback is attached to the generated managed realm but closes over a client in the manually imported authz-test realm. It executes only after AbstractAuthzTest.afterAuthzTest() deletes that realm, so cleanup can fail with 404; run it before realm removal or manage authz-test through ManagedRealm.

This issue also appears on line 211 of the same file.

tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractAuthorizationTest.java:52

  • @InjectRealm creates an empty generated realm by default; the JUnit 5 extension does not invoke the legacy addTestRealms/JUnit 4 setup that creates authz-test and resource-server-test. Consequently getClientResource() returns null for every subclass; configure the injected realm with createTestRealm() (or add an explicit Jupiter import lifecycle) and consistently use that realm.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/AbstractPolicyManagementTest.java:80
  • This Jupiter setup accesses authz-test, but no Jupiter lifecycle imports the realm returned by addTestRealms; the inherited importer is JUnit 4 @Before and is not run by Jupiter. All policy-management tests therefore reach this method without resource-server-test; migrate realm creation into @InjectRealm or add a Jupiter import/cleanup lifecycle.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ScopeManagementTest.java:45
  • The class enables the Jupiter extension, but its test methods still use JUnit 4 @Test; Jupiter will not execute those methods with the injected realm. Change this import to the Jupiter annotation.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/ResourceManagementTest.java:56
  • The class enables the Jupiter extension, but its test methods still use JUnit 4 @Test; Jupiter will not execute those methods with the injected realm. Change this import to the Jupiter annotation.
    tests/base/src/test/java/org/keycloak/tests/authz/UmaDiscoveryDocumentTest.java:17
  • Moving this class into org.keycloak.tests.authz makes the new suite select it, but it remains a JUnit 4/Arquillian test using @ArquillianResource and fixed legacy URLs, with no @KeycloakIntegrationTest. It therefore is not actually migrated to or executed by the Jupiter framework; migrate its annotations/resources and URLs before moving the package.
    tests/base/src/test/java/org/keycloak/tests/authz/AuthzClientTest.java:18
  • This overwrites the process-wide crypto provider and never restores it. Because the framework only installs DefaultCryptoProvider when CryptoIntegration is uninitialized, later integration tests can inherit AuthzClientCryptoProvider, whose algorithm/certificate methods throw UnsupportedOperationException; save the previous provider and restore it in finally/@AfterEach.
    tests/base/src/test/java/org/keycloak/tests/authz/admin/GenericPolicyManagementAdminEventTest.java:41
  • This update remains inside the legacy afterAbstractKeycloakTestRealmImport hook, which the Jupiter extension does not invoke, so this subclass never enables admin events. Convert the override into a Jupiter lifecycle callback.
    tests/base/src/test/java/org/keycloak/tests/authz/RolePolicyTest.java:214
  • This managed-realm cleanup also targets the manually imported authz-test client and runs after that realm has been deleted by the superclass @AfterEach. Move this restoration ahead of manual realm teardown or use a ManagedRealm representing authz-test.

Copilot AI review requested due to automatic review settings August 26, 2026 10:59
edewit added 29 commits December 4, 2026 14:48
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
AuthzClientCryptoProvider was leaking into later Base2TestSuite tests and
breaking ManagedCertificates setup.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Admin policy and authorization tests still extended AbstractKeycloakTest
without importing the authz-test realm. Extend AbstractAuthzTest so realm
setup runs b
10BC8
efore configureAuthorization, and fix client lookup to use
the imported realm.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Remove the private authzConfigurationStream helper now that admin tests
extend AbstractAuthzTest, which already provides the protected method.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Load custom test providers in Base2, remove unavailable event-queue listener,
add test policy provider to custom-providers, and migrate UmaDiscoveryDocumentTest
to the new test framework.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Rewrite authz client config URLs, use test realm OIDC endpoints in UMA
discovery test, deploy script policies, fix export test client realm, and
replace Arquillian cleanup in policy evaluation test.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Decouple authz tests from the legacy Arquillian base, enable realm events
for manual Events wrappers, use KeycloakServerConfig for SCRIPTS, and fix
API drift in PolicyEvaluationTest and UmaDiscoveryDocumentTest.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Assign the injected admin client to the shared realm support field so
authz tests can import realms during @beforeeach setup.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Use integration-arquillian-testsuite-providers instead of the empty
deployment artifact so custom policy providers and test application
endpoints are available to migrated authz tests.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Use dynamic auth server and sector identifier URLs for pairwise clients,
invoke afterImportTestRealms for user ID setup, and resolve token endpoint
from the injected OAuth client instead of legacy static URLs.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Poll events via the testsuite testing SPI like legacy AssertEvents,
migrate remaining JUnit 4 admin tests to Jupiter, and isolate OAuth
client config in the public client claims test.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Register TestEventsListenerProvider when importing authz test realms so
pollEvent() works, and fix ScopeManagementTest policy scope assertion.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copy deployed script policies into keycloak-tests-custom-scripts, wire
that dependency into AuthzScriptsServerConfig/Base2ServerConfig, create
alice in the authz-test realm for import settings, use InjectRunOnServer
for UMA permission cleanup checks, and fix the public-client claims test.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
AUTHORIZATION is already a default feature; enabling it in the suite
conflicted with AuthorizationDisabledInPreviewTest which disables it.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Clear leaked OAuth offline_access scope between EntitlementAPITest methods,
disable ADMIN_FINE_GRAINED_AUTHZ_V2 with AUTHORIZATION so the preview-disabled
server can start, and give migrated authz tests DefaultAuthzServerConfig with
testsuite providers.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Drop arquillian and system-rules dependencies from tests/base, move
authz policy test providers into custom-providers, and switch the
migrated authz base to framework SectorIdentifier/events APIs. Also fix
KEYCLOAK-4340 realm lookup, authz-client cleanup, AuthzClient HTTP
client reuse, and restore env-var substitution coverage.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
PERMISSION_TOKEN_ERROR is not saveByDefault, so enable all EventTypes
when configuring migrated authz test realms for admin-API event asserts.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Use the injected RunOnServerClient so the migrated PolicyEvaluation and
UserManagedPermission tests compile under the new framework.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Also remove unused Assertions imports that failed Spotless check.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
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.

🟡 Changes recommended

Authorization tests still use clients without framework-managed certificates, causing discovery and authorization requests to fail in TLS/mTLS runs.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment on lines +145 to +149
String authServerRoot = authServerRoot();
String config = new String(input.readAllBytes(), StandardCharsets.UTF_8)
.replace("http://localhost:8180/auth", authServerRoot)
.replace("https://localhost:8543/auth", authServerRoot);
return new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8));
public void testFetchDiscoveryDocument() {
Client client = AdminClientUtil.createResteasyClient();
UriBuilder builder = UriBuilder.fromUri(OAuthClient.AUTH_SERVER_ROOT);
Client client = ClientBuilder.newClient();
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 authz package to the new test framework

4 participants

0