From fff27f8bd6b8e3102f7d31e8a0676313e46d5082 Mon Sep 17 00:00:00 2001 From: Vlastimil Elias Date: Thu, 22 Jul 2021 14:55:15 +0200 Subject: [PATCH] KEYCLOAK-18812 fixing Account REST API tests under User Profile enabled --- .../account/AccountRestServiceTest.java | 11 ++++++- ...AccountRestServiceWithUserProfileTest.java | 30 +++++++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceTest.java index 0bef0baf01..138852d0fc 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceTest.java @@ -285,7 +285,12 @@ public class AccountRestServiceTest extends AbstractRestServiceTest { user = updateAndGet(user); - assertEquals(1, user.getAttributes().size()); + if (isDeclarativeUserProfile()) { + assertEquals(2, user.getAttributes().size()); + assertTrue(user.getAttributes().get("attr1").isEmpty()); + } else { + assertEquals(1, user.getAttributes().size()); + } assertEquals(2, user.getAttributes().get("attr2").size()); assertThat(user.getAttributes().get("attr2"), containsInAnyOrder("val2", "val3")); @@ -1368,4 +1373,8 @@ public class AccountRestServiceTest extends AbstractRestServiceTest { // custom-audience client is used only in this test so no need to revert the changes } + + protected boolean isDeclarativeUserProfile() { + return false; + } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceWithUserProfileTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceWithUserProfileTest.java index b6b0fa49be..17ee068f70 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceWithUserProfileTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountRestServiceWithUserProfileTest.java @@ -17,7 +17,6 @@ package org.keycloak.testsuite.account; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -49,7 +48,12 @@ public class AccountRestServiceWithUserProfileTest extends AccountRestServiceTes enableDynamicUserProfile(); setUserProfileConfiguration(null); } - + + @Override + protected boolean isDeclarativeUserProfile() { + return true; + } + private static String UP_CONFIG_FOR_METADATA = "{\"attributes\": [" + "{\"name\": \"firstName\"," + PERMISSIONS_ALL + ", \"required\": {\"scopes\":[\"profile\"]}, \"displayName\": \"${profile.firstName}\", \"validations\": {\"length\": { \"max\": 255 }}}," + "{\"name\": \"lastName\"," + PERMISSIONS_ALL + ", \"required\": {}, \"displayName\": \"Last name\", \"annotations\": {\"formHintKey\" : \"userEmailFormFieldHint\", \"anotherKey\" : 10, \"yetAnotherKey\" : \"some value\"}}," @@ -158,21 +162,23 @@ public class AccountRestServiceWithUserProfileTest extends AccountRestServiceTes @Test @Override public void testUpdateProfile() throws IOException { - // TODO uncomment next lines once KEYCLOAK-18839 is patched -// setUserProfileConfiguration("{\"attributes\": [" -// + "{\"name\": \"firstName\"," + PERMISSIONS_ALL + ", \"required\": {}}," -// + "{\"name\": \"lastName\"," + PERMISSIONS_ALL + ", \"required\": {}}," -// + "{\"name\": \"attr1\"," + PERMISSIONS_ALL + "}," -// + "{\"name\": \"attr2\"," + PERMISSIONS_ALL + "}" -// + "]}"); -// super.testUpdateProfile(); + setUserProfileConfiguration("{\"attributes\": [" + + "{\"name\": \"firstName\"," + PERMISSIONS_ALL + ", \"required\": {}}," + + "{\"name\": \"lastName\"," + PERMISSIONS_ALL + ", \"required\": {}}," + + "{\"name\": \"attr1\"," + PERMISSIONS_ALL + "}," + + "{\"name\": \"attr2\"," + PERMISSIONS_ALL + "}" + + "]}"); + super.testUpdateProfile(); } @Test @Override public void testUpdateSingleField() throws IOException { - // TODO uncomment next lines once KEYCLOAK-18839 is patched - // super.testUpdateSingleField(); + setUserProfileConfiguration("{\"attributes\": [" + + "{\"name\": \"firstName\"," + PERMISSIONS_ALL + "}," + + "{\"name\": \"lastName\"," + PERMISSIONS_ALL + ", \"required\": {}}" + + "]}"); + super.testUpdateSingleField(); } protected void setUserProfileConfiguration(String configuration) {