added UI tests for client mappers oidc

This commit is contained in:
vramik 2015-12-02 12:50:52 +01:00 committed by Vlasta Ramik
parent c4f3bd3dda
commit 2b25c120d4
17 changed files with 649 additions and 197 deletions

View file

@ -1,47 +0,0 @@
package org.keycloak.testsuite.console.page.clients;
import org.keycloak.testsuite.console.page.roles.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
*
* @author tkyjovsk
*/
public class ClientRole extends ClientRoles {
public static final String ROLE_ID = "roleId";
@FindBy(xpath = "//i[contains(@class, 'delete')]")
private WebElement deleteIcon;
@Override
public String getUriFragment() {
return super.getUriFragment() + "/{" + ROLE_ID + "}";
}
public void setRoleId(String id) {
setUriParameter(ROLE_ID, id);
}
public String getRoleId() {
return getUriParameter(ROLE_ID).toString();
}
private RoleForm form;
public RoleForm form() {
return form;
}
public void backToClientRolesViaBreadcrumb() {
breadcrumb().clickItemOneLevelUp();
}
@Override
public void delete() {
deleteIcon.click();
modalDialog.confirmDeletion();
}
}

View file

@ -1,29 +0,0 @@
package org.keycloak.testsuite.console.page.clients;
import org.keycloak.admin.client.resource.RolesResource;
import org.keycloak.testsuite.console.page.roles.RolesTable;
import org.openqa.selenium.support.FindBy;
/**
*
* @author tkyjovsk
*/
public class ClientRoles extends Client {
@Override
public String getUriFragment() {
return super.getUriFragment() + "/roles";
}
@FindBy(css = "table[class*='table']")
private RolesTable table;
public RolesTable roles() {
return table;
}
public RolesResource rolesResource() {
return clientResource().roles();
}
}

View file

@ -0,0 +1,63 @@
/*
* 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.page.clients.mappers;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
*
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class ClientMapper extends ClientMappers {
public static final String MAPPER_ID = "mapperId";
@FindBy(xpath = "//i[contains(@class, 'delete')]")
private WebElement deleteIcon;
@FindBy(tagName = "form")
private MapperSettingsForm form;
@Override
public String getUriFragment() {
return super.getUriFragment() + "/{" + MAPPER_ID + "}";
}
public void setMapperId(String id) {
setUriParameter(MAPPER_ID, id);
}
public String getMapperId() {
return getUriParameter(MAPPER_ID).toString();
}
@Override
public void delete() {
deleteIcon.click();
modalDialog.confirmDeletion();
}
public MapperSettingsForm form() {
return form;
}
}

View file

@ -1,4 +1,4 @@
package org.keycloak.testsuite.console.page.clients;
package org.keycloak.testsuite.console.page.clients.mappers;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import org.keycloak.testsuite.console.page.fragment.DataTable;
@ -8,6 +8,7 @@ import org.openqa.selenium.support.FindBy;
import java.util.ArrayList;
import java.util.List;
import org.keycloak.testsuite.console.page.clients.Client;
/**
*
@ -32,6 +33,9 @@ public class ClientMappers extends Client {
public class ClientMapperTable extends DataTable {
@FindBy(xpath = "//button[text() = 'Add selected']")
private WebElement addSelectedButton;
public List<ProtocolMapperRepresentation> searchMappings(String searchPattern) {
search(searchPattern);
return getMappingsFromRows();
@ -81,6 +85,14 @@ public class ClientMappers extends Client {
clickMapperActionButton(mapper, DELETE);
}
public void checkBuiltinMapper(String mapperName) {
body().findElement(By.xpath("//td[text() = '" + mapperName + "']/..//input")).click();
}
public void clickAddSelectedBuiltinMapper() {
addSelectedButton.click();
}
public ProtocolMapperRepresentation getMappingFromRow(WebElement row) {
if (!row.isDisplayed()) {return null;} // Is that necessary?
@ -96,7 +108,7 @@ public class ClientMappers extends Client {
}
public List<ProtocolMapperRepresentation> getMappingsFromRows() {
List<ProtocolMapperRepresentation> mappings = new ArrayList<ProtocolMapperRepresentation>();
List<ProtocolMapperRepresentation> mappings = new ArrayList<>();
for (WebElement row : rows()) {
ProtocolMapperRepresentation mapperRepresentation = getMappingFromRow(row);

View file

@ -1,4 +1,4 @@
package org.keycloak.testsuite.console.page.clients;
package org.keycloak.testsuite.console.page.clients.mappers;
import org.jboss.arquillian.graphene.page.Page;
import org.keycloak.testsuite.console.page.AdminConsoleCreate;

View file

@ -1,15 +1,11 @@
package org.keycloak.testsuite.console.page.clients;
package org.keycloak.testsuite.console.page.clients.mappers;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.keycloak.testsuite.page.Form;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
/**
* @author Vaclav Muzikar <vmuzikar@redhat.com>
@ -27,6 +23,11 @@ public class CreateClientMappersForm extends Form {
public static final String USERS_FULL_NAME = "User's full name";
public static final String USER_ATTRIBUTE = "User Attribute";
public static final String USER_PROPERTY = "User Property";
public static final String GROUP_MEMBERSHIP = "Group Membership";
// Role types
public static final String REALM_ROLE = "realm";
public static final String CLIENT_ROLE = "client";
@FindBy(id = "name")
private WebElement nameElement;
@ -52,7 +53,7 @@ public class CreateClientMappersForm extends Form {
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Multivalued']//following-sibling::node()//div[@class='onoffswitch']")
private OnOffSwitch multivaluedInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Role']//following-sibling::node()//input[@type='text']")
@FindBy(xpath = ".//button[text() = 'Select Role']/../..//input")
private WebElement roleInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='New Role Name']//following-sibling::node()//input[@type='text']")
@ -73,6 +74,73 @@ public class CreateClientMappersForm extends Form {
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Add to access token']//following-sibling::node()//div[@class='onoffswitch']")
private OnOffSwitch addToAccessTokenInput;
@FindBy(xpath = ".//div[@properties='mapperType.properties']//label[text()='Full group path']//following-sibling::node()//div[@class='onoffswitch']")
private OnOffSwitch fullGroupPath;
@FindBy(xpath = ".//button[text() = 'Select Role']")
private WebElement selectRoleButton;
@FindBy(xpath = "//div[@class='modal-dialog']")
private RoleSelectorModalDialog roleSelectorModalDialog;
public class RoleSelectorModalDialog {
@FindBy(id = "available")
private Select realmAvailable;
@FindBy(xpath = ".//button[@tooltip='Select realm role']")
private WebElement selectRealmRoleButton;
@FindBy(id = "available-client")
private Select clientAvailable;
@FindBy(id = "clients")
private Select clientSelect;
@FindBy(xpath = ".//button[@tooltip='Select client role']")
private WebElement selectClientRoleButton;
@FindBy(xpath = ".//button[@class='close']")
private WebElement closeButton;
public void closeRoleSelectorModalDialog() {
closeButton.click();
}
public void selectRealmRole(String roleName) {
if (roleName != null) {
realmAvailable.selectByVisibleText(roleName);
}
selectRealmRoleButton.click();
}
public void selectClientRole(String clientName, String roleName) {
if (roleName != null || clientName != null) {
clientSelect.selectByVisibleText(clientName);
clientAvailable.selectByVisibleText(roleName);
}
selectClientRoleButton.click();
}
}
public void selectRole(String roleType, String roleName, String clientName) {
selectRoleButton.click();
switch (roleType) {
case REALM_ROLE:
roleSelectorModalDialog.selectRealmRole(roleName);
break;
case CLIENT_ROLE:
roleSelectorModalDialog.selectClientRole(clientName, roleName);
break;
default:
throw new IllegalArgumentException("No such role type, use \"" +
REALM_ROLE + "\" or \"" + CLIENT_ROLE + "\"");
}
}
public void closeRoleSelectorModalDialog() {
roleSelectorModalDialog.closeRoleSelectorModalDialog();
}
public void setName(String value) {
setInputValue(nameElement, value);
}
public boolean isConsentRequired() {
return consentRequiredSwitch.isOn();
}
@ -89,10 +157,6 @@ public class CreateClientMappersForm extends Form {
setInputValue(consentTextElement, consentText);
}
public String getMapperType() {
return mapperTypeSelect.getFirstSelectedOption().getText();
}
public void setMapperType(String type) {
mapperTypeSelect.selectByVisibleText(type);
}
@ -184,4 +248,13 @@ public class CreateClientMappersForm extends Form {
public void setAddToAccessToken(boolean value) {
addToAccessTokenInput.setOn(value);
}
public boolean isFullGroupPath() {
return fullGroupPath.isOn();
}
public void setFullGroupPath(boolean value) {
fullGroupPath.setOn(value);
}
}

View file

@ -0,0 +1,56 @@
/*
* 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.page.clients.mappers;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class MapperSettingsForm extends CreateClientMappersForm {
@FindBy(id = "protocol")
private WebElement protocolInput;
@FindBy(id = "mapperId")
private WebElement mapperIdInput;
@FindBy(id = "name")
private WebElement nameInput;
@FindBy(id = "mapperType")
private WebElement mapperTypeInput;
public String getProtocol() {
return getInputValue(protocolInput);
}
public String getMapperId() {
return getInputValue(mapperIdInput);
}
public String getName() {
return getInputValue(nameInput);
}
public String getMapperType() {
return getInputValue(mapperTypeInput);
}
}

View file

@ -1,6 +1,8 @@
package org.keycloak.testsuite.console.page.clients.roles;
import org.keycloak.testsuite.console.page.roles.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
*
@ -10,6 +12,9 @@ public class ClientRole extends ClientRoles {
public static final String ROLE_ID = "roleId";
@FindBy(xpath = "//i[contains(@class, 'delete')]")
private WebElement deleteIcon;
@Override
public String getUriFragment() {
return super.getUriFragment() + "/{" + ROLE_ID + "}";
@ -33,4 +38,10 @@ public class ClientRole extends ClientRoles {
breadcrumb().clickItemOneLevelUp();
}
@Override
public void delete() {
deleteIcon.click();
modalDialog.confirmDeletion();
}
}

View file

@ -1,4 +1,4 @@
package org.keycloak.testsuite.console.page.clients;
package org.keycloak.testsuite.console.page.clients.roles;
import static org.keycloak.testsuite.console.page.clients.Client.ID;
import org.keycloak.testsuite.console.page.roles.CreateRole;

View file

@ -17,6 +17,7 @@
*/
package org.keycloak.testsuite.console.page.fragment;
import java.util.concurrent.TimeUnit;
import static org.jboss.arquillian.graphene.Graphene.waitGui;
import org.jboss.arquillian.graphene.fragment.Root;
@ -42,7 +43,9 @@ public class FlashMessage {
}
public boolean isSuccess() {
waitGui().until("Flash message should be success")
waitGui().withTimeout(SCRIPT_TIMEOUT, TimeUnit.MILLISECONDS)
.pollingEvery(POLLING_INTERVAL, TimeUnit.MILLISECONDS)
.until("Flash message should be success")
.element(root)
.attribute("class")
.contains("success");
@ -50,7 +53,9 @@ public class FlashMessage {
}
public boolean isError() {
waitGui().until("Flash message should be error")
waitGui().withTimeout(SCRIPT_TIMEOUT, TimeUnit.MILLISECONDS)
.pollingEvery(POLLING_INTERVAL, TimeUnit.MILLISECONDS)
.until("Flash message should be error")
.element(root)
.attribute("class")
.contains("error");
@ -58,7 +63,9 @@ public class FlashMessage {
}
public boolean isDanger() {
waitGui().until("Flash message should be danger")
waitGui().withTimeout(SCRIPT_TIMEOUT, TimeUnit.MILLISECONDS)
.pollingEvery(POLLING_INTERVAL, TimeUnit.MILLISECONDS)
.until("Flash message should be danger")
.element(root)
.attribute("class")
.contains("danger");

View file

@ -17,6 +17,8 @@ public class ModalDialog {
@FindBy(xpath = ".//button[@ng-click='ok()']")
private WebElement okButton;
@FindBy(id = "name")
private WebElement nameInput;
public void ok() {
waitAjaxForElement(okButton);
@ -33,4 +35,9 @@ public class ModalDialog {
cancelButton.click();
}
public void setName(String name) {
waitAjaxForElement(nameInput);
nameInput.clear();
nameInput.sendKeys(name);
}
}

View file

@ -80,7 +80,7 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
return client;
}
public ClientRepresentation findClientRepByClientId(String clientId) {
public ClientRepresentation findClientByClientId(String clientId) {
ClientRepresentation found = null;
for (ClientRepresentation clientRepresentation : testRealmResource().clients().findAll()) {
if (clientRepresentation.getClientId().equals(clientId)) {

View file

@ -49,7 +49,7 @@ public class ClientCredentialsTest extends AbstractClientTest {
newClient = createClientRepresentation(TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close();
ClientRepresentation found = findClientRepByClientId(TEST_CLIENT_ID);
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
assertNotNull("Client " + TEST_CLIENT_ID + " was not found.", found);
clientCredentials.setId(found.getId());
clientCredentials.navigateTo();

View file

@ -0,0 +1,389 @@
/*
* 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.HashMap;
import java.util.List;
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>
*
* TODO: saml mappers
*/
public class ClientMappersTest extends AbstractClientTest {
private String id;
@Page
private ClientMappers clientMappersPage;
@Page
private ClientMapper clientMapperPage;
@Page
private CreateClientMappers createClientMappersPage;
@Before
public void beforeClientMappersTest() {
ClientRepresentation newClient = createClientRepresentation(TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close();
id = findClientByClientId(TEST_CLIENT_ID).getId();
clientMappersPage.setId(id);
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);
if (consentRequired) {
createClientMappersPage.form().setConsentText(consentText);
}
}
@Test
public void testOIDCHardcodedRole() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role", true, "Consent Text");
createClientMappersPage.form().setMapperType(HARDCODED_ROLE);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("hardcoded role");
assertNotNull(found);
assertTrue(found.isConsentRequired());
assertEquals("Consent Text", found.getConsentText());
assertEquals("oidc-hardcoded-role-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals(1, config.size());
assertEquals("offline_access", config.get("role"));
//edit
createClientMappersPage.form().selectRole(CLIENT_ROLE, "view-profile", "account");
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
config = findClientMapperByName("hardcoded role").getConfig();
assertEquals("account.view-profile", config.get("role"));
//delete
clientMapperPage.setMapperId(found.getId());
clientMapperPage.delete();
assertFlashMessageSuccess();
//check
assertNull(findClientMapperByName("hardcoded role"));
}
@Test
public void testOIDCHardcodedClaim() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded claim", false, null);
createClientMappersPage.form().setMapperType(HARDCODED_CLAIM);
createClientMappersPage.form().setTokenClaimName("claim name");
createClientMappersPage.form().setTokenClaimValue("claim value");
createClientMappersPage.form().setClaimJSONType("long");
createClientMappersPage.form().setAddToIDToken(true);
createClientMappersPage.form().setAddToAccessToken(true);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("hardcoded claim");
assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("oidc-hardcoded-claim-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("true", config.get("id.token.claim"));
assertEquals("true", config.get("access.token.claim"));
assertEquals("claim name", config.get("claim.name"));
assertEquals("claim value", config.get("claim.value"));
assertEquals("long", config.get("jsonType.label"));
}
@Test
public void testOIDCUserSessionNote() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user session note", false, null);
createClientMappersPage.form().setMapperType(USER_SESSION_NOTE);
createClientMappersPage.form().setUserSessionNote("session note");
createClientMappersPage.form().setTokenClaimName("claim name");
createClientMappersPage.form().setClaimJSONType("int");
createClientMappersPage.form().setAddToIDToken(false);
createClientMappersPage.form().setAddToAccessToken(false);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user session note");
assertNotNull(found);
assertFalse(found.isConsentRequired());
assertEquals("oidc-usersessionmodel-note-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertNull(config.get("id.token.claim"));
assertNull(config.get("access.token.claim"));
assertEquals("claim name", config.get("claim.name"));
assertEquals("session note", config.get("user.session.note"));
assertEquals("int", config.get("jsonType.label"));
}
@Test
public void testOIDCRoleName() {
//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("role name");
assertEquals("oidc-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 testOIDCUserAddress() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user address", false, null);
createClientMappersPage.form().setMapperType(USERS_FULL_NAME);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user address");
assertEquals("oidc-full-name-mapper", found.getProtocolMapper());
}
@Test
public void testOIDCUserFullName() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user full name", false, null);
createClientMappersPage.form().setMapperType(USERS_FULL_NAME);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user full name");
assertEquals("oidc-full-name-mapper", found.getProtocolMapper());
}
@Test
public void testOIDCUserAttribute() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user attribute", false, null);
createClientMappersPage.form().setMapperType(USER_ATTRIBUTE);
createClientMappersPage.form().setUserAttribute("user attribute");
createClientMappersPage.form().setMultivalued(true);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user attribute");
assertEquals("oidc-usermodel-attribute-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("true", config.get("multivalued"));
assertEquals("user attribute", config.get("user.attribute"));
}
@Test
public void testOIDCUserProperty() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user property", false, null);
createClientMappersPage.form().setMapperType(USER_PROPERTY);
createClientMappersPage.form().setProperty("property");
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("user property");
assertEquals("oidc-usermodel-property-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("property", config.get("user.attribute"));
}
@Test
public void testOIDCGroupMembership() {
//create
clientMappersPage.mapperTable().createMapper();
setInitialValues("group membership", false, null);
createClientMappersPage.form().setMapperType(GROUP_MEMBERSHIP);
createClientMappersPage.form().setFullGroupPath(true);
createClientMappersPage.form().save();
assertFlashMessageSuccess();
//check
ProtocolMapperRepresentation found = findClientMapperByName("group membership");
assertEquals("oidc-group-membership-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("true", config.get("full.path"));
}
@Test
public void testOIDCEditMapper() {
//prepare data
ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation();
mapper.setName("mapper name");
mapper.setConsentRequired(true);
mapper.setConsentText("consent text");
mapper.setProtocol("openid-connect");
mapper.setProtocolMapper("oidc-usersessionmodel-note-mapper");
Map<String, String> config = new HashMap<>();
config.put("access.token.claim", "true");
config.put("id.token.claim", "true");
config.put("claim.name", "claim name");
config.put("jsonType.label", "String");
config.put("user.session.note", "session note");
mapper.setConfig(config);
//insert data
testRealmResource().clients().get(id).getProtocolMappers().createMapper(mapper).close();
//check form
clientMapperPage.setId(id);
String mapperId = findClientMapperByName("mapper name").getId();
clientMapperPage.setMapperId(mapperId);
clientMapperPage.navigateTo();
assertEquals("openid-connect", clientMapperPage.form().getProtocol());
assertEquals(mapperId, clientMapperPage.form().getMapperId());
assertEquals("mapper name", clientMapperPage.form().getName());
assertTrue(clientMapperPage.form().isConsentRequired());
assertEquals("consent text", clientMapperPage.form().getConsentText());
assertEquals("User Session Note", clientMapperPage.form().getMapperType());
assertEquals("session note", clientMapperPage.form().getUserSessionNote());
assertEquals("claim name", clientMapperPage.form().getTokenClaimName());
assertEquals("String", clientMapperPage.form().getClaimJSONType());
assertTrue(clientMapperPage.form().isAddToIDToken());
assertTrue(clientMapperPage.form().isAddToAccessToken());
//edit
clientMapperPage.form().setConsentRequired(false);
clientMapperPage.form().save();
assertFlashMessageSuccess();
//check
assertFalse(findClientMapperByName("mapper name").isConsentRequired());
}
@Test
public void testAddBuiltin() {
clientMappersPage.mapperTable().addBuiltin();
clientMappersPage.mapperTable().checkBuiltinMapper("locale");
clientMappersPage.mapperTable().clickAddSelectedBuiltinMapper();
assertFlashMessageSuccess();
assertTrue("Builtin mapper \"locale\" should be present.", isMapperPresent("locale"));
clientMappersPage.mapperTable().deleteMapper("locale");
modalDialog.confirmDeletion();
assertFlashMessageSuccess();
assertFalse("Builtin mapper \"locale\" should not be present.", isMapperPresent("locale"));
}
private boolean isMapperPresent(String name) {
List<ProtocolMapperRepresentation> mappers = testRealmResource().clients().get(id).getProtocolMappers().getMappers();
boolean found = false;
for (ProtocolMapperRepresentation mapper : mappers) {
if (name.equals(mapper.getName())) {
found = true;
}
}
return found;
}
@Test
public void testCreateMapperInvalidValues() {
//empty mapper type
clientMappersPage.mapperTable().createMapper();
createClientMappersPage.form().save();
assertFlashMessageDanger();
//empty name
createClientMappersPage.form().setMapperType(HARDCODED_ROLE);
createClientMappersPage.form().save();
assertFlashMessageDanger();
createClientMappersPage.form().setName("");
createClientMappersPage.form().save();
assertFlashMessageDanger();
createClientMappersPage.form().setName("name");
createClientMappersPage.form().setName("");
createClientMappersPage.form().save();
assertFlashMessageDanger();
//existing name
createClientMappersPage.form().setName("email");
createClientMappersPage.form().save();
assertFlashMessageDanger();
}
}

View file

@ -9,9 +9,9 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.testsuite.console.page.clients.ClientRole;
import org.keycloak.testsuite.console.page.clients.ClientRoles;
import org.keycloak.testsuite.console.page.clients.CreateClientRole;
import org.keycloak.testsuite.console.page.clients.roles.ClientRole;
import org.keycloak.testsuite.console.page.clients.roles.ClientRoles;
import org.keycloak.testsuite.console.page.clients.roles.CreateClientRole;
import org.keycloak.testsuite.console.page.users.User;
import org.keycloak.testsuite.util.URLAssert;
@ -41,7 +41,7 @@ public class ClientRolesTest extends AbstractClientTest {
ClientRepresentation newClient = createClientRepresentation(TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close();
id = findClientRepByClientId(TEST_CLIENT_ID).getId();
id = findClientByClientId(TEST_CLIENT_ID).getId();
clientPage.setId(id);
clientRolePage.setId(id);
clientRolesPage.setId(id);

View file

@ -53,7 +53,7 @@ public class ClientSettingsTest extends AbstractClientTest {
assertFlashMessageSuccess();
// read & verify
ClientRepresentation found = findClientRepByClientId(newClient.getClientId());
ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found);
@ -80,14 +80,14 @@ public class ClientSettingsTest extends AbstractClientTest {
clientSettingsPage.form().save();
assertFlashMessageSuccess();
found = findClientRepByClientId(newClient.getClientId());
found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found);
// delete
clientPage.delete();
assertFlashMessageSuccess();
found = findClientRepByClientId(newClient.getClientId());
found = findClientByClientId(newClient.getClientId());
assertNull("Deleted client " + newClient.getClientId() + " was found.", found);
}
@ -98,7 +98,7 @@ public class ClientSettingsTest extends AbstractClientTest {
createClient(newClient);
assertFlashMessageSuccess();
ClientRepresentation found = findClientRepByClientId(newClient.getClientId());
ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found);
}
@ -112,7 +112,7 @@ public class ClientSettingsTest extends AbstractClientTest {
createClient(newClient);
assertFlashMessageSuccess();
ClientRepresentation found = findClientRepByClientId(newClient.getClientId());
ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found);
}
@ -129,7 +129,7 @@ public class ClientSettingsTest extends AbstractClientTest {
createClient(newClient);
assertFlashMessageSuccess();
ClientRepresentation found = findClientRepByClientId(newClient.getClientId());
ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found);
assertClientSamlAttributes(getSAMLAttributes(), found.getAttributes());

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.console.clients;
import java.util.ArrayList;
import java.util.List;
import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*;
import org.junit.Before;
@ -30,8 +28,6 @@ import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.testsuite.console.page.clients.settings.ClientSettings;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
/**
*
@ -49,7 +45,7 @@ public class ClientsTest extends AbstractClientTest {
newClient = createClientRepresentation(TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close();
ClientRepresentation found = findClientRepByClientId(TEST_CLIENT_ID);
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
assertNotNull("Client " + TEST_CLIENT_ID + " was not found.", found);
clientSettingsPage.setId(found.getId());
}
@ -71,93 +67,7 @@ public class ClientsTest extends AbstractClientTest {
modalDialog.confirmDeletion();
assertFlashMessageSuccess();
ClientRepresentation found = findClientRepByClientId(TEST_CLIENT_ID);
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
assertNull("Deleted client " + TEST_CLIENT_ID + " was found.", found);
}
@Test
public void tabs() {
clientSettingsPage.navigateTo();
//oidc-confidential
WebElement tabs = clientPage.tabs().getTabs();
List<String> visibleTabs = new ArrayList<>();
visibleTabs.add("Settings");
visibleTabs.add("Credentials");
visibleTabs.add("Roles");
visibleTabs.add("Mappers");
visibleTabs.add("Scope");
visibleTabs.add("Revocation");
visibleTabs.add("Sessions");
visibleTabs.add("Offline Access");
visibleTabs.add("Clustering");
visibleTabs.add("Installation");
List<String> invisibleTabs = new ArrayList<>();
invisibleTabs.add("SAML Keys");
invisibleTabs.add("Service Account Roles");
assertVisibilityOfTabs(tabs, visibleTabs, invisibleTabs);
//oidc-public
newClient.setPublicClient(true);
clientSettingsPage.form().setAccessType(newClient);
clientSettingsPage.form().save();
assertFlashMessageSuccess();
tabs = clientPage.tabs().getTabs();
visibleTabs.clear();
invisibleTabs.clear();
visibleTabs.add("Settings");
visibleTabs.add("Roles");
visibleTabs.add("Mappers");
visibleTabs.add("Scope");
visibleTabs.add("Revocation");
visibleTabs.add("Sessions");
visibleTabs.add("Offline Access");
visibleTabs.add("Installation");
invisibleTabs.add("Credentials");
invisibleTabs.add("SAML Keys");
invisibleTabs.add("Clustering");
invisibleTabs.add("Service Account Roles");
assertVisibilityOfTabs(tabs, visibleTabs, invisibleTabs);
//oidc-bearer-only
newClient.setPublicClient(false);
newClient.setBearerOnly(true);
clientSettingsPage.form().setAccessType(newClient);
clientSettingsPage.form().save();
assertFlashMessageSuccess();
tabs = clientPage.tabs().getTabs();
visibleTabs.clear();
invisibleTabs.clear();
visibleTabs.add("Settings");
visibleTabs.add("Credentials");
visibleTabs.add("Roles");
visibleTabs.add("Revocation");
visibleTabs.add("Clustering");
visibleTabs.add("Installation");
invisibleTabs.add("SAML Keys");
invisibleTabs.add("Mappers");
invisibleTabs.add("Scope");
invisibleTabs.add("Sessions");
invisibleTabs.add("Service Account Roles");
assertVisibilityOfTabs(tabs, visibleTabs, invisibleTabs);
}
private void assertVisibilityOfTabs(WebElement tabs, List<String> visible, List<String> invisible) {
for (String visibleLink : visible) {
assertTrue(tabs.findElement(By.linkText(visibleLink)).isDisplayed());
}
for (String invisibleLink : invisible) {
assertTrue(tabs.findElements(By.linkText(invisibleLink)).isEmpty());
}
}
}