8000 Fix SSSD tests by stianst · Pull Request #48360 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/conditional/conditions
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ model/ ci-store
testsuite/model/ ci-store
operator/ operator

testsuite/integration-arquillian/tests/other/sssd/ ci-sssd

docs/guides/ guides
docs/documentation/ documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.common.util.MultivaluedHashMap;
Expand All @@ -43,10 +39,16 @@
import org.keycloak.storage.UserStorageProvider;
import org.keycloak.testsuite.admin.AdminApiUtil;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.util.oauth.AccessTokenResponse;
import org.keycloak.testsuite.util.WaitUtils;
import org.keycloak.testsuite.util.oauth.AccessTokenResponse;
import org.keycloak.userprofile.config.UPConfigUtils;

import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

/**
* <p>Test for the User profile integration in the SSSD provider.</p>
*
Expand Down Expand Up @@ -86,7 +88,7 @@ public void test02DefaultSSSDUserProfile() throws Exception {
// default configuration adds all sssd attributes
// check they are read-only in both admin and user for a SSSD user
String username = getUsername();
UserResource userResource = AdminApiUtil.findUserByUsernameId(testRealm(), username);
UserResource userResource = AdminApiUtil.findUserByUsernameId(managedRealm.admin(), username);
UserRepresentation user = userResource.toRepresentation(true);

// for admin the four should be read-only
Expand Down Expand Up @@ -130,7 +132,7 @@ public void test02DefaultSSSDUserProfile() throws Exception {
@Test
public void test03DefaultInternalDBUserProfile() throws Exception {
// check non sssd user has normal atttributes enabled
UserResource testResource = AdminApiUtil.findUserByUsernameId(testRealm(), "test-user@localhost");
UserResource testResource = AdminApiUtil.findUserByUsernameId(managedRealm.admin(), "test-user@localhost");
UserRepresentation test = testResource.toRepresentation(true);

// for admin the four should be editable
Expand Down Expand Up @@ -172,15 +174,15 @@ public void test03DefaultInternalDBUserProfile() throws Exception {

@Test
public void test04MixedSSSDUserProfile() throws Exception {
RealmResource realm = testRealm();
RealmResource realm = managedRealm.admin();
UPConfig origConfig = realm.users().userProfile().getConfiguration();
try {
createMixedUPConfiguration();

// for admin all attributes are added as read-only and postal_code remains editable
String username = getUsername();
String sssdId = getSssdProviderId();
UserResource userResource = AdminApiUtil.findUserByUsernameId(testRealm(), username);
UserResource userResource = AdminApiUtil.findUserByUsernameId(managedRealm.admin(), username);
UserRepresentation user = userResource.toRepresentation(true);
// first and last names are removed from the UP config (unmanaged) and are not available from the representation
assertUser(user, username, getEmail(username), null, null, sssdId);
Expand Down Expand Up @@ -225,13 +227,13 @@ public void test04MixedSSSDUserProfile() throws Exception {

@Test
public void test05MixedInternalDBUserProfile() throws Exception {
RealmResource realm = testRealm();
RealmResource realm = managedRealm.admin();
UPConfig origConfig = realm.users().userProfile().getConfiguration();
try {
createMixedUPConfiguration();

// for admin firstName and lastName remains removed, the rest editable
UserResource testResource = AdminApiUtil.findUserByUsernameId(testRealm(), "test-user@localhost");
UserResource testResource = AdminApiUtil.findUserByUsernameId(managedRealm.admin(), "test-user@localhost");
UserRepresentation test = testResource.toRepresentation(true);
assertUser(test, "test-user@localhost", "test-user@localhost", null, null, null);
assertProfileAttributes(test, null, false, "username", "email", "postal_code");
Expand Down Expand Up @@ -294,15 +296,15 @@ private void assertProfileAttributes(UserRepresentation user, String expectedGro
}

private String getSssdProviderId() {
List<ComponentRepresentation> comps = testRealm().components()
List<ComponentRepresentation> comps = managedRealm.admin().components()
.query(TEST_REALM_NAME, UserStorageProvider.class.getName(), PROVIDER_NAME);
Assert.assertEquals(1, comps.size());
return comps.iterator().next().getId();
}

private void createMixedUPConfiguration() {
// removes firstName and lastName, adds a custom postal_code
RealmResource realm = testRealm();
RealmResource realm = managedRealm.admin();
UPConfig config = realm.users().userProfile().getConfiguration();
config.getAttributes().remove(config.getAttribute(UserModel.FIRST_NAME));
config.getAttributes().remove(config.getAttribute(UserModel.LAST_NAME));
Expand Down
Loading
0