keycloak-memoizeit
Changes
testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/clients/mappers/CreateClientMappersForm.java 53(+53 -0)
testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/OnOffSwitch.java 1(+0 -1)
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/AbstractClientTest.java 36(+33 -3)
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientMappersOIDCTest.java 60(+24 -36)
Details
diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/clients/mappers/CreateClientMappersForm.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/clients/mappers/CreateClientMappersForm.java
index 5d54800..ef533d2 100644
--- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/clients/mappers/CreateClientMappersForm.java
+++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/clients/mappers/CreateClientMappersForm.java
@@ -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);
+    }
 }
                diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/OnOffSwitch.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/OnOffSwitch.java
index 82eb0f6..950ea3d 100644
--- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/OnOffSwitch.java
+++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/OnOffSwitch.java
@@ -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;
                diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/AbstractClientTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/AbstractClientTest.java
index b53b74f..a3a1463 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/AbstractClientTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/AbstractClientTest.java
@@ -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;
+    }
 }
                diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientMappersSAMLTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientMappersSAMLTest.java
new file mode 100644
index 0000000..d3fe6f2
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientMappersSAMLTest.java
@@ -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"));
+    }
+}
                diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientSettingsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientSettingsTest.java
index 567a476..8d30b20 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientSettingsTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/console/clients/ClientSettingsTest.java
@@ -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;
-    }
 }