Skip to content

Ignore empty attribute values when retriveing boolean/int/long (#26729) - #26737

Merged
stianst merged 1 commit into
keycloak:mainfrom
stianst:backport-main
Feb 6, 2024
Merged

stianst merged 1 commit into
keycloak:mainfrom
stianst:backport-main

Conversation

@stianst

@stianst stianst commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

Resolves #26597, resolves #26665

Signed-off-by: stianst stianst@gmail.com

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

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();
}
}

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.

@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));
});
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd rather just merge it as is, and if you want to polish the test afterwards feel free ;)

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost

ghost commented Feb 2, 2024

Copy link
Copy Markdown

Unreported flaky test detected

If 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#updateEmailLinkNotVisibleWithoutUpdateEmailActionEnabled

Keycloak CI - Account Console IT (chrome)

org.openqa.selenium.NoSuchElementException: 
no such element: Unable to locate element: {"method":"css selector","selector":"#username"}
  (Session info: chrome-headless-shell=121.0.6167.85)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
...

Report flaky test

@stianst
stianst merged commit 3e08a17 into keycloak:main Feb 6, 2024
@stianst
stianst deleted the backport-main branch February 6, 2024 14:29
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants