Repository navigation
Ignore empty attribute values when retriveing boolean/int/long (#26729) - #26737
Merged
Merged
Conversation
…oak#26729) Resolves keycloak#26597, resolves keycloak#26665 Signed-off-by: stianst <stianst@gmail.com>
mhajas
approved these changes
Feb 2, 2024
mhajas
left a comment
Contributor
There was a problem hiding this comment.
Sorry I didn't bring it up with PR to 23 but I added another nitpick to the test. Feel free to ignore if you don't like it.
Comment on lines
+1006
to
+1042
| public void testSetEmptyAttributeValues() { | ||
| String realmName = "testSetEmptyAttributeValues"; | ||
| RealmRepresentation rep = new RealmRepresentation(); | ||
| rep.setRealm(realmName); | ||
| rep.setAttributes(new HashMap<>()); | ||
| rep.getAttributes().put("myboolean", ""); | ||
| rep.getAttributes().put("mylong", ""); | ||
| rep.getAttributes().put("myint", ""); | ||
| rep.getAttributes().put(RealmAttributes.ACTION_TOKEN_GENERATED_BY_USER_LIFESPAN + ".something", ""); | ||
|
|
||
| adminClient.realms().create(rep); | ||
|
|
||
| try { | ||
| adminClient.realm(realmName); | ||
|
|
||
| testingClient.server().run(session -> { | ||
| RealmModel realm = session.realms().getRealmByName(realmName); | ||
| Assert.assertTrue(realm instanceof org.keycloak.models.cache.infinispan.RealmAdapter); | ||
|
|
||
| Assert.assertNull(realm.getUserActionTokenLifespans().get("something")); | ||
| Assert.assertEquals(true, realm.getAttribute("myboolean", true)); | ||
| Assert.assertEquals(Long.valueOf(123), realm.getAttribute("mylong", (long) 123)); | ||
| Assert.assertEquals(Integer.valueOf(1234), realm.getAttribute("myint", 1234)); | ||
|
|
||
| RealmProvider delegate = session.getProvider(CacheRealmProvider.class).getRealmDelegate(); | ||
| RealmModel realm2 = delegate.getRealm(realm.getId()); | ||
| Assert.assertTrue(realm2 instanceof org.keycloak.models.jpa.RealmAdapter); | ||
|
|
||
| Assert.assertNull(realm2.getUserActionTokenLifespans().get("something")); | ||
| Assert.assertEquals(true, realm2.getAttribute("myboolean", true)); | ||
| Assert.assertEquals(Long.valueOf(123), realm2.getAttribute("mylong", (long) 123)); | ||
| Assert.assertEquals(Integer.valueOf(1234), realm2.getAttribute("myint", 1234)); | ||
| }); | ||
| } finally { | ||
| adminClient.realm(realmName).remove(); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
@stianst Should we use something more fancy for main?
Suggested change
| public void testSetEmptyAttributeValues() { | |
| String realmName = "testSetEmptyAttributeValues"; | |
| RealmRepresentation rep = new RealmRepresentation(); | |
| rep.setRealm(realmName); | |
| rep.setAttributes(new HashMap<>()); | |
| rep.getAttributes().put("myboolean", ""); | |
| rep.getAttributes().put("mylong", ""); | |
| rep.getAttributes().put("myint", ""); | |
| rep.getAttributes().put(RealmAttributes.ACTION_TOKEN_GENERATED_BY_USER_LIFESPAN + ".something", ""); | |
| adminClient.realms().create(rep); | |
| try { | |
| adminClient.realm(realmName); | |
| testingClient.server().run(session -> { | |
| RealmModel realm = session.realms().getRealmByName(realmName); | |
| Assert.assertTrue(realm instanceof org.keycloak.models.cache.infinispan.RealmAdapter); | |
| Assert.assertNull(realm.getUserActionTokenLifespans().get("something")); | |
| Assert.assertEquals(true, realm.getAttribute("myboolean", true)); | |
| Assert.assertEquals(Long.valueOf(123), realm.getAttribute("mylong", (long) 123)); | |
| Assert.assertEquals(Integer.valueOf(1234), realm.getAttribute("myint", 1234)); | |
| RealmProvider delegate = session.getProvider(CacheRealmProvider.class).getRealmDelegate(); | |
| RealmModel realm2 = delegate.getRealm(realm.getId()); | |
| Assert.assertTrue(realm2 instanceof org.keycloak.models.jpa.RealmAdapter); | |
| Assert.assertNull(realm2.getUserActionTokenLifespans().get("something")); | |
| Assert.assertEquals(true, realm2.getAttribute("myboolean", true)); | |
| Assert.assertEquals(Long.valueOf(123), realm2.getAttribute("mylong", (long) 123)); | |
| Assert.assertEquals(Integer.valueOf(1234), realm2.getAttribute("myint", 1234)); | |
| }); | |
| } finally { | |
| adminClient.realm(realmName).remove(); | |
| } | |
| } | |
| public void testSetEmptyAttributeValues() { | |
| final String realmName = "testSetEmptyAttributeValues"; | |
| try (Creator<RealmResource> c = Creator.create(adminClient, RealmBuilder.create() | |
| .name(realmName) | |
| .attribute("myboolean", "") | |
| .attribute("mylong", "") | |
| .attribute("myint", "") | |
| .attribute(RealmAttributes.ACTION_TOKEN_GENERATED_BY_USER_LIFESPAN + ".something", "") | |
| .build() | |
| )) { | |
| testingClient.server().run(session -> { | |
| RealmModel realm = session.realms().getRealmByName(realmName); | |
| Assert.assertTrue(realm instanceof org.keycloak.models.cache.infinispan.RealmAdapter); | |
| Assert.assertNull(realm.getUserActionTokenLifespans().get("something")); | |
| Assert.assertEquals(true, realm.getAttribute("myboolean", true)); | |
| Assert.assertEquals(Long.valueOf(123), realm.getAttribute("mylong", (long) 123)); | |
| Assert.assertEquals(Integer.valueOf(1234), realm.getAttribute("myint", 1234)); | |
| RealmProvider delegate = session.getProvider(CacheRealmProvider.class).getRealmDelegate(); | |
| RealmModel realm2 = delegate.getRealm(realm.getId()); | |
| Assert.assertTrue(realm2 instanceof org.keycloak.models.jpa.RealmAdapter); | |
| Assert.assertNull(realm2.getUserActionTokenLifespans().get("something")); | |
| Assert.assertEquals(true, realm2.getAttribute("myboolean", true)); | |
| Assert.assertEquals(Long.valueOf(123), realm2.getAttribute("mylong", (long) 123)); | |
| Assert.assertEquals(Integer.valueOf(1234), realm2.getAttribute("myint", 1234)); | |
| }); | |
| } | |
| } |
Contributor
Author
There was a problem hiding this comment.
I'd rather just merge it as is, and if you want to polish the test afterwards feel free ;)
ghost
reviewed
Feb 2, 2024
ghost
left a comment
There was a problem hiding this comment.
Unreported flaky test detected, please review
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.ui.account2.UpdateEmailTest#updateEmailLinkNotVisibleWithoutUpdateEmailActionEnabledKeycloak CI - Account Console IT (chrome) |
cavuugroup
pushed a commit
to cavuugroup/keycloak
that referenced
this pull request
Feb 8, 2024
…oak#26729) (keycloak#26737) Resolves keycloak#26597, resolves keycloak#26665 Signed-off-by: stianst <stianst@gmail.com> Signed-off-by: Krzysztof Walczewski <kwalczewski@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #26597, resolves #26665
Signed-off-by: stianst stianst@gmail.com