KEYCLOAK-7584 Fix some admin console tests broken by adding clientScopes support

This commit is contained in:
mposolda 2018-08-28 17:16:14 +02:00 committed by Marek Posolda
parent c0b5c12dee
commit 5ae126b10e
5 changed files with 44 additions and 81 deletions

View file

@ -38,12 +38,6 @@ public class CreateClientMappersForm extends Form {
@FindBy(id = "name") @FindBy(id = "name")
private WebElement nameElement; private WebElement nameElement;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='consentRequired']]")
private OnOffSwitch consentRequiredSwitch;
@FindBy(id = "consentText")
private WebElement consentTextElement;
@FindBy(id = "mapperTypeCreate") @FindBy(id = "mapperTypeCreate")
private Select mapperTypeSelect; private Select mapperTypeSelect;
@ -154,22 +148,6 @@ public class CreateClientMappersForm extends Form {
UIUtils.setTextInputValue(nameElement, value); UIUtils.setTextInputValue(nameElement, value);
} }
public boolean isConsentRequired() {
return consentRequiredSwitch.isOn();
}
public void setConsentRequired(boolean consentRequired) {
consentRequiredSwitch.setOn(consentRequired);
}
public String getConsentText() {
return UIUtils.getTextInputValue(consentTextElement);
}
public void setConsentText(String consentText) {
UIUtils.setTextInputValue(consentTextElement, consentText);
}
public void setMapperType(String type) { public void setMapperType(String type) {
mapperTypeSelect.selectByVisibleText(type); mapperTypeSelect.selectByVisibleText(type);
} }

View file

