[KEYCLOAK-5660] - Rest API User count returns wrong value

This commit is contained in:
pedroigor 2017-11-29 11:18:01 -02:00 committed by Stian Thorgersen
parent c5d9301951
commit 674fb31a2c
2 changed files with 23 additions and 1 deletions

View file

@ -48,7 +48,7 @@ import java.util.Collection;
@NamedQuery(name="getRealmUserByLastName", query="select u from UserEntity u where u.lastName = :lastName and u.realmId = :realmId"),
@NamedQuery(name="getRealmUserByFirstLastName", query="select u from UserEntity u where u.firstName = :first and u.lastName = :last and u.realmId = :realmId"),
@NamedQuery(name="getRealmUserByServiceAccount", query="select u from UserEntity u where u.serviceAccountClientLink = :clientInternalId and u.realmId = :realmId"),
@NamedQuery(name="getRealmUserCount", query="select count(u) from UserEntity u where u.realmId = :realmId"),
@NamedQuery(name="getRealmUserCount", query="select count(u) from UserEntity u where u.realmId = :realmId and (u.serviceAccountClientLink is null)"),
@NamedQuery(name="getRealmUsersByAttributeNameAndValue", query="select u from UserEntity u join u.attributes attr " +
"where u.realmId = :realmId and attr.name = :name and attr.value = :value"),
@NamedQuery(name="deleteUsersByRealm", query="delete from UserEntity u where u.realmId = :realmId"),

View file

@ -405,6 +405,28 @@ public class UserTest extends AbstractAdminTest {
assertEquals(9, count.intValue());
}
@Test
public void countUsersNotServiceAccount() {
createUsers();
Integer count = realm.users().count();
assertEquals(9, count.intValue());
ClientRepresentation client = new ClientRepresentation();
client.setClientId("test-client");
client.setPublicClient(false);
client.setSecret("secret");
client.setServiceAccountsEnabled(true);
client.setEnabled(true);
client.setRedirectUris(Arrays.asList("http://url"));
getAdminClient().realm(REALM_NAME).clients().create(client);
// KEYCLOAK-5660, should not consider service accounts
assertEquals(9, realm.users().count().intValue());
}
@Test
public void delete() {
String userId = createUser();