added UI tests for client mappers saml

This commit is contained in:
vramik 2015-12-03 14:47:13 +01:00
parent c16b6e6a43
commit 1dd3fc537b
6 changed files with 323 additions and 65 deletions

View file

@ -24,6 +24,10 @@ public class CreateClientMappersForm extends Form {
public static final String USER_ATTRIBUTE = "User Attribute";
public static final String USER_PROPERTY = "User Property";
public static final String GROUP_MEMBERSHIP = "Group Membership";
public static final String ROLE_LIST = "Role list";
public static final String HARDCODED_ATTRIBUTE = "Hardcoded attribute";
public static final String GROUP_LIST = "Group list";
public static final String HARDCODED_ROLE_SAML = "Hardcoded role";
// Role types
public static final String REALM_ROLE = "realm";
@ -256,5 +260,54 @@ public class CreateClientMappersForm extends Form {
public void setFullGroupPath(boolean value) {
fullGroupPath.setOn(value);
}
//SAML
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Role attribute name']//following-sibling::node()//input[@type='text']")
private WebElement roleAttributeNameInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Friendly Name']//following-sibling::node()//input[@type='text']")
private WebElement friendlyNameInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='SAML Attribute NameFormat']//following-sibling::node()//select")
private Select samlAttributeNameFormatSelect;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Single Role Attribute']//following-sibling::node()//div[@class='onoffswitch']")
private OnOffSwitch singleRoleAttributeSwitch;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Attribute value']//following-sibling::node()//input[@type='text']")
private WebElement attributeValueInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Group attribute name']//following-sibling::node()//input[@type='text']")
private WebElement groupAttributeNameInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Single Group Attribute']//following-sibling::node()//div[@class='onoffswitch']")
private OnOffSwitch singleGroupAttributeSwitch;
public void setRoleAttributeName(String value) {
setInputValue(roleAttributeNameInput, value);
}
public void setFriendlyName(String value) {
setInputValue(friendlyNameInput, value);
}
public void setSamlAttributeNameFormat(String value) {
samlAttributeNameFormatSelect.selectByVisibleText(value);
}
public void setSingleRoleAttribute(boolean value) {
singleRoleAttributeSwitch.setOn(value);
}
public void setAttributeValue(String value) {
setInputValue(attributeValueInput, value);
}
public void setGroupAttributeName(String value) {
setInputValue(groupAttributeNameInput, value);
}
public void setSingleGroupAttribute(boolean value) {
singleGroupAttributeSwitch.setOn(value);
}
}

View file

@ -17,7 +17,6 @@
*/
package org.keycloak.testsuite.console.page.fragment;
import java.util.List;
import org.jboss.arquillian.graphene.fragment.Root;
import org.jboss.arquillian.test.api.ArquillianResource;
import static org.keycloak.testsuite.util.WaitUtils.waitAjaxForElement;

View file

@ -9,6 +9,7 @@ import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import static org.keycloak.testsuite.auth.page.login.OIDCLogin.OIDC;
import static org.keycloak.testsuite.auth.page.login.OIDCLogin.SAML;
import org.keycloak.testsuite.console.AbstractConsoleTest;
@ -106,13 +107,13 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
return client;
}
public static ClientRepresentation createSamlClientRep(String clinetId, Map<String, String> samlAttributes) {
public static ClientRepresentation createSamlClientRep(String clinetId) {
ClientRepresentation client = createClientRep(clinetId);
client.setProtocol(SAML);
client.setFrontchannelLogout(true);
client.setAttributes(samlAttributes);
client.setAttributes(getSAMLAttributes());
return client;
}
@ -170,5 +171,34 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
assertEquals("Expected attribute " + key, expected.get(key), actual.get(key));
}
}
protected static Map<String, String> getSAMLAttributes() {
Map<String, String> attributes = new HashMap<>();
attributes.put(SAML_ASSERTION_SIGNATURE, "true");
attributes.put(SAML_AUTHNSTATEMENT, "false");
attributes.put(SAML_CLIENT_SIGNATURE, "true");
attributes.put(SAML_ENCRYPT, "true");
attributes.put(SAML_FORCE_POST_BINDING, "true");
attributes.put(SAML_MULTIVALUED_ROLES, "false");
attributes.put(SAML_SERVER_SIGNATURE, "true");
attributes.put(SAML_SIGNATURE_ALGORITHM, "RSA_SHA512");
attributes.put(SAML_ASSERTION_CONSUMER_URL_POST, "http://example0.test");
attributes.put(SAML_ASSERTION_CONSUMER_URL_REDIRECT, "http://example1.test");
attributes.put(SAML_FORCE_NAME_ID_FORMAT, "true");
attributes.put(SAML_NAME_ID_FORMAT, "email");
attributes.put(SAML_SIGNATURE_CANONICALIZATION_METHOD, "http://www.w3.org/2001/10/xml-exc-c14n#WithComments");
attributes.put(SAML_SINGLE_LOGOUT_SERVICE_URL_POST, "http://example2.test");
attributes.put(SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT, "http://example3.test");
return attributes;
}
public ProtocolMapperRepresentation findClientMapperByName(String clientId, String mapperName) {
ProtocolMapperRepresentation found = null;
for (ProtocolMapperRepresentation mapper : testRealmResource().clients().get(clientId).getProtocolMappers().getMappers()) {
if (mapperName.equals(mapper.getName())) {
found = mapper;
}
}
return found;
}
}

View file

@ -40,10 +40,8 @@ import static org.keycloak.testsuite.console.page.clients.mappers.CreateClientMa
/**
*
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*
* TODO: saml mappers
*/
public class ClientMappersTest extends AbstractClientTest {
public class ClientMappersOIDCTest extends AbstractClientTest {
private String id;
@ -65,16 +63,6 @@ public class ClientMappersTest extends AbstractClientTest {
clientMappersPage.navigateTo();
}
private ProtocolMapperRepresentation findClientMapperByName(String mapperName) {
ProtocolMapperRepresentation found = null;
for (ProtocolMapperRepresentation mapper : testRealmResource().clients().get(id).getProtocolMappers().getMappers()) {
if (mapperName.equals(mapper.getName())) {
found = mapper;
}
}
return found;
}
private void setInitialValues(String name, boolean consentRequired, String consentText) {
createClientMappersPage.form().setName(name);
createClientMappersPage.form().setConsentRequired(consentRequired);
@ -84,7 +72,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCHardcodedRole() {
public void testHardcodedRole() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role", true, "Consent Text");
@ -94,7 +82,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("hardcoded role");
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded role");
assertNotNull(found);
assertTrue(found.isConsentRequired());
@ -111,7 +99,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
config = findClientMapperByName("hardcoded role").getConfig();
config = findClientMapperByName(id, "hardcoded role").getConfig();
assertEquals("account.view-profile", config.get("role"));
//delete
@ -120,11 +108,11 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
assertNull(findClientMapperByName("hardcoded role"));
assertNull(findClientMapperByName(id, "hardcoded role"));
}
@Test
public void testOIDCHardcodedClaim() {
public void testHardcodedClaim() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded claim", false, null);
@ -138,7 +126,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("hardcoded claim");
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded claim");
assertNotNull(found);
assertFalse(found.isConsentRequired());
@ -153,7 +141,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCUserSessionNote() {
public void testUserSessionNote() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user session note", false, null);
@ -167,7 +155,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user session note");
ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note");
assertNotNull(found);
assertFalse(found.isConsentRequired());
@ -182,7 +170,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCRoleName() {
public void testRoleName() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("role name", false, null);
@ -193,7 +181,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("role name");
ProtocolMapperRepresentation found = findClientMapperByName(id, "role name");
assertEquals("oidc-role-name-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
@ -202,7 +190,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCUserAddress() {
public void testUserAddress() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user address", false, null);
@ -211,12 +199,12 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user address");
ProtocolMapperRepresentation found = findClientMapperByName(id, "user address");
assertEquals("oidc-full-name-mapper", found.getProtocolMapper());
}
@Test
public void testOIDCUserFullName() {
public void testUserFullName() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user full name", false, null);
@ -225,12 +213,12 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user full name");
ProtocolMapperRepresentation found = findClientMapperByName(id, "user full name");
assertEquals("oidc-full-name-mapper", found.getProtocolMapper());
}
@Test
public void testOIDCUserAttribute() {
public void testUserAttribute() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user attribute", false, null);
@ -241,7 +229,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user attribute");
ProtocolMapperRepresentation found = findClientMapperByName(id, "user attribute");
assertEquals("oidc-usermodel-attribute-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
@ -250,7 +238,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCUserProperty() {
public void testUserProperty() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user property", false, null);
@ -260,7 +248,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user property");
ProtocolMapperRepresentation found = findClientMapperByName(id, "user property");
assertEquals("oidc-usermodel-property-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
@ -268,7 +256,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCGroupMembership() {
public void testGroupMembership() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("group membership", false, null);
@ -278,7 +266,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("group membership");
ProtocolMapperRepresentation found = findClientMapperByName(id, "group membership");
assertEquals("oidc-group-membership-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
@ -286,7 +274,7 @@ public class ClientMappersTest extends AbstractClientTest {
}
@Test
public void testOIDCEditMapper() {
public void testEditMapper() {
//prepare data
ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation();
mapper.setName("mapper name");
@ -309,7 +297,7 @@ public class ClientMappersTest extends AbstractClientTest {
//check form
clientMapperPage.setId(id);
String mapperId = findClientMapperByName("mapper name").getId();
String mapperId = findClientMapperByName(id, "mapper name").getId();
clientMapperPage.setMapperId(mapperId);
clientMapperPage.navigateTo();
@ -331,7 +319,7 @@ public class ClientMappersTest extends AbstractClientTest {
assertFlashMessageSuccess();
//check
assertFalse(findClientMapperByName("mapper name").isConsentRequired());
assertFalse(findClientMapperByName(id, "mapper name").isConsentRequired());
}
@Test

View file

@ -0,0 +1,212 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.testsuite.console.clients;
import java.util.Map;
import org.jboss.arquillian.graphene.page.Page;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import org.keycloak.testsuite.console.page.clients.mappers.ClientMapper;
import org.keycloak.testsuite.console.page.clients.mappers.ClientMappers;
import org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappers;
import static org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappersForm.*;
/**
*
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class ClientMappersSAMLTest extends AbstractClientTest {
private String id;
@Page
private ClientMappers clientMappersPage;
@Page
private ClientMapper clientMapperPage;
@Page
private CreateClientMappers createClientMappersPage;
@Before
public void beforeClientMappersTest() {
ClientRepresentation newClient = createSamlClientRep(TEST_CLIENT_ID);
testRealmResource().clients().create(newClient).close();
id = findClientByClientId(TEST_CLIENT_ID).getId();
clientMappersPage.setId(id);
clientMappersPage.navigateTo();
}
private void setInitialValues(String name, boolean consentRequired, String consentText) {
createClientMappersPage.form().setName(name);
createClientMappersPage.form().setConsentRequired(consentRequired);
if (consentRequired) {
createClientMappersPage.form().setConsentText(consentText);
}
}
@Test
public void testRoleName() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("role name", false, null);
createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER);
createClientMappersPage.form().setRole("offline_access");
createClientMappersPage.form().setNewRole("new role");
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "role name");
assertEquals("saml-role-name-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("offline_access", config.get("role"));
assertEquals("new role", config.get("new.role.name"));
}
@Test
public void testRoleList() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("new role list", false, null);
createClientMappersPage.form().setMapperType(ROLE_LIST);
createClientMappersPage.form().setRoleAttributeName("role attribute name");
createClientMappersPage.form().setFriendlyName("friendly name");
createClientMappersPage.form().setSamlAttributeNameFormat("URI Reference");
createClientMappersPage.form().setSingleRoleAttribute(true);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "new role list");
assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-role-list-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("role attribute name", config.get("attribute.name"));
assertEquals("URI Reference", config.get("attribute.nameformat"));
assertEquals("friendly name", config.get("friendly.name"));
assertEquals("true", config.get("single"));
}
@Test
public void testUserProperty() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user property", false, null);
createClientMappersPage.form().setMapperType(USER_PROPERTY);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "user property");
assertEquals("saml-user-property-mapper", found.getProtocolMapper());
}
@Test
public void testUserSessionNote() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user session note", false, null);
createClientMappersPage.form().setMapperType(USER_SESSION_NOTE);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "user session note");
assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-user-session-note-mapper", found.getProtocolMapper());
}
@Test
public void testHardcodedAttribute() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded attribute", false, null);
createClientMappersPage.form().setMapperType(HARDCODED_ATTRIBUTE);
createClientMappersPage.form().setAttributeValue("attribute value");
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded attribute");
assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("saml-hardcode-attribute-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("attribute value", config.get("attribute.value"));
}
@Test
public void testGroupList() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("group list", false, null);
createClientMappersPage.form().setMapperType(GROUP_LIST);
createClientMappersPage.form().setGroupAttributeName("group attribute name");
createClientMappersPage.form().setSingleGroupAttribute(true);
createClientMappersPage.form().setFullGroupPath(true);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "group list");
assertEquals("saml-group-membership-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("true", config.get("full.path"));
assertEquals("true", config.get("single"));
assertEquals("group attribute name", config.get("attribute.name"));
}
@Test
public void testHardcodedRole() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role", false, null);
createClientMappersPage.form().setMapperType(HARDCODED_ROLE_SAML);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded role");
assertNotNull(found);
assertEquals("saml-hardcode-role-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals(1, config.size());
assertEquals("offline_access", config.get("role"));
}
}

View file

@ -18,9 +18,7 @@
package org.keycloak.testsuite.console.clients;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*;
@ -28,10 +26,8 @@ import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.admin.ApiUtil.getCreatedId;
import static org.keycloak.testsuite.auth.page.login.Login.SAML;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.*;
import org.keycloak.testsuite.console.page.clients.settings.ClientSettings;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.*;
import static org.keycloak.testsuite.util.WaitUtils.pause;
import org.keycloak.testsuite.util.Timer;
@ -132,7 +128,7 @@ public class ClientSettingsTest extends AbstractClientTest {
@Test
public void createSAML() {
newClient = createSamlClientRep("saml", getSAMLAttributes());
newClient = createSamlClientRep("saml");
createClient(newClient);
assertFlashMessageSuccess();
@ -186,24 +182,4 @@ public class ClientSettingsTest extends AbstractClientTest {
clientsPage.navigateTo();
pause(120000);
}
private Map<String, String> getSAMLAttributes() {
Map<String, String> attributes = new HashMap<>();
attributes.put(SAML_ASSERTION_SIGNATURE, "true");
attributes.put(SAML_AUTHNSTATEMENT, "false");
attributes.put(SAML_CLIENT_SIGNATURE, "true");
attributes.put(SAML_ENCRYPT, "true");
attributes.put(SAML_FORCE_POST_BINDING, "true");
attributes.put(SAML_MULTIVALUED_ROLES, "false");
attributes.put(SAML_SERVER_SIGNATURE, "true");
attributes.put(SAML_SIGNATURE_ALGORITHM, "RSA_SHA512");
attributes.put(SAML_ASSERTION_CONSUMER_URL_POST, "http://example0.test");
attributes.put(SAML_ASSERTION_CONSUMER_URL_REDIRECT, "http://example1.test");
attributes.put(SAML_FORCE_NAME_ID_FORMAT, "true");
attributes.put(SAML_NAME_ID_FORMAT, "email");
attributes.put(SAML_SIGNATURE_CANONICALIZATION_METHOD, "http://www.w3.org/2001/10/xml-exc-c14n#WithComments");
attributes.put(SAML_SINGLE_LOGOUT_SERVICE_URL_POST, "http://example2.test");
attributes.put(SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT, "http://example3.test");
return attributes;
}
}