From 563ae104fd1671b8dd8d4b912ff16835fc169e9d Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 21 Aug 2023 10:26:14 +0200 Subject: [PATCH] [issue-14134] test partial import user with id Fix #14134 --- .../partialimport/UsersPartialImport.java | 4 +- .../testsuite/AbstractKeycloakTest.java | 7 ++- .../partialimport/PartialImportTest.java | 52 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java b/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java index 7820462cd1..d7d3eb1abf 100755 --- a/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/UsersPartialImport.java @@ -110,7 +110,9 @@ public class UsersPartialImport extends AbstractPartialImport groups, boolean enabled) { + public static UserRepresentation createUserRepresentation(String id, String username, String email, String firstName, String lastName, List groups, boolean enabled) { UserRepresentation user = new UserRepresentation(); + user.setId(id); user.setUsername(username); user.setEmail(email); user.setFirstName(firstName); @@ -567,6 +568,10 @@ public abstract class AbstractKeycloakTest { return user; } + public static UserRepresentation createUserRepresentation(String username, String email, String firstName, String lastName, List groups, boolean enabled) { + return createUserRepresentation(null, username, email, firstName, lastName, groups, enabled); + } + public static UserRepresentation createUserRepresentation(String username, String email, String firstName, String lastName, boolean enabled) { return createUserRepresentation(username, email, firstName, lastName, null, enabled); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java index e5cd2344ea..b1c6503d25 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/partialimport/PartialImportTest.java @@ -57,6 +57,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.startsWith; @@ -247,6 +248,17 @@ public class PartialImportTest extends AbstractAuthTest { piRep.setUsers(users); } + private void addUsersWithIds() { + List users = new ArrayList<>(); + + for (int i = 0; i < NUM_ENTITIES; i++) { + UserRepresentation user = createUserRepresentation(UUID.randomUUID().toString(), USER_PREFIX + i, USER_PREFIX + i + "@foo.com", "foo", "bar", null, true); + users.add(user); + } + + piRep.setUsers(users); + } + private void addUsersWithTermsAndConditions() { List users = new ArrayList<>(); List requiredActions = new ArrayList<>(); @@ -418,6 +430,46 @@ public class PartialImportTest extends AbstractAuthTest { } } + @Test + public void testAddUsersWithIds() { + assertAdminEvents.clear(); + + setFail(); + addUsersWithIds(); + + Set userRepIds = new HashSet<>(); + for (UserRepresentation userRep : piRep.getUsers()) { + userRepIds.add(userRep.getId()); + } + + PartialImportResults results = doImport(); + assertEquals(NUM_ENTITIES, results.getAdded()); + + // Need to do this way as admin events from partial import are unsorted + Set userIds = new HashSet<>(); + for (int i=0 ; i