Migrate the AccountRestServiceTest - #49296
Conversation
b14bc3f to
68f2fdb
Compare
7b2bf50 to
69ea8ea
Compare
ca73108 to
116f5b4
Compare
vaceksimon
left a comment
There was a problem hiding this comment.
Great effort on this! It’s a massive PR, so to keep things manageable, let's break the review into a couple of rounds. Let's get these current points squared away first, and then proceed with the rest.
One thing that might save you some effort here: you don't need to migrate all the extending classes just because you're migrating the abstract one. You can absolutely scope this down to just what AccountRestServiceTest needs, and we can let the next developers handle the rest.
| oauth.scope(null); | ||
| setRequiredActionEnabled(managedRealm.admin(), UserModel.RequiredAction.VERIFY_PROFILE, false); | ||
| managedRealm.admin().logoutAll(); | ||
| events.clear(); |
There was a problem hiding this comment.
There was a problem hiding this comment.
Done, have removed them and @beforeeach. there are still two events.clear() calls in the tests but those are not dead. the events.clear() actually needed cause they drain login events before checking specific subsequent events. otherwise can't pass the ci/cd. let me know if you prefer a different pattern :)
a6b6534 to
315e940
Compare
69fb906 to
481e4cc
Compare
69d9b3d to
ac3f585
Compare
There was a problem hiding this comment.
Thanks @gaoyikeshuer! I added a new commit in my test branch for this PR https://github.com/rmartinc/keycloak/tree/refs/heads/pr-49296. The main idea is adding the theme and provider to run the disabled test in another class. I have added some other minor changes to not do manual modifications in the realm and always use the updateWithCleanup. If you find something more on those lines, you can follow the same idea (although I think that with those changes the PR is OK to me).
Please include the changes in the test commit from my branch in this PR. You can just squash it or amend or do whatever you like with it.
I think that with that commit, this is OK to me.
vaceksimon
left a comment
There was a problem hiding this comment.
Keep up the good work @gaoyikeshuer!
| UserBuilder.create().username("test-user@localhost") | ||
| .email("test-user@localhost") | ||
| .name("Tom", "Brady") | ||
| .attribute("attr_required", "value") | ||
| .attribute("attr_required_by_role", "value") | ||
| .attribute("attr_required_by_scope", "value") | ||
| .realmRoles("user", "offline_access") | ||
| .clientRoles("account", "view-profile", "manage-account") | ||
| .password("password"), |
There was a problem hiding this comment.
This user is referenced a lot in the tests. In this case, we can turn it into a managed user with this config:
@InjectUser(config = TestUserConfig.class)
ManagedUser testUser;With that, you can replace registerUserCleanup(...) with a call to testUser.dirty().
Also using "test-user@localhost" and "password" directly can turn into testUser.getUsername() and testUser.getPassword()
There was a problem hiding this comment.
@gaoyikeshuer @vaceksimon I think this is the only point that still stands. I leave it to you both, if you prefer to change to use the ManagedUser, OK, but it's also OK to me as it's now. 😄
There was a problem hiding this comment.
Hi @vaceksimon , thanks for this suggestion! I tried to use the @InjectUser before but it fails at UserSupplier:42 with "Creating user with roles or client roles is not supported!". this user needs the account/view-profile + account/manage-account client roles plus user + offline_access realm roles to function. so i've reverted that change. I think we will need to modify framework if we want @injectUser here. which is better to be in a separate PR
There was a problem hiding this comment.
Right. The role creation is unfortunately a limitation of the current admin API, which should be fixed with admin API v2. In this case, I'm ok with this
| events.poll(); | ||
| events.poll(); | ||
| events.poll(); |
There was a problem hiding this comment.
This is a nitpick, and I only mention it so you know it exists; the same thing can be done with events.skip(3);
| final OAuth2ErrorRepresentation error = response.asJson(OAuth2ErrorRepresentation.class); | ||
| assertThat(error.getError(), containsString("Invalid json representation for UserRepresentation. Unrecognized field \"invalid\" at line")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testEmailWhenUpdateEmailEnabled() throws Exception { | ||
| reconnectAdminClient(); | ||
| managedRealm.cleanup().add(r -> setRequiredActionEnabled(r, RequiredAction.UPDATE_EMAIL, false)); | ||
| managedRealm.updateWithCleanup(r -> r); |
There was a problem hiding this comment.
This is a preferable way to achieve the same thing
| managedRealm.updateWithCleanup(r -> r); | |
| managedRealm.dirty(); |
| String accessToken = tokenUtil.getToken(); | ||
| org.keycloak.representations.idm.ClientRepresentation originalClientRep = AdminApiUtil.findClientByClientId(managedRealm.admin(), "direct-grant").toRepresentation(); | ||
| managedRealm.cleanup().add(r -> AdminApiUtil.findClientByClientId(r, "direct-grant").update(originalClientRep)); | ||
| managedRealm.updateWithCleanup(r -> r); |
There was a problem hiding this comment.
This is a preferable way to achieve the same thing.
| managedRealm.updateWithCleanup(r -> r); | |
| managedRealm.dirty(); |
| @Test | ||
| public void testAccountAccessWithRealmNotBeforeAndClientNotBefore() throws IOException { | ||
| String accessToken = tokenUtil.getToken(); | ||
| org.keycloak.representations.idm.ClientRepresentation originalClientRep = AdminApiUtil.findClientByClientId(managedRealm.admin(), "direct-grant").toRepresentation(); |
There was a problem hiding this comment.
Since the realm will be recreated with everything in it, the cleanup for the "direct-grant" client can be removed.
547db7b to
5e42776
Compare
rmartinc
left a comment
There was a problem hiding this comment.
Thanks @gaoyikeshuer! For me it's OK. Please @vaceksimon take a look when you have time to see if it's also OK for you.
vaceksimon
left a comment
There was a problem hiding this comment.
@gaoyikeshuer took a quick look. I will check the rest tomorrow once back in the office
…loak#48148 Signed-off-by: Yike Gao <yikegao8@gmail.com>
5e42776 to
26e0b7e
Compare
rmartinc
left a comment
There was a problem hiding this comment.
Thanks @gaoyikeshuer! LGTM!
vaceksimon
left a comment
There was a problem hiding this comment.
Well done @gaoyikeshuer, thank you!
|
Thanks @gaoyikeshuer and @vaceksimon! |
…loak#48148 (keycloak#49296) Signed-off-by: Yike Gao <yikegao8@gmail.com>
This PR is aim to migrate AccountRestServiceTest. the two extending classes (Lightweight, withUserProfile) are technically not required by this issue, but I migrate them because they share AccountRestServiceTest as their parent, and moving the parent without them will create a half migrated state where they break.
Tests missing for full migration of the account package are:
AccountRestServiceCorsTest
AccountRestServiceReadOnlyAttributesTest
LinkedAccountsRestServiceTest
ResourcesRestServiceTest
SessionRestServiceTest
custom/* tests
Delete legacy AbstractRestServiceTest (only possible once all the above are migrated)
Closes #48148