@ -19,9 +19,6 @@ public class RoleDetailsForm extends Form {
@FindBy(id = "description") @FindBy(id = "description")
private WebElement descriptionInput; private WebElement descriptionInput;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='scopeParamRequired']]")
private OnOffSwitch scopeParamRequired;
@FindBy(xpath = ".//div[contains(@class,'onoffswitch') and ./input[@id='compositeSwitch']]") @FindBy(xpath = ".//div[contains(@class,'onoffswitch') and ./input[@id='compositeSwitch']]")
private OnOffSwitch compositeSwitch; private OnOffSwitch compositeSwitch;
@ -32,7 +29,7 @@ public class RoleDetailsForm extends Form {
private WebElement removeIcon; private WebElement removeIcon;
public RoleRepresentation getRole() { public RoleRepresentation getRole() {
RoleRepresentation role = new RoleRepresentation(getName(), getDescription(), isScopeParamRequired()); RoleRepresentation role = new RoleRepresentation(getName(), getDescription(), false);
role.setComposite(isComposite()); role.setComposite(isComposite());
if (role.isComposite()) { if (role.isComposite()) {
role.setComposites(compositeRoles.getComposites()); role.setComposites(compositeRoles.getComposites());
@ -48,7 +45,6 @@ public class RoleDetailsForm extends Form {
RoleRepresentation role = new RoleRepresentation(); RoleRepresentation role = new RoleRepresentation();
role.setName(getName()); role.setName(getName());
role.setDescription(getDescription()); role.setDescription(getDescription());
//role.setScopeParamRequired(isScopeParamRequired()); // TODO Do we need this param?
role.setComposite(isComposite()); role.setComposite(isComposite());
log.info(role.getName() + ": " + role.getDescription() + ", comp: " + role.isComposite()); log.info(role.getName() + ": " + role.getDescription() + ", comp: " + role.isComposite());
return role; return role;
@ -57,7 +53,6 @@ public class RoleDetailsForm extends Form {
public void setBasicAttributes(RoleRepresentation role) { public void setBasicAttributes(RoleRepresentation role) {
setName(role.getName()); setName(role.getName());
setDescription(role.getDescription()); setDescription(role.getDescription());
setScopeParamRequired(role.isScopeParamRequired());
if (role.isComposite()) { if (role.isComposite()) {
setCompositeRoles(role); setCompositeRoles(role);
} }
@ -88,14 +83,6 @@ public class RoleDetailsForm extends Form {
return UIUtils.getTextInputValue(descriptionInput); return UIUtils.getTextInputValue(descriptionInput);
} }
public void setScopeParamRequired(boolean scopeParamRequired) {
this.scopeParamRequired.setOn(scopeParamRequired);
}
public boolean isScopeParamRequired() {
return scopeParamRequired.isOn();
}
public void setComposite(boolean composite) { public void setComposite(boolean composite) {
compositeSwitch.setOn(composite); compositeSwitch.setOn(composite);
} }

View file

@ -25,6 +25,7 @@ import org.jboss.arquillian.graphene.page.Page;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import org.keycloak.testsuite.console.page.clients.mappers.ClientMapper; import org.keycloak.testsuite.console.page.clients.mappers.ClientMapper;
@ -68,19 +69,15 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
clientMappersPage.navigateTo(); clientMappersPage.navigateTo();
} }
private void setInitialValues(String name, boolean consentRequired, String consentText) { private void setInitialValues(String name) {
createClientMappersPage.form().setName(name); createClientMappersPage.form().setName(name);
createClientMappersPage.form().setConsentRequired(consentRequired);
if (consentRequired) {
createClientMappersPage.form().setConsentText(consentText);
}
} }
@Test @Test
public void testHardcodedRole() { public void testHardcodedRole() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role", true, "Consent Text"); setInitialValues("hardcoded role");
createClientMappersPage.form().setMapperType(HARDCODED_ROLE); createClientMappersPage.form().setMapperType(HARDCODED_ROLE);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null); createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
@ -90,8 +87,6 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded role"); ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded role");
assertNotNull(found); assertNotNull(found);
assertTrue(found.isConsentRequired());
assertEquals("Consent Text", found.getConsentText());
assertEquals("oidc-hardcoded-role-mapper", found.getProtocolMapper()); assertEquals("oidc-hardcoded-role-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig(); Map<String, String> config = found.getConfig();
@ -119,7 +114,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testHardcodedClaim() { public void testHardcodedClaim() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded claim", false, null); setInitialValues("hardcoded claim");
createClientMappersPage.form().setMapperType(HARDCODED_CLAIM); createClientMappersPage.form().setMapperType(HARDCODED_CLAIM);
createClientMappersPage.form().setTokenClaimName("claim name"); createClientMappersPage.form().setTokenClaimName("claim name");
createClientMappersPage.form().setTokenClaimValue("claim value"); createClientMappersPage.form().setTokenClaimValue("claim value");
@ -133,7 +128,6 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded claim"); ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded claim");
assertNotNull(found); assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("oidc-hardcoded-claim-mapper", found.getProtocolMapper()); assertEquals("oidc-hardcoded-claim-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig(); Map<String, String> config = found.getConfig();
@ -148,7 +142,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testUserSessionNote() { public void testUserSessionNote() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user session note", false, null); setInitialValues("user session note");
createClientMappersPage.form().setMapperType(USER_SESSION_NOTE); createClientMappersPage.form().setMapperType(USER_SESSION_NOTE);
createClientMappersPage.form().setUserSessionNote("session note"); createClientMappersPage.form().setUserSessionNote("session note");
createClientMappersPage.form().setTokenClaimName("claim name"); createClientMappersPage.form().setTokenClaimName("claim name");
@ -162,7 +156,6 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note"); ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note");
assertNotNull(found); assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("oidc-usersessionmodel-note-mapper", found.getProtocolMapper()); assertEquals("oidc-usersessionmodel-note-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig(); Map<String, String> config = found.getConfig();
@ -175,7 +168,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testRoleName() { public void testRoleName() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("role name", false, null); setInitialValues("role name");
createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER); createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER);
createClientMappersPage.form().setRole("offline_access"); createClientMappersPage.form().setRole("offline_access");
createClientMappersPage.form().setNewRole("new role"); createClientMappersPage.form().setNewRole("new role");
@ -195,7 +188,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testUserAddress() { public void testUserAddress() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user address", false, null); setInitialValues("user address");
createClientMappersPage.form().setMapperType(USERS_FULL_NAME); createClientMappersPage.form().setMapperType(USERS_FULL_NAME);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
@ -209,7 +202,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testUserFullName() { public void testUserFullName() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user full name", false, null); setInitialValues("user full name");
createClientMappersPage.form().setMapperType(USERS_FULL_NAME); createClientMappersPage.form().setMapperType(USERS_FULL_NAME);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
@ -223,7 +216,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testUserAttribute() { public void testUserAttribute() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user attribute", false, null); setInitialValues("user attribute");
createClientMappersPage.form().setMapperType(USER_ATTRIBUTE); createClientMappersPage.form().setMapperType(USER_ATTRIBUTE);
createClientMappersPage.form().setUserAttribute("user attribute"); createClientMappersPage.form().setUserAttribute("user attribute");
createClientMappersPage.form().setMultivalued(true); createClientMappersPage.form().setMultivalued(true);
@ -243,7 +236,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testUserProperty() { public void testUserProperty() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user property", false, null); setInitialValues("user property");
createClientMappersPage.form().setMapperType(USER_PROPERTY); createClientMappersPage.form().setMapperType(USER_PROPERTY);
createClientMappersPage.form().setProperty("property"); createClientMappersPage.form().setProperty("property");
createClientMappersPage.form().save(); createClientMappersPage.form().save();
@ -261,7 +254,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
public void testGroupMembership() { public void testGroupMembership() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("group membership", false, null); setInitialValues("group membership");
createClientMappersPage.form().setMapperType(GROUP_MEMBERSHIP); createClientMappersPage.form().setMapperType(GROUP_MEMBERSHIP);
createClientMappersPage.form().setFullGroupPath(true); createClientMappersPage.form().setFullGroupPath(true);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
@ -306,8 +299,6 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
assertEquals("openid-connect", clientMapperPage.form().getProtocol()); assertEquals("openid-connect", clientMapperPage.form().getProtocol());
assertEquals(mapperId, clientMapperPage.form().getMapperId()); assertEquals(mapperId, clientMapperPage.form().getMapperId());
assertEquals("mapper name", clientMapperPage.form().getName()); assertEquals("mapper name", clientMapperPage.form().getName());
assertTrue(clientMapperPage.form().isConsentRequired());
assertEquals("consent text", clientMapperPage.form().getConsentText());
assertEquals("User Session Note", clientMapperPage.form().getMapperType()); assertEquals("User Session Note", clientMapperPage.form().getMapperType());
assertEquals("session note", clientMapperPage.form().getUserSessionNote()); assertEquals("session note", clientMapperPage.form().getUserSessionNote());
assertEquals("claim name", clientMapperPage.form().getTokenClaimName()); assertEquals("claim name", clientMapperPage.form().getTokenClaimName());
@ -316,12 +307,18 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
assertTrue(clientMapperPage.form().isAddToAccessToken()); assertTrue(clientMapperPage.form().isAddToAccessToken());
//edit //edit
clientMapperPage.form().setConsentRequired(false); clientMapperPage.form().setAddToAccessToken(false);
clientMapperPage.form().save(); clientMapperPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
//check //check
assertFalse(findClientMapperByName(id, "mapper name").isConsentRequired()); assertTrue(clientMapperPage.form().isAddToIDToken());
assertFalse(clientMapperPage.form().isAddToAccessToken());
ProtocolMapperRepresentation rep = findClientMapperByName(id, "mapper name");
assertEquals("false", rep.getConfig().get(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN));
assertEquals("true", rep.getConfig().get(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN));
} }
@Test @Test
@ -353,7 +350,16 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
@Test @Test
public void testCreateMapperInvalidValues() { public void testCreateMapperInvalidValues() {
//create some mapper, so we have some existing
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role - existing");
createClientMappersPage.form().setMapperType(HARDCODED_ROLE);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save();
assertAlertSuccess();
//empty mapper type //empty mapper type
clientMappersPage.navigateTo();
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertDanger(); assertAlertDanger();
@ -373,7 +379,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
assertAlertDanger(); assertAlertDanger();
//existing name //existing name
createClientMappersPage.form().setName("email"); createClientMappersPage.form().setName("hardcoded role - existing");
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertDanger(); assertAlertDanger();
} }

View file

@ -63,19 +63,15 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
clientMappersPage.navigateTo(); clientMappersPage.navigateTo();
} }
private void setInitialValues(String name, boolean consentRequired, String consentText) { private void setInitialValues(String name) {
createClientMappersPage.form().setName(name); createClientMappersPage.form().setName(name);
createClientMappersPage.form().setConsentRequired(consentRequired);
if (consentRequired) {
createClientMappersPage.form().setConsentText(consentText);
}
} }
@Test @Test
public void testRoleName() { public void testRoleName() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("role name", false, null); setInitialValues("role name");
createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER); createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER);
createClientMappersPage.form().setRole("offline_access"); createClientMappersPage.form().setRole("offline_access");
createClientMappersPage.form().setNewRole("new role"); createClientMappersPage.form().setNewRole("new role");
@ -95,7 +91,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testRoleList() { public void testRoleList() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("new role list", false, null); setInitialValues("new role list");
createClientMappersPage.form().setMapperType(ROLE_LIST); createClientMappersPage.form().setMapperType(ROLE_LIST);
createClientMappersPage.form().setRoleAttributeName("role attribute name"); createClientMappersPage.form().setRoleAttributeName("role attribute name");
createClientMappersPage.form().setFriendlyName("friendly name"); createClientMappersPage.form().setFriendlyName("friendly name");
@ -108,7 +104,6 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "new role list"); ProtocolMapperRepresentation found = findClientMapperByName(id, "new role list");
assertNotNull(found); assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-role-list-mapper", found.getProtocolMapper()); assertEquals("saml-role-list-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig(); Map<String, String> config = found.getConfig();
@ -122,7 +117,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testUserProperty() { public void testUserProperty() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user property", false, null); setInitialValues("user property");
createClientMappersPage.form().setMapperType(USER_PROPERTY); createClientMappersPage.form().setMapperType(USER_PROPERTY);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
@ -136,7 +131,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testUserSessionNote() { public void testUserSessionNote() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("user session note", false, null); setInitialValues("user session note");
createClientMappersPage.form().setMapperType(USER_SESSION_NOTE); createClientMappersPage.form().setMapperType(USER_SESSION_NOTE);
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
@ -145,7 +140,6 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note"); ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note");
assertNotNull(found); assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-user-session-note-mapper", found.getProtocolMapper()); assertEquals("saml-user-session-note-mapper", found.getProtocolMapper());
} }
@ -153,7 +147,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testHardcodedAttribute() { public void testHardcodedAttribute() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded attribute", false, null); setInitialValues("hardcoded attribute");
createClientMappersPage.form().setMapperType(HARDCODED_ATTRIBUTE); createClientMappersPage.form().setMapperType(HARDCODED_ATTRIBUTE);
createClientMappersPage.form().setAttributeValue("attribute value"); createClientMappersPage.form().setAttributeValue("attribute value");
createClientMappersPage.form().save(); createClientMappersPage.form().save();
@ -163,7 +157,6 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded attribute"); ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded attribute");
assertNotNull(found); assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-hardcode-attribute-mapper", found.getProtocolMapper()); assertEquals("saml-hardcode-attribute-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig(); Map<String, String> config = found.getConfig();
@ -174,7 +167,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testGroupList() { public void testGroupList() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("group list", false, null); setInitialValues("group list");
createClientMappersPage.form().setMapperType(GROUP_LIST); createClientMappersPage.form().setMapperType(GROUP_LIST);
createClientMappersPage.form().setGroupAttributeName("group attribute name"); createClientMappersPage.form().setGroupAttributeName("group attribute name");
createClientMappersPage.form().setSingleGroupAttribute(true); createClientMappersPage.form().setSingleGroupAttribute(true);
@ -196,7 +189,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
public void testHardcodedRole() { public void testHardcodedRole() {
//create //create
clientMappersPage.mapperTable().createMapper(); clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role", false, null); setInitialValues("hardcoded role");
createClientMappersPage.form().setMapperType(HARDCODED_ROLE_SAML); createClientMappersPage.form().setMapperType(HARDCODED_ROLE_SAML);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null); createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save(); createClientMappersPage.form().save();

View file

@ -74,7 +74,6 @@ public class ClientRolesTest extends AbstractClientTest {
RoleRepresentation role = clientRoles.get(0); RoleRepresentation role = clientRoles.get(0);
assertEquals(TEST_CLIENT_ROLE_NAME, role.getName()); assertEquals(TEST_CLIENT_ROLE_NAME, role.getName());
assertEquals("description", role.getDescription()); assertEquals("description", role.getDescription());
assertFalse(role.isScopeParamRequired());
assertFalse(role.isComposite()); assertFalse(role.isComposite());
assertNull(role.getComposites()); assertNull(role.getComposites());