Migrated following keycloak-quickstart extension tests using new keyc…#741
Migrated following keycloak-quickstart extension tests using new keyc…#741jimmychakkalakal wants to merge 1 commit intokeycloak:mainfrom
Conversation
…loak testframework: Tests under extension/action-token-authenticator and extension/action-token-required-action Closes keycloak#739 Signed-off-by: Jimmy Chakkalakal <[email protected]>
There was a problem hiding this comment.
@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?
|
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, |
|
Hi Marek and Jimmy, @mposolda @jimmychakkalakal, did you consider using testcontainers: https://java.testcontainers.org/features/creating_container/ for using wildfly? |
|
@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. |
lhanusov
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
I propose to use testcontainers lib instead: https://java.testcontainers.org/features/creating_container/
|
|
||
| @Before | ||
| @BeforeEach | ||
| public void setup() { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
What is the reason to use the WebDriver directly instead of the LoginPage?
| } | ||
| } | ||
|
|
||
| private void createUserIfNeeded() { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
please, rename it to ActionTokenTest
| } | ||
|
|
||
| @Before | ||
| @BeforeEach |
There was a problem hiding this comment.
same applies over here, as in the previous test class, this method can be removed
| 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; | ||
| } |
There was a problem hiding this comment.
please move it to the RealmConfig
| static ManagedRealm realm; | ||
|
|
||
| @Drone | ||
| private WebDriver webDriver; |
There was a problem hiding this comment.
please, replace it with InjectWebDriver and ManagedWebDriver
| private static boolean userCreated = false; | ||
|
|
||
| @Deployment(testable=false, name=EXTERNAL_APP) | ||
| @TargetsContainer("wildfly") |
There was a problem hiding this comment.
please consider for replacing it with testcontainers
Migrated following keycloak-quickstart extension tests using new keycloak testframework:
Tests under extension/action-token-authenticator and extension/action-token-required-action
Closes #739