8000 [Test Framework] Fixing ManagedClient updateWithCleanup, when using non-managed client with attachTo. by lhanusov · Pull Request #48109 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[Test Framework] Fixing ManagedClient updateWithCleanup, when using non-managed client with attachTo. - #48109

Closed
lhanusov wants to merge 1 commit into
keycloak:mainfrom
lhanusov:test-framework/client-cleanup
Closed

lhanusov wants to merge 1 commit into
keycloak:mainfrom
lhanusov:test-framework/client-cleanup

Conversation

@lhanusov
@lhanusov lhanusov commented Apr 15, 2026 •
Copy link
Copy Markdown
Contributor

Closes #48263

@lhanusov
lhanusov force-pushed the test-framework/client-cleanup branch 2 times, most recently from f91f88f to 4a0b496 Compare April 20, 2026 09:41
@lhanusov
lhanusov marked this pull request as ready for review April 20, 2026 09:41
@lhanusov
lhanusov requested a review from a team as a code owner April 20, 2026 09:41
@lhanusov
lhanusov force-pushed the test-framework/client-cleanup branch 2 times, most recently from 1f7cee9 to f4192bc Compare April 20, 2026 10:14
@lhanusov lhanusov added the area/test-framework Test framework — infrastructure, Realm DSL, page objects, migration utils label Apr 20, 2026
…on-managed client with attachTo.

Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
@lhanusov
lhanusov force-pushed the test-framework/client-cleanup branch from f4192bc to 7fc6f92 Compare April 20, 2026 10:40
@lhanusov
lhanusov requested a review from stianst April 20, 2026 12:44
@lhanusov lhanusov self-assigned this Apr 20, 2026
@lhanusov
lhanusov requested a review from vaceksimon April 20, 2026 12:44
@stianst stianst 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.

There's a few issues with this approach; in ManagedClient constructor you are fetching the representation resulting in an extra call to Keycloak everytime we create a client, which is not needed as we already have that in createdRepresentation.

In the ManagedClient close method you are re-creating the client, which is rather against what is intended in the close method.

I'm not really convinced we should support cleanup for non-managed clients, but if we really want to do that we need a different approach. I'd probably say the updateWithCleanup should use dirty for managed clients, while for non-managed clients it would add a cleanup task that resets it to the createdRepresentation.

A last thing is I don't see why this is hardcoding the special admin-client client as a client that can't be updated.

@stianst
stianst commented May 20, 2026
Copy link
Copy Markdown
Contributor

I question whether or not we really should support cleanup with non-managed clients, users, etc. It feels like an anti-pattern (honestly I don't quite like the attachTo in the first place), and it also adds a lot of complexity/overhead.

I would argue that a better/simpler approach would be to simply not support any cleanup with non-managed resources. For those probably very few cases where it is needed that can be handled with ManagedRealm#updateUserWithCleanup - we can add the same for clients.

@stianst stianst 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.

Thinking about this more I'm not in favour of adding this; the framework really shouldn't support cleanup for non-managed (it's kinda in the name right?) clients. Rather, looking at how attachTo is used, in general it is abused, and there's better ways to write tests than attaching to existing clients.

@lhanusov
Copy link
Copy Markdown
Contributor Author

this issue is not fixing the problem rather creating a shady behavior, instead we plan to remove the attachTo functionality from ManagedClient.

@lhanusov lhanusov closed this May 20, 2026
Sign up for free to join this conversation on GitHub. 7AF5 Already have an account? Sign in to comment

Labels

area/test-framework Test framework — infrastructure, Realm DSL, page objects, migration utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test Framework] Add support for custom clients with attachTo to enable automated cleanup.

2 participants

0