Skip to content

Migrated following keycloak-quickstart extension tests using new keyc…#741

Open
jimmychakkalakal wants to merge 1 commit intokeycloak:mainfrom
jimmychakkalakal:issue-test-migration-java-extension
Open

Migrated following keycloak-quickstart extension tests using new keyc…#741
jimmychakkalakal wants to merge 1 commit intokeycloak:mainfrom
jimmychakkalakal:issue-test-migration-java-extension

Conversation

@jimmychakkalakal
Copy link
Copy Markdown

Migrated following keycloak-quickstart extension tests using new keycloak testframework:

Tests under extension/action-token-authenticator and extension/action-token-required-action

Closes #739

…loak testframework:

Tests under extension/action-token-authenticator and extension/action-token-required-action

Closes keycloak#739

Signed-off-by: Jimmy Chakkalakal <[email protected]>
@mposolda mposolda self-assigned this Apr 16, 2026
@mposolda mposolda requested a review from lhanusov April 16, 2026 10:18
Copy link
Copy Markdown
Contributor

@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@jimmychakkalakal Thanks for the PR!

The idea looks good.

I think test failures in node.js and javascript tests in GH actions are not related to your PR and hence are out of scope.

It is unfortuate that action-token quickstarts still need Wildfly AFAIK and hence I guess that is the reason why arquillian+wildfly still needs to be used in the action-token quickstart?

It will be ideal if we can get rid of the arquillian in the action-token quickstarts. That will probably require those action-token quickstarts to not use Wildfly. Which we can hopefully do (either by deploying custom REST endpoint provider to Keycloak, or by using quarkus instead of Wildfly). But I suppose that might be a follow-up of this task. As initial PR, this is OK to me.

@lhanusov Do you please have opportunity to review?

@jimmychakkalakal
Copy link
Copy Markdown
Author

jimmychakkalakal commented Apr 16, 2026

It is unfortuate that action-token quickstarts still need Wildfly AFAIK and hence I guess that is the reason why arquillian+wildfly still needs to be used in the action-token quickstart? --> Yes,

@lhanusov
Copy link
Copy Markdown
Contributor

Hi Marek and Jimmy, @mposolda @jimmychakkalakal, did you consider using testcontainers: https://java.testcontainers.org/features/creating_container/ for using wildfly?

@abstractj
Copy link
Copy Markdown

@lhanusov honestly I don't see a reason for us to invest any more time on quickstarts with WildFly. Ideally we should plan the migration to Quarkus.

Copy link
Copy Markdown
Contributor

@lhanusov lhanusov left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of it Jimmy. To correlate with the new test framework, few changes must be done, before merging it. Please, let me know if you need any help with it. Thanks

static ManagedRealm realm;

@Drone
private WebDriver webDriver;
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.

Please, don't use Drone from Arquillian, but InjectWebDriver and ManagedWebDriver from the test framework.

private static boolean userCreated = false;

@Deployment(testable=false, name=EXTERNAL_APP)
@TargetsContainer("wildfly")
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.

I propose to use testcontainers lib instead: https://java.testcontainers.org/features/creating_container/


@Before
@BeforeEach
public void setup() {
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.

I don't think this is actually needed, since it's handled by the framework itself. Please, remove the whole method.

oAuthClient.openLoginForm();

// Attempt to login as alice using WebDriver directly
webDriver.findElement(org.openqa.selenium.By.id("username")).sendKeys("alice");
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.

What is the reason to use the WebDriver directly instead of the LoginPage?

}
}

private void createUserIfNeeded() {
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.

Why don't you use ManagedUser instead? ManagedUser has Class lifecycle, that means it's created once.

@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
@KeycloakIntegrationTest(config = ArquillianActionTokenTest.ServerConfig.class)
public class ArquillianActionTokenTest {
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.

please, rename it to ActionTokenTest

}

@Before
@BeforeEach
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.

same applies over here, as in the previous test class, this method can be removed

Comment on lines +185 to +234
private void createUserIfNeeded() {
if (userCreated) {
return;
}

UserRepresentation alice = new UserRepresentation();
alice.setUsername("alice");
alice.setEmail("[email protected]");
alice.setFirstName("Alice");
alice.setLastName("Liddel");
alice.setEnabled(true);

CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue("password");
credential.setTemporary(false);
alice.setCredentials(List.of(credential));

jakarta.ws.rs.core.Response response = realm.admin().users().create(alice);
response.close();

userCreated = true;
}

private void setupRequiredActionIfNeeded() {
if (requiredActionConfigured) {
return;
}

// Register the custom required action provider
RequiredActionProviderSimpleRepresentation requiredActionProvider = new RequiredActionProviderSimpleRepresentation();
requiredActionProvider.setProviderId("redirect-to-external-application");
requiredActionProvider.setName("Redirect to external application");
realm.admin().flows().registerRequiredAction(requiredActionProvider);

// Add the new required action to alice user
List<String> reqActions = Arrays.asList("redirect-to-external-application");
realm.admin().users().search("alice").forEach(u -> {
u.setRequiredActions(reqActions);
realm.admin().users().get(u.getId()).update(u);
});

// Enable unmanaged attributes of user profile
UserProfileResource userProfileRes = realm.admin().users().userProfile();
UPConfig cfg = userProfileRes.getConfiguration();
cfg.setUnmanagedAttributePolicy(UPConfig.UnmanagedAttributePolicy.ENABLED);
userProfileRes.update(cfg);

requiredActionConfigured = true;
}
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.

please move it to the RealmConfig

static ManagedRealm realm;

@Drone
private WebDriver webDriver;
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.

please, replace it with InjectWebDriver and ManagedWebDriver

private static boolean userCreated = false;

@Deployment(testable=false, name=EXTERNAL_APP)
@TargetsContainer("wildfly")
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.

please consider for replacing it with testcontainers

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.

Migrate Extension Quickstart tests to Keycloak Test Framework

4 participants