Skip to content

Add integration tests with Keycloak #2343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2025
Merged

Add integration tests with Keycloak #2343

merged 3 commits into from
Aug 15, 2025

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Aug 13, 2025

No description provided.

}
// Keycloak Admin Client brings RESTEasy Classic, which conflicts with Quarkus RESTEasy Reactive;
// it must not be present during Quarkus augmentation otherwise Quarkus tests won't start.
compileOnly(libs.keycloak.admin.client)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spent 5 hours today trying to find a better solution for this, but in the end, having both RESTEasy Classic and Reactive on the classpath gets blocked here:

https://github.com/quarkusio/quarkus/blob/072896e711640752ffc3176677591c6d263360e8/extensions/resteasy-reactive/rest-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java#L109-L110

Maybe a better solution would be to isolate the Keycloak container in a separate module, and shade RESTEasy Classic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Having a server runner that launches pre-built jars would help here, I believe... There was a discussion or PR about that somewhere, right?

Copy link
Member

Choose a reason for hiding this comment

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

I recall that RESTEasy classic vs reactive issue from Nessie, where it's resolved this way. But the effect's the same: exclude RESTEasy Classic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest to leave it this way for now and I'll investigate if shading is an option.

Copy link
Member

Choose a reason for hiding this comment

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

+1, shading feels too much.

Copy link
Contributor

@dimas-b dimas-b Aug 14, 2025

Choose a reason for hiding this comment

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

shading is too much for this case :) I'd go with a custom runner... not ok "as is" for now

@adutra adutra force-pushed the keycloak-it branch 3 times, most recently from 22eba9a to 64249ed Compare August 13, 2025 19:50
Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

Nice improvement 👍 ... just one minor comment :)

keycloak.createRole(principalRole);
keycloak.createUser(
principalName,
// Use the same password as the client secret
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? As for me, it detracts from the test's validity because now it is not obvious whether authentication happens locally (client secret) or via Keycloak 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I get your point. This password is never used outside of this class (see method below).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyways, I replaced this with a fixed password for all users. Let me know if that's better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guessed the password was not used outside, but that's also a reason for not using the same password, right? ;) Thx for changing!

Copy link
Contributor

Choose a reason for hiding this comment

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

My point was that if the password is the same (with a specific comment) it creates an expectation that it might be reused somewhere... which is what I wanted to avoid 😅

tokenEndpoint = issuerUrl.resolve("protocol/openid-connect/token");
createRole("ALL");
createUser("root");
assignRoleToUser("ALL", "root");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI I initially forgot to assign PRINCIPAL_ROLE:ALL to root and yet, the tests passed: this is because ActiveRolesProvider automatically infers "all granted roles" when no role is found in the token. This is another reason why I am advocating for merging ActiveRolesProvider into Authenticator.

Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

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

LGTM

Letting @dimas-b take another look though.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Aug 14, 2025
@adutra adutra merged commit c4fc848 into apache:main Aug 15, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in Basic Kanban Board Aug 15, 2025
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