Updated test scenarios

This commit is contained in:
azilentech 2022-04-29 17:49:49 +05:30 committed by Pedro Igor
parent 96f5883ee0
commit f7f24c6ca3
2 changed files with 51 additions and 13 deletions

View file

@ -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.ModalDialog;
import org.keycloak.testsuite.console.page.fragment.MultipleStringSelect2; import org.keycloak.testsuite.console.page.fragment.MultipleStringSelect2;
import org.keycloak.testsuite.console.page.fragment.SingleStringSelect2; 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.page.Form;
import org.keycloak.testsuite.util.UIUtils; import org.keycloak.testsuite.util.UIUtils;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
@ -73,9 +74,6 @@ public class ScopePermissionForm extends Form {
@FindBy(id = "s2id_scopes") @FindBy(id = "s2id_scopes")
private MultipleStringSelect2 scopeSelect; private MultipleStringSelect2 scopeSelect;
@FindBy(id = "s2id_resourceScopes")
private MultipleStringSelect2 resourceScopeSelect;
@FindBy(id = "s2id_resources") @FindBy(id = "s2id_resources")
private ResourceSelect resourceSelect; private ResourceSelect resourceSelect;
@ -85,6 +83,12 @@ public class ScopePermissionForm extends Form {
@FindBy(id = "create-policy") @FindBy(id = "create-policy")
private Select createPolicySelect; private Select createPolicySelect;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='applyToResourceTypeFlag']]")
private OnOffSwitch resourceTypeSwitch;
@FindBy(id = "resourceType")
private WebElement resourceType;
@Page @Page
private RolePolicy rolePolicy; private RolePolicy rolePolicy;
@ -110,15 +114,24 @@ public class ScopePermissionForm extends Form {
Set<String> resources = expected.getResources(); Set<String> resources = expected.getResources();
if (resources != null && !resources.isEmpty()) { resourceTypeSwitch.setOn(expected.getResourceType() != null);
resourceSelect.update(resources);
resourceScopeSelect.update(expected.getScopes()); if (expected.getResourceType() != null) {
} else { UIUtils.setTextInputValue(resourceType, expected.getResourceType());
if (resourceSelectRemoveChoice.isDisplayed()) {
resourceSelectRemoveChoice.click();
}
scopeSelect.update(expected.getScopes());
} }
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) { if (expected.getPolicies() != null) {
policySelect.update(expected.getPolicies()); policySelect.update(expected.getPolicies());
@ -141,9 +154,15 @@ public class ScopePermissionForm extends Form {
representation.setDescription(UIUtils.getTextInputValue(description)); representation.setDescription(UIUtils.getTextInputValue(description));
representation.setDecisionStrategy(DecisionStrategy.valueOf(UIUtils.getTextFromElement(decisionStrategy.getFirstSelectedOption()).toUpperCase())); representation.setDecisionStrategy(DecisionStrategy.valueOf(UIUtils.getTextFromElement(decisionStrategy.getFirstSelectedOption()).toUpperCase()));
representation.setPolicies(policySelect.getSelected()); 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.setScopes(scopeSelect.getSelected());
representation.getScopes().addAll(resourceScopeSelect.getSelected());
return representation; return representation;
} }

View file

@ -27,6 +27,7 @@ import org.junit.Test;
import org.keycloak.admin.client.resource.AuthorizationResource; import org.keycloak.admin.client.resource.AuthorizationResource;
import org.keycloak.admin.client.resource.PoliciesResource; import org.keycloak.admin.client.resource.PoliciesResource;
import org.keycloak.admin.client.resource.ResourcesResource; 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.RolePoliciesResource;
import org.keycloak.admin.client.resource.RolesResource; import org.keycloak.admin.client.resource.RolesResource;
import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.RoleRepresentation;
@ -301,6 +302,23 @@ public class ScopePermissionManagementTest extends AbstractAuthorizationSettings
assertPolicy(expected, actual); 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) { private ScopePermissionRepresentation createPermission(ScopePermissionRepresentation expected) {
ScopePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, true); ScopePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, true);
assertAlertSuccess(); assertAlertSuccess();
@ -313,6 +331,7 @@ public class ScopePermissionManagementTest extends AbstractAuthorizationSettings
assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getName(), actual.getName());
assertEquals(expected.getDescription(), actual.getDescription()); assertEquals(expected.getDescription(), actual.getDescription());
assertEquals(expected.getDecisionStrategy(), actual.getDecisionStrategy()); assertEquals(expected.getDecisionStrategy(), actual.getDecisionStrategy());
assertEquals(expected.getResourceType(), actual.getResourceType());
if (expected.getPolicies() == null) { if (expected.getPolicies() == null) {
assertTrue(actual.getPolicies() == null || actual.getPolicies().isEmpty()); assertTrue(actual.getPolicies() == null || actual.getPolicies().isEmpty());