KEYCLOAK-2850 migrate RealmTest from old testsuite to new
This commit is contained in:
parent
656161ff61
commit
060527ac67
11 changed files with 111 additions and 128 deletions
|
@ -31,7 +31,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class Assert {
|
||||
public class Assert extends org.junit.Assert {
|
||||
|
||||
public static <T> void assertNames(List<T> actual, String... expected) {
|
||||
Arrays.sort(expected);
|
||||
|
|
|
@ -18,25 +18,21 @@
|
|||
package org.keycloak.testsuite.admin;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.Keycloak;
|
||||
import org.keycloak.admin.client.resource.ServerInfoResource;
|
||||
import org.keycloak.common.util.StreamUtil;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.GroupRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.testsuite.KeycloakServer;
|
||||
import org.keycloak.testsuite.Assert;
|
||||
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
||||
import org.keycloak.testsuite.auth.page.AuthRealm;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
@ -53,7 +49,7 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class RealmTest extends AbstractClientTest {
|
||||
public class RealmTest extends AbstractAdminTest {
|
||||
|
||||
public static final String PRIVATE_KEY = "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=";
|
||||
public static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB";
|
||||
|
@ -61,8 +57,8 @@ public class RealmTest extends AbstractClientTest {
|
|||
|
||||
@Test
|
||||
public void getRealms() {
|
||||
List<RealmRepresentation> realms = keycloak.realms().findAll();
|
||||
assertNames(realms, "master", "test", REALM_NAME);
|
||||
List<RealmRepresentation> realms = adminClient.realms().findAll();
|
||||
Assert.assertNames(realms, "master", AuthRealm.TEST, REALM_NAME);
|
||||
|
||||
for (RealmRepresentation rep : realms) {
|
||||
assertNull(rep.getPrivateKey());
|
||||
|
@ -79,78 +75,64 @@ public class RealmTest extends AbstractClientTest {
|
|||
rep.setRealm("old");
|
||||
|
||||
try {
|
||||
keycloak.realms().create(rep);
|
||||
adminClient.realms().create(rep);
|
||||
|
||||
rep.setRealm("new");
|
||||
keycloak.realm("old").update(rep);
|
||||
adminClient.realm("old").update(rep);
|
||||
|
||||
// Check client in master realm renamed
|
||||
assertEquals(0, keycloak.realm("master").clients().findByClientId("old-realm").size());
|
||||
assertEquals(1, keycloak.realm("master").clients().findByClientId("new-realm").size());
|
||||
Assert.assertEquals(0, adminClient.realm("master").clients().findByClientId("old-realm").size());
|
||||
Assert.assertEquals(1, adminClient.realm("master").clients().findByClientId("new-realm").size());
|
||||
|
||||
ClientRepresentation adminClient = keycloak.realm("new").clients().findByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID).get(0);
|
||||
assertEquals("/auth/admin/new/console/index.html", adminClient.getBaseUrl());
|
||||
assertEquals("/auth/admin/new/console/*", adminClient.getRedirectUris().get(0));
|
||||
ClientRepresentation adminConsoleClient = adminClient.realm("new").clients().findByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID).get(0);
|
||||
assertEquals("/auth/admin/new/console/index.html", adminConsoleClient.getBaseUrl());
|
||||
assertEquals("/auth/admin/new/console/*", adminConsoleClient.getRedirectUris().get(0));
|
||||
|
||||
ClientRepresentation accountClient = keycloak.realm("new").clients().findByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).get(0);
|
||||
ClientRepresentation accountClient = adminClient.realm("new").clients().findByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).get(0);
|
||||
assertEquals("/auth/realms/new/account", accountClient.getBaseUrl());
|
||||
assertEquals("/auth/realms/new/account/*", accountClient.getRedirectUris().get(0));
|
||||
} finally {
|
||||
keycloak.realms().realm(rep.getRealm()).remove();
|
||||
adminClient.realms().realm(rep.getRealm()).remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRealmEmpty() {
|
||||
try {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setRealm("new-realm");
|
||||
|
||||
keycloak.realms().create(rep);
|
||||
adminClient.realms().create(rep);
|
||||
|
||||
assertNames(keycloak.realms().findAll(), "master", "test", REALM_NAME, "new-realm");
|
||||
} finally {
|
||||
KeycloakSession session = keycloakRule.startSession();
|
||||
RealmManager manager = new RealmManager(session);
|
||||
RealmModel newRealm = manager.getRealmByName("new-realm");
|
||||
if (newRealm != null) {
|
||||
manager.removeRealm(newRealm);
|
||||
}
|
||||
keycloakRule.stopSession(session, true);
|
||||
}
|
||||
Assert.assertNames(adminClient.realms().findAll(), "master", AuthRealm.TEST, REALM_NAME, "new-realm");
|
||||
|
||||
adminClient.realms().realm("new-realm").remove();
|
||||
|
||||
Assert.assertNames(adminClient.realms().findAll(), "master", AuthRealm.TEST, REALM_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRealm() {
|
||||
try {
|
||||
RealmRepresentation rep = KeycloakServer.loadJson(getClass().getResourceAsStream("/admin-test/testrealm.json"), RealmRepresentation.class);
|
||||
keycloak.realms().create(rep);
|
||||
public void createRealmFromJson() {
|
||||
RealmRepresentation rep = loadJson(getClass().getResourceAsStream("/admin-test/testrealm.json"), RealmRepresentation.class);
|
||||
adminClient.realms().create(rep);
|
||||
|
||||
RealmRepresentation created = keycloak.realms().realm("admin-test-1").toRepresentation();
|
||||
RealmRepresentation created = adminClient.realms().realm("admin-test-1").toRepresentation();
|
||||
assertRealm(rep, created);
|
||||
} finally {
|
||||
KeycloakSession session = keycloakRule.startSession();
|
||||
RealmManager manager = new RealmManager(session);
|
||||
RealmModel newRealm = manager.getRealmByName("admin-test-1");
|
||||
if (newRealm != null) {
|
||||
manager.removeRealm(newRealm);
|
||||
}
|
||||
keycloakRule.stopSession(session, true);
|
||||
}
|
||||
|
||||
adminClient.realms().realm("admin-test-1").remove();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeRealm() {
|
||||
realm.remove();
|
||||
|
||||
assertNames(keycloak.realms().findAll(), "master", "test");
|
||||
Assert.assertNames(adminClient.realms().findAll(), "master", AuthRealm.TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginAfterRemoveRealm() {
|
||||
realm.remove();
|
||||
|
||||
ServerInfoResource serverInfoResource = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID).serverInfo();
|
||||
ServerInfoResource serverInfoResource = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID).serverInfo();
|
||||
serverInfoResource.getInfo();
|
||||
}
|
||||
|
||||
|
@ -160,26 +142,21 @@ public class RealmTest extends AbstractClientTest {
|
|||
*/
|
||||
@Test
|
||||
public void renameRealmTest() throws Exception {
|
||||
Keycloak keycloak = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID);
|
||||
RealmRepresentation realm1 = new RealmRepresentation();
|
||||
realm1.setRealm("test-immutable");
|
||||
keycloak.realms().create(realm1);
|
||||
realm1 = keycloak.realms().realm("test-immutable").toRepresentation();
|
||||
adminClient.realms().create(realm1);
|
||||
realm1 = adminClient.realms().realm("test-immutable").toRepresentation();
|
||||
realm1.setRealm("test-immutable-old");
|
||||
keycloak.realms().realm("test-immutable").update(realm1);
|
||||
realm1 = keycloak.realms().realm("test-immutable-old").toRepresentation();
|
||||
adminClient.realms().realm("test-immutable").update(realm1);
|
||||
realm1 = adminClient.realms().realm("test-immutable-old").toRepresentation();
|
||||
|
||||
RealmRepresentation realm2 = new RealmRepresentation();
|
||||
realm2.setRealm("test-immutable");
|
||||
keycloak.realms().create(realm2);
|
||||
realm2 = keycloak.realms().realm("test-immutable").toRepresentation();
|
||||
|
||||
keycloak.realms().realm("test-immutable-old").remove();
|
||||
keycloak.realms().realm("test-immutable").remove();
|
||||
|
||||
|
||||
|
||||
adminClient.realms().create(realm2);
|
||||
realm2 = adminClient.realms().realm("test-immutable").toRepresentation();
|
||||
|
||||
adminClient.realms().realm("test-immutable-old").remove();
|
||||
adminClient.realms().realm("test-immutable").remove();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -245,7 +222,7 @@ public class RealmTest extends AbstractClientTest {
|
|||
@Test
|
||||
public void getRealmRepresentation() {
|
||||
RealmRepresentation rep = realm.toRepresentation();
|
||||
assertEquals(REALM_NAME, rep.getRealm());
|
||||
Assert.assertEquals(REALM_NAME, rep.getRealm());
|
||||
assertTrue(rep.isEnabled());
|
||||
|
||||
assertNull(rep.getPrivateKey());
|
||||
|
@ -255,7 +232,7 @@ public class RealmTest extends AbstractClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
// KEYCLOAK-1110
|
||||
// KEYCLOAK-1110 TODO: Functionality more related to roles. So maybe rather move to RolesTest once we have it
|
||||
public void deleteDefaultRole() {
|
||||
RoleRepresentation role = new RoleRepresentation("test", "test", false);
|
||||
realm.roles().create(role);
|
||||
|
@ -274,6 +251,7 @@ public class RealmTest extends AbstractClientTest {
|
|||
realm.roles().get("testsadfsadf").toRepresentation();
|
||||
fail("Expected NotFoundException");
|
||||
} catch (NotFoundException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,60 +287,60 @@ public class RealmTest extends AbstractClientTest {
|
|||
|
||||
public static void assertRealm(RealmRepresentation realm, RealmRepresentation storedRealm) {
|
||||
if (realm.getId() != null) {
|
||||
Assert.assertEquals(realm.getId(), storedRealm.getId());
|
||||
assertEquals(realm.getId(), storedRealm.getId());
|
||||
}
|
||||
if (realm.getRealm() != null) {
|
||||
Assert.assertEquals(realm.getRealm(), storedRealm.getRealm());
|
||||
assertEquals(realm.getRealm(), storedRealm.getRealm());
|
||||
}
|
||||
if (realm.isEnabled() != null) Assert.assertEquals(realm.isEnabled(), storedRealm.isEnabled());
|
||||
if (realm.isBruteForceProtected() != null) Assert.assertEquals(realm.isBruteForceProtected(), storedRealm.isBruteForceProtected());
|
||||
if (realm.getMaxFailureWaitSeconds() != null) Assert.assertEquals(realm.getMaxFailureWaitSeconds(), storedRealm.getMaxFailureWaitSeconds());
|
||||
if (realm.getMinimumQuickLoginWaitSeconds() != null) Assert.assertEquals(realm.getMinimumQuickLoginWaitSeconds(), storedRealm.getMinimumQuickLoginWaitSeconds());
|
||||
if (realm.getWaitIncrementSeconds() != null) Assert.assertEquals(realm.getWaitIncrementSeconds(), storedRealm.getWaitIncrementSeconds());
|
||||
if (realm.getQuickLoginCheckMilliSeconds() != null) Assert.assertEquals(realm.getQuickLoginCheckMilliSeconds(), storedRealm.getQuickLoginCheckMilliSeconds());
|
||||
if (realm.getMaxDeltaTimeSeconds() != null) Assert.assertEquals(realm.getMaxDeltaTimeSeconds(), storedRealm.getMaxDeltaTimeSeconds());
|
||||
if (realm.getFailureFactor() != null) Assert.assertEquals(realm.getFailureFactor(), storedRealm.getFailureFactor());
|
||||
if (realm.isRegistrationAllowed() != null) Assert.assertEquals(realm.isRegistrationAllowed(), storedRealm.isRegistrationAllowed());
|
||||
if (realm.isRegistrationEmailAsUsername() != null) Assert.assertEquals(realm.isRegistrationEmailAsUsername(), storedRealm.isRegistrationEmailAsUsername());
|
||||
if (realm.isRememberMe() != null) Assert.assertEquals(realm.isRememberMe(), storedRealm.isRememberMe());
|
||||
if (realm.isVerifyEmail() != null) Assert.assertEquals(realm.isVerifyEmail(), storedRealm.isVerifyEmail());
|
||||
if (realm.isResetPasswordAllowed() != null) Assert.assertEquals(realm.isResetPasswordAllowed(), storedRealm.isResetPasswordAllowed());
|
||||
if (realm.isEditUsernameAllowed() != null) Assert.assertEquals(realm.isEditUsernameAllowed(), storedRealm.isEditUsernameAllowed());
|
||||
if (realm.getSslRequired() != null) Assert.assertEquals(realm.getSslRequired(), storedRealm.getSslRequired());
|
||||
if (realm.getAccessCodeLifespan() != null) Assert.assertEquals(realm.getAccessCodeLifespan(), storedRealm.getAccessCodeLifespan());
|
||||
if (realm.isEnabled() != null) assertEquals(realm.isEnabled(), storedRealm.isEnabled());
|
||||
if (realm.isBruteForceProtected() != null) assertEquals(realm.isBruteForceProtected(), storedRealm.isBruteForceProtected());
|
||||
if (realm.getMaxFailureWaitSeconds() != null) assertEquals(realm.getMaxFailureWaitSeconds(), storedRealm.getMaxFailureWaitSeconds());
|
||||
if (realm.getMinimumQuickLoginWaitSeconds() != null) assertEquals(realm.getMinimumQuickLoginWaitSeconds(), storedRealm.getMinimumQuickLoginWaitSeconds());
|
||||
if (realm.getWaitIncrementSeconds() != null) assertEquals(realm.getWaitIncrementSeconds(), storedRealm.getWaitIncrementSeconds());
|
||||
if (realm.getQuickLoginCheckMilliSeconds() != null) assertEquals(realm.getQuickLoginCheckMilliSeconds(), storedRealm.getQuickLoginCheckMilliSeconds());
|
||||
if (realm.getMaxDeltaTimeSeconds() != null) assertEquals(realm.getMaxDeltaTimeSeconds(), storedRealm.getMaxDeltaTimeSeconds());
|
||||
if (realm.getFailureFactor() != null) assertEquals(realm.getFailureFactor(), storedRealm.getFailureFactor());
|
||||
if (realm.isRegistrationAllowed() != null) assertEquals(realm.isRegistrationAllowed(), storedRealm.isRegistrationAllowed());
|
||||
if (realm.isRegistrationEmailAsUsername() != null) assertEquals(realm.isRegistrationEmailAsUsername(), storedRealm.isRegistrationEmailAsUsername());
|
||||
if (realm.isRememberMe() != null) assertEquals(realm.isRememberMe(), storedRealm.isRememberMe());
|
||||
if (realm.isVerifyEmail() != null) assertEquals(realm.isVerifyEmail(), storedRealm.isVerifyEmail());
|
||||
if (realm.isResetPasswordAllowed() != null) assertEquals(realm.isResetPasswordAllowed(), storedRealm.isResetPasswordAllowed());
|
||||
if (realm.isEditUsernameAllowed() != null) assertEquals(realm.isEditUsernameAllowed(), storedRealm.isEditUsernameAllowed());
|
||||
if (realm.getSslRequired() != null) assertEquals(realm.getSslRequired(), storedRealm.getSslRequired());
|
||||
if (realm.getAccessCodeLifespan() != null) assertEquals(realm.getAccessCodeLifespan(), storedRealm.getAccessCodeLifespan());
|
||||
if (realm.getAccessCodeLifespanUserAction() != null)
|
||||
Assert.assertEquals(realm.getAccessCodeLifespanUserAction(), storedRealm.getAccessCodeLifespanUserAction());
|
||||
if (realm.getNotBefore() != null) Assert.assertEquals(realm.getNotBefore(), storedRealm.getNotBefore());
|
||||
if (realm.getAccessTokenLifespan() != null) Assert.assertEquals(realm.getAccessTokenLifespan(), storedRealm.getAccessTokenLifespan());
|
||||
if (realm.getAccessTokenLifespanForImplicitFlow() != null) Assert.assertEquals(realm.getAccessTokenLifespanForImplicitFlow(), storedRealm.getAccessTokenLifespanForImplicitFlow());
|
||||
if (realm.getSsoSessionIdleTimeout() != null) Assert.assertEquals(realm.getSsoSessionIdleTimeout(), storedRealm.getSsoSessionIdleTimeout());
|
||||
if (realm.getSsoSessionMaxLifespan() != null) Assert.assertEquals(realm.getSsoSessionMaxLifespan(), storedRealm.getSsoSessionMaxLifespan());
|
||||
assertEquals(realm.getAccessCodeLifespanUserAction(), storedRealm.getAccessCodeLifespanUserAction());
|
||||
if (realm.getNotBefore() != null) assertEquals(realm.getNotBefore(), storedRealm.getNotBefore());
|
||||
if (realm.getAccessTokenLifespan() != null) assertEquals(realm.getAccessTokenLifespan(), storedRealm.getAccessTokenLifespan());
|
||||
if (realm.getAccessTokenLifespanForImplicitFlow() != null) assertEquals(realm.getAccessTokenLifespanForImplicitFlow(), storedRealm.getAccessTokenLifespanForImplicitFlow());
|
||||
if (realm.getSsoSessionIdleTimeout() != null) assertEquals(realm.getSsoSessionIdleTimeout(), storedRealm.getSsoSessionIdleTimeout());
|
||||
if (realm.getSsoSessionMaxLifespan() != null) assertEquals(realm.getSsoSessionMaxLifespan(), storedRealm.getSsoSessionMaxLifespan());
|
||||
if (realm.getRequiredCredentials() != null) {
|
||||
Assert.assertNotNull(storedRealm.getRequiredCredentials());
|
||||
assertNotNull(storedRealm.getRequiredCredentials());
|
||||
for (String cred : realm.getRequiredCredentials()) {
|
||||
Assert.assertTrue(storedRealm.getRequiredCredentials().contains(cred));
|
||||
assertTrue(storedRealm.getRequiredCredentials().contains(cred));
|
||||
}
|
||||
}
|
||||
if (realm.getLoginTheme() != null) Assert.assertEquals(realm.getLoginTheme(), storedRealm.getLoginTheme());
|
||||
if (realm.getAccountTheme() != null) Assert.assertEquals(realm.getAccountTheme(), storedRealm.getAccountTheme());
|
||||
if (realm.getAdminTheme() != null) Assert.assertEquals(realm.getAdminTheme(), storedRealm.getAdminTheme());
|
||||
if (realm.getEmailTheme() != null) Assert.assertEquals(realm.getEmailTheme(), storedRealm.getEmailTheme());
|
||||
if (realm.getLoginTheme() != null) assertEquals(realm.getLoginTheme(), storedRealm.getLoginTheme());
|
||||
if (realm.getAccountTheme() != null) assertEquals(realm.getAccountTheme(), storedRealm.getAccountTheme());
|
||||
if (realm.getAdminTheme() != null) assertEquals(realm.getAdminTheme(), storedRealm.getAdminTheme());
|
||||
if (realm.getEmailTheme() != null) assertEquals(realm.getEmailTheme(), storedRealm.getEmailTheme());
|
||||
|
||||
if (realm.getPasswordPolicy() != null) Assert.assertEquals(realm.getPasswordPolicy(), storedRealm.getPasswordPolicy());
|
||||
if (realm.getPasswordPolicy() != null) assertEquals(realm.getPasswordPolicy(), storedRealm.getPasswordPolicy());
|
||||
|
||||
if (realm.getDefaultRoles() != null) {
|
||||
Assert.assertNotNull(storedRealm.getDefaultRoles());
|
||||
assertNotNull(storedRealm.getDefaultRoles());
|
||||
for (String role : realm.getDefaultRoles()) {
|
||||
Assert.assertTrue(storedRealm.getDefaultRoles().contains(role));
|
||||
assertTrue(storedRealm.getDefaultRoles().contains(role));
|
||||
}
|
||||
}
|
||||
|
||||
if (realm.getSmtpServer() != null) {
|
||||
Assert.assertEquals(realm.getSmtpServer(), storedRealm.getSmtpServer());
|
||||
assertEquals(realm.getSmtpServer(), storedRealm.getSmtpServer());
|
||||
}
|
||||
|
||||
if (realm.getBrowserSecurityHeaders() != null) {
|
||||
Assert.assertEquals(realm.getBrowserSecurityHeaders(), storedRealm.getBrowserSecurityHeaders());
|
||||
assertEquals(realm.getBrowserSecurityHeaders(), storedRealm.getBrowserSecurityHeaders());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -379,6 +357,7 @@ public class RealmTest extends AbstractClientTest {
|
|||
realm.update(rep);
|
||||
fail("Expected BadRequestException");
|
||||
} catch (BadRequestException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
rep.setPrivateKey(PRIVATE_KEY);
|
||||
|
@ -388,17 +367,18 @@ public class RealmTest extends AbstractClientTest {
|
|||
realm.update(rep);
|
||||
fail("Expected BadRequestException");
|
||||
} catch (BadRequestException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
assertEquals(originalPublicKey, realm.toRepresentation().getPublicKey());
|
||||
Assert.assertEquals(originalPublicKey, realm.toRepresentation().getPublicKey());
|
||||
|
||||
rep.setPublicKey(PUBLIC_KEY);
|
||||
realm.update(rep);
|
||||
|
||||
assertEquals(PUBLIC_KEY, rep.getPublicKey());
|
||||
|
||||
String privateKey2048 = IOUtils.toString(getClass().getResourceAsStream("/keys/private2048.pem"));
|
||||
String publicKey2048 = IOUtils.toString(getClass().getResourceAsStream("/keys/public2048.pem"));
|
||||
String privateKey2048 = StreamUtil.readString(getClass().getResourceAsStream("/keys/private2048.pem"));
|
||||
String publicKey2048 = StreamUtil.readString(getClass().getResourceAsStream("/keys/public2048.pem"));
|
||||
|
||||
rep.setPrivateKey(privateKey2048);
|
||||
|
||||
|
@ -406,24 +386,25 @@ public class RealmTest extends AbstractClientTest {
|
|||
realm.update(rep);
|
||||
fail("Expected BadRequestException");
|
||||
} catch (BadRequestException e) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
assertEquals(PUBLIC_KEY, realm.toRepresentation().getPublicKey());
|
||||
Assert.assertEquals(PUBLIC_KEY, realm.toRepresentation().getPublicKey());
|
||||
|
||||
rep.setPublicKey(publicKey2048);
|
||||
|
||||
realm.update(rep);
|
||||
|
||||
assertEquals(publicKey2048, realm.toRepresentation().getPublicKey());
|
||||
Assert.assertEquals(publicKey2048, realm.toRepresentation().getPublicKey());
|
||||
|
||||
String privateKey4096 = IOUtils.toString(getClass().getResourceAsStream("/keys/private4096.pem"));
|
||||
String publicKey4096 = IOUtils.toString(getClass().getResourceAsStream("/keys/public4096.pem"));
|
||||
String privateKey4096 = StreamUtil.readString(getClass().getResourceAsStream("/keys/private4096.pem"));
|
||||
String publicKey4096 = StreamUtil.readString(getClass().getResourceAsStream("/keys/public4096.pem"));
|
||||
rep.setPrivateKey(privateKey4096);
|
||||
rep.setPublicKey(publicKey4096);
|
||||
|
||||
realm.update(rep);
|
||||
|
||||
assertEquals(publicKey4096, realm.toRepresentation().getPublicKey());
|
||||
Assert.assertEquals(publicKey4096, realm.toRepresentation().getPublicKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -443,22 +424,4 @@ public class RealmTest extends AbstractClientTest {
|
|||
assertEquals(certificate, rep.getCertificate());
|
||||
}
|
||||
|
||||
@Test
|
||||
// KEYCLOAK-2700
|
||||
public void deleteRealmWithDefaultGroups() throws IOException {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setRealm("foo");
|
||||
|
||||
GroupRepresentation group = new GroupRepresentation();
|
||||
group.setName("default1");
|
||||
group.setPath("/default1");
|
||||
|
||||
rep.setGroups(Collections.singletonList(group));
|
||||
rep.setDefaultGroups(Collections.singletonList("/default1"));
|
||||
|
||||
keycloak.realms().create(rep);
|
||||
|
||||
keycloak.realm(rep.getRealm()).remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -37,6 +37,7 @@ import javax.ws.rs.NotFoundException;
|
|||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -243,4 +244,23 @@ public class GroupTest extends AbstractGroupTest {
|
|||
|
||||
Assert.assertNull(login("direct-login", "resource-owner", "secret", user.getId()).getRealmAccess());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
// KEYCLOAK-2700
|
||||
public void deleteRealmWithDefaultGroups() throws IOException {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setRealm("foo");
|
||||
|
||||
GroupRepresentation group = new GroupRepresentation();
|
||||
group.setName("default1");
|
||||
group.setPath("/default1");
|
||||
|
||||
rep.setGroups(Collections.singletonList(group));
|
||||
rep.setDefaultGroups(Collections.singletonList("/default1"));
|
||||
|
||||
adminClient.realms().create(rep);
|
||||
|
||||
adminClient.realm(rep.getRealm()).remove();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue