From 61d5425fdf40b60528c1881fa9fe7bb8508177d8 Mon Sep 17 00:00:00 2001 From: pedroigor Date: Wed, 21 Feb 2018 09:45:30 -0300 Subject: [PATCH] [KEYCLOAK-6321] - Tests --- .../authorization/AuthorizationTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/AuthorizationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/AuthorizationTest.java index 55936b26fc..2d549de86b 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/AuthorizationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/AuthorizationTest.java @@ -20,8 +20,10 @@ package org.keycloak.testsuite.admin.client.authorization; import org.junit.Test; import org.keycloak.admin.client.resource.ClientResource; +import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.representations.adapters.config.PolicyEnforcerConfig; import org.keycloak.representations.idm.ClientRepresentation; +import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.authorization.PolicyRepresentation; import org.keycloak.representations.idm.authorization.ResourceRepresentation; import org.keycloak.representations.idm.authorization.ResourceServerRepresentation; @@ -29,6 +31,7 @@ import org.keycloak.representations.idm.authorization.ResourceServerRepresentati import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @@ -55,4 +58,32 @@ public class AuthorizationTest extends AbstractAuthorizationTest { assertEquals(2, defaultPolicies.size()); } + + // KEYCLOAK-6321 + @Test + public void testRemoveDefaultResourceWithAdminEventsEnabled() { + RealmResource realmResource = testRealmResource(); + RealmRepresentation realmRepresentation = realmResource.toRepresentation(); + + realmRepresentation.setAdminEventsEnabled(true); + + realmResource.update(realmRepresentation); + + ClientResource clientResource = getClientResource(); + ClientRepresentation resourceServer = getResourceServer(); + + enableAuthorizationServices(); + + ResourceServerRepresentation settings = clientResource.authorization().getSettings(); + + assertEquals(PolicyEnforcerConfig.EnforcementMode.ENFORCING.name(), settings.getPolicyEnforcementMode().name()); + assertEquals(resourceServer.getId(), settings.getClientId()); + List defaultResources = clientResource.authorization().resources().resources(); + + assertEquals(1, defaultResources.size()); + + clientResource.authorization().resources().resource(defaultResources.get(0).getId()).remove(); + + assertTrue(clientResource.authorization().resources().resources().isEmpty()); + } } \ No newline at end of file