diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/ScopePermissionForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/ScopePermissionForm.java index f7947c7769..171d2fbe51 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/ScopePermissionForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/ScopePermissionForm.java @@ -41,6 +41,7 @@ import org.keycloak.testsuite.console.page.clients.authorization.policy.UserPoli import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.console.page.fragment.MultipleStringSelect2; import org.keycloak.testsuite.console.page.fragment.SingleStringSelect2; +import org.keycloak.testsuite.console.page.fragment.OnOffSwitch; import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.util.UIUtils; import org.openqa.selenium.WebElement; @@ -73,9 +74,6 @@ public class ScopePermissionForm extends Form { @FindBy(id = "s2id_scopes") private MultipleStringSelect2 scopeSelect; - @FindBy(id = "s2id_resourceScopes") - private MultipleStringSelect2 resourceScopeSelect; - @FindBy(id = "s2id_resources") private ResourceSelect resourceSelect; @@ -85,6 +83,12 @@ public class ScopePermissionForm extends Form { @FindBy(id = "create-policy") private Select createPolicySelect; + @FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='applyToResourceTypeFlag']]") + private OnOffSwitch resourceTypeSwitch; + + @FindBy(id = "resourceType") + private WebElement resourceType; + @Page private RolePolicy rolePolicy; @@ -110,15 +114,24 @@ public class ScopePermissionForm extends Form { Set resources = expected.getResources(); - if (resources != null && !resources.isEmpty()) { - resourceSelect.update(resources); - resourceScopeSelect.update(expected.getScopes()); - } else { - if (resourceSelectRemoveChoice.isDisplayed()) { - resourceSelectRemoveChoice.click(); - } - scopeSelect.update(expected.getScopes()); + resourceTypeSwitch.setOn(expected.getResourceType() != null); + + if (expected.getResourceType() != null) { + UIUtils.setTextInputValue(resourceType, expected.getResourceType()); } + else { + resourceTypeSwitch.setOn(false); + if (resources != null && !resources.isEmpty()) { + resourceSelect.update(resources); + } + else { + if (resourceSelectRemoveChoice.isDisplayed()) { + resourceSelectRemoveChoice.click(); + } + } + } + + scopeSelect.update(expected.getScopes()); if (expected.getPolicies() != null) { policySelect.update(expected.getPolicies()); @@ -141,9 +154,15 @@ public class ScopePermissionForm extends Form { representation.setDescription(UIUtils.getTextInputValue(description)); representation.setDecisionStrategy(DecisionStrategy.valueOf(UIUtils.getTextFromElement(decisionStrategy.getFirstSelectedOption()).toUpperCase())); representation.setPolicies(policySelect.getSelected()); - representation.setResources(resourceSelect.getSelected()); + String inputValue = UIUtils.getTextInputValue(resourceType); + if (!"".equals(inputValue)) { + representation.setResourceType(inputValue); + } + else{ + representation.setResources(resourceSelect.getSelected()); + } + representation.setScopes(scopeSelect.getSelected()); - representation.getScopes().addAll(resourceScopeSelect.getSelected()); return representation; } diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authorization/ScopePermissionManagementTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authorization/ScopePermissionManagementTest.java index d53efcfe8e..0c57f6492b 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authorization/ScopePermissionManagementTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authorization/ScopePermissionManagementTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.keycloak.admin.client.resource.AuthorizationResource; import org.keycloak.admin.client.resource.PoliciesResource; import org.keycloak.admin.client.resource.ResourcesResource; +import org.keycloak.admin.client.resource.ScopePermissionsResource; import org.keycloak.admin.client.resource.RolePoliciesResource; import org.keycloak.admin.client.resource.RolesResource; import org.keycloak.representations.idm.RoleRepresentation; @@ -301,6 +302,23 @@ public class ScopePermissionManagementTest extends AbstractAuthorizationSettings assertPolicy(expected, actual); } + @Test + public void testUpdateResourceType() { + authorizationPage.navigateTo(); + ScopePermissionRepresentation expected = new ScopePermissionRepresentation(); + + expected.setName("testUpdateResourceType Permission"); + expected.setDescription("description"); + expected.setResourceType("test-resource-type"); + expected.addScope("Scope A"); + + expected = createPermission(expected); + + authorizationPage.navigateTo(); + ScopePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName()); + assertPolicy(expected, actual); + } + private ScopePermissionRepresentation createPermission(ScopePermissionRepresentation expected) { ScopePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, true); assertAlertSuccess(); @@ -313,6 +331,7 @@ public class ScopePermissionManagementTest extends AbstractAuthorizationSettings assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getDescription(), actual.getDescription()); assertEquals(expected.getDecisionStrategy(), actual.getDecisionStrategy()); + assertEquals(expected.getResourceType(), actual.getResourceType()); if (expected.getPolicies() == null) { assertTrue(actual.getPolicies() == null || actual.getPolicies().isEmpty());