KEYCLOAK-2414 Fix ClientSettingsTest

This commit is contained in:
Vaclav Muzikar 2016-01-29 18:18:51 +01:00
parent 41551e08b0
commit b930ef4b1b
4 changed files with 178 additions and 169 deletions

View file

@ -25,24 +25,6 @@ public class CreateClientForm extends Form {
@FindBy(id = "clientId")
private WebElement clientIdInput;
@FindBy(id = "name")
private WebElement nameInput;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='enabled']]")
private OnOffSwitch enabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='consentRequired']]")
private OnOffSwitch consentRequiredSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='standardFlowEnabled']]")
private OnOffSwitch standardFlowEnabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='implicitFlowEnabled']]")
private OnOffSwitch implicitFlowEnabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='directAccessGrantsEnabled']]")
private OnOffSwitch directAccessGrantsEnabledSwitch;
@FindBy(id = "protocol")
private Select protocolSelect;
@ -53,43 +35,11 @@ public class CreateClientForm extends Form {
return samlForm;
}
@FindBy(id = "accessType")
private Select accessTypeSelect;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='serviceAccountsEnabled']]")
private OnOffSwitch serviceAccountsEnabledSwitch;
@FindBy(id = "newRedirectUri")
private WebElement newRedirectUriInput;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'newRedirectUri')]")
private WebElement newRedirectUriSubmit;
@FindBy(xpath = ".//input[@ng-model='client.redirectUris[i]']")
private List<WebElement> redirectUriInputs;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteRedirectUri')]")
private List<WebElement> deleteRedirectUriIcons;
public void setValues(ClientRepresentation client) {
waitUntilElement(clientIdInput).is().present();
setClientId(client.getClientId());
setName(client.getName());
setEnabled(client.isEnabled());
setConsentRequired(client.isConsentRequired());
setProtocol(client.getProtocol());
if (OIDC.equals(client.getProtocol())) {
setAccessType(client);
if (!client.isBearerOnly()) {
setStandardFlowEnabled(client.isStandardFlowEnabled());
setDirectAccessGrantsEnabled(client.isDirectAccessGrantsEnabled());
if (client.isPublicClient()) {
setImplicitFlowEnabled(client.isImplicitFlowEnabled());
} else {//confidential
setServiceAccountsEnabled(client.isServiceAccountsEnabled());
}
if (client.isStandardFlowEnabled() || client.isImplicitFlowEnabled()) {
setRedirectUris(client.getRedirectUris());
}
}
}
}
public String getClientId() {
@ -100,22 +50,6 @@ public class CreateClientForm extends Form {
setInputValue(clientIdInput, clientId);
}
public String getName() {
return getInputValue(nameInput);
}
public void setName(String name) {
setInputValue(nameInput, name);
}
public boolean isEnabled() {
return enabledSwitch.isOn();
}
public void setEnabled(boolean enabled) {
enabledSwitch.setOn(enabled);
}
public enum OidcAccessType {
BEARER_ONLY("bearer-only"),
PUBLIC("public"),
@ -131,77 +65,6 @@ public class CreateClientForm extends Form {
return name;
}
}
public void setAccessType(ClientRepresentation client) {
if (client.isBearerOnly()) {
accessTypeSelect.selectByVisibleText(BEARER_ONLY.getName());
} else if (client.isPublicClient()) {
accessTypeSelect.selectByVisibleText(PUBLIC.getName());
} else {
accessTypeSelect.selectByVisibleText(CONFIDENTIAL.getName());
}
}
public void addRedirectUri(String redirectUri) {
newRedirectUriInput.sendKeys(redirectUri);
newRedirectUriSubmit.click();
}
public List<String> getRedirectUris() {
List<String> values = new ArrayList<>();
for (WebElement input : redirectUriInputs) {
values.add(getInputValue(input));
}
return values;
}
public void setRedirectUris(List<String> redirectUris) {
Timer.time();
while (!deleteRedirectUriIcons.isEmpty()) {
deleteRedirectUriIcons.get(0).click();
pause(100);
}
Timer.time("deleteRedirectUris");
if (redirectUris != null) {
for (String redirectUri : redirectUris) {
addRedirectUri(redirectUri);
pause(100);
}
}
Timer.time("addRedirectUris");
}
public boolean isConsentRequired() {
return consentRequiredSwitch.isOn();
}
public void setConsentRequired(boolean consentRequired) {
consentRequiredSwitch.setOn(consentRequired);
}
public boolean isStandardFlowEnabled() {
return standardFlowEnabledSwitch.isOn();
}
public void setStandardFlowEnabled(boolean standardFlowEnabled) {
standardFlowEnabledSwitch.setOn(standardFlowEnabled);
}
public boolean isImplicitFlowEnabled() {
return implicitFlowEnabledSwitch.isOn();
}
public void setImplicitFlowEnabled(boolean implicitFlowEnabled) {
implicitFlowEnabledSwitch.setOn(implicitFlowEnabled);
}
public boolean isDirectAccessGrantsEnabled() {
return directAccessGrantsEnabledSwitch.isOn();
}
public void setDirectAccessGrantsEnabled(boolean directAccessGrantsEnabled) {
directAccessGrantsEnabledSwitch.setOn(directAccessGrantsEnabled);
}
public String getProtocol() {
waitUntilElement(protocolSelect.getFirstSelectedOption()).is().present();
@ -214,14 +77,6 @@ public class CreateClientForm extends Form {
Timer.time("clientSettings.setProtocol()");
}
public boolean isServiceAccountsEnabled() {
return serviceAccountsEnabledSwitch.isOn();
}
public void setServiceAccountsEnabled(boolean serviceAccountsEnabled) {
serviceAccountsEnabledSwitch.setOn(serviceAccountsEnabled);
}
public class SAMLClientSettingsForm extends Form {
public static final String SAML_ASSERTION_SIGNATURE = "saml.assertion.signature";

View file

@ -2,14 +2,19 @@ package org.keycloak.testsuite.console.page.clients.settings;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.keycloak.testsuite.util.Timer;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.ArrayList;
import java.util.List;
import org.keycloak.testsuite.console.page.clients.CreateClientForm;
import org.openqa.selenium.support.ui.Select;
import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.BEARER_ONLY;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.PUBLIC;
import static org.keycloak.testsuite.util.WaitUtils.pause;
/**
@ -17,11 +22,43 @@ import static org.keycloak.testsuite.util.WaitUtils.pause;
*/
public class ClientSettingsForm extends CreateClientForm {
@FindBy(id = "name")
private WebElement nameInput;
@FindBy(id = "baseUrl")
private WebElement baseUrlInput;
@FindBy(id = "adminUrl")
private WebElement adminUrlInput;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='enabled']]")
private OnOffSwitch enabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='consentRequired']]")
private OnOffSwitch consentRequiredSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='standardFlowEnabled']]")
private OnOffSwitch standardFlowEnabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='implicitFlowEnabled']]")
private OnOffSwitch implicitFlowEnabledSwitch;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='directAccessGrantsEnabled']]")
private OnOffSwitch directAccessGrantsEnabledSwitch;
@FindBy(id = "accessType")
private Select accessTypeSelect;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='serviceAccountsEnabled']]")
private OnOffSwitch serviceAccountsEnabledSwitch;
@FindBy(id = "newRedirectUri")
private WebElement newRedirectUriInput;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'newRedirectUri')]")
private WebElement newRedirectUriSubmit;
@FindBy(xpath = ".//input[@ng-model='client.redirectUris[i]']")
private List<WebElement> redirectUriInputs;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteRedirectUri')]")
private List<WebElement> deleteRedirectUriIcons;
@FindBy(id = "newWebOrigin")
private WebElement newWebOriginInput;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'newWebOrigin')]")
@ -79,16 +116,122 @@ public class ClientSettingsForm extends CreateClientForm {
@Override
public void setValues(ClientRepresentation client) {
super.setValues(client);
setName(client.getName());
setEnabled(client.isEnabled());
setConsentRequired(client.isConsentRequired());
setBaseUrl(client.getBaseUrl());
if (OIDC.equals(client.getProtocol())) {
setAccessType(client);
if (!client.isBearerOnly()) {
setStandardFlowEnabled(client.isStandardFlowEnabled());
setDirectAccessGrantsEnabled(client.isDirectAccessGrantsEnabled());
if (client.isPublicClient()) {
setImplicitFlowEnabled(client.isImplicitFlowEnabled());
} else {//confidential
setServiceAccountsEnabled(client.isServiceAccountsEnabled());
}
if (client.isStandardFlowEnabled() || client.isImplicitFlowEnabled()) {
setRedirectUris(client.getRedirectUris());
}
}
setAdminUrl(client.getAdminUrl());
setWebOrigins(client.getWebOrigins());
}
}
@Override
public void setConsentRequired(boolean value) {
consentRequired.setOn(value);
public String getName() {
return getInputValue(nameInput);
}
public void setName(String name) {
setInputValue(nameInput, name);
}
public boolean isEnabled() {
return enabledSwitch.isOn();
}
public void setEnabled(boolean enabled) {
enabledSwitch.setOn(enabled);
}
public boolean isConsentRequired() {
return consentRequiredSwitch.isOn();
}
public void setConsentRequired(boolean consentRequired) {
consentRequiredSwitch.setOn(consentRequired);
}
public void setAccessType(ClientRepresentation client) {
if (client.isBearerOnly()) {
accessTypeSelect.selectByVisibleText(BEARER_ONLY.getName());
} else if (client.isPublicClient()) {
accessTypeSelect.selectByVisibleText(PUBLIC.getName());
} else {
accessTypeSelect.selectByVisibleText(CONFIDENTIAL.getName());
}
}
public void addRedirectUri(String redirectUri) {
newRedirectUriInput.sendKeys(redirectUri);
newRedirectUriSubmit.click();
}
public List<String> getRedirectUris() {
List<String> values = new ArrayList<>();
for (WebElement input : redirectUriInputs) {
values.add(getInputValue(input));
}
return values;
}
public void setRedirectUris(List<String> redirectUris) {
Timer.time();
while (!deleteRedirectUriIcons.isEmpty()) {
deleteRedirectUriIcons.get(0).click();
pause(100);
}
Timer.time("deleteRedirectUris");
if (redirectUris != null) {
for (String redirectUri : redirectUris) {
addRedirectUri(redirectUri);
pause(100);
}
}
Timer.time("addRedirectUris");
}
public boolean isStandardFlowEnabled() {
return standardFlowEnabledSwitch.isOn();
}
public void setStandardFlowEnabled(boolean standardFlowEnabled) {
standardFlowEnabledSwitch.setOn(standardFlowEnabled);
}
public boolean isImplicitFlowEnabled() {
return implicitFlowEnabledSwitch.isOn();
}
public void setImplicitFlowEnabled(boolean implicitFlowEnabled) {
implicitFlowEnabledSwitch.setOn(implicitFlowEnabled);
}
public boolean isDirectAccessGrantsEnabled() {
return directAccessGrantsEnabledSwitch.isOn();
}
public void setDirectAccessGrantsEnabled(boolean directAccessGrantsEnabled) {
directAccessGrantsEnabledSwitch.setOn(directAccessGrantsEnabled);
}
public boolean isServiceAccountsEnabled() {
return serviceAccountsEnabledSwitch.isOn();
}
public void setServiceAccountsEnabled(boolean serviceAccountsEnabled) {
serviceAccountsEnabledSwitch.setOn(serviceAccountsEnabled);
}
}

View file

@ -17,6 +17,10 @@ import org.keycloak.testsuite.console.page.clients.Client;
import org.keycloak.testsuite.console.page.clients.Clients;
import org.keycloak.testsuite.console.page.clients.CreateClient;
import org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType;
import org.keycloak.testsuite.console.page.clients.settings.ClientSettings;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.*;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_ASSERTION_CONSUMER_URL_POST;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_ASSERTION_CONSUMER_URL_REDIRECT;
@ -53,6 +57,8 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
protected Client clientPage; // note: cannot call navigateTo() unless client id is set
@Page
protected CreateClient createClientPage;
@Page
protected ClientSettings clientSettingsPage;
@Before
public void beforeClientTest() {
@ -61,13 +67,17 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
}
public void createClient(ClientRepresentation client) {
WaitUtils.waitUntilElement(By.tagName("body"));
assertCurrentUrlEquals(clientsPage);
clientsPage.table().createClient();
createClientPage.form().setValues(client);
createClientPage.form().save();
clientSettingsPage.form().setValues(client);
if (SAML.equals(client.getProtocol())) {
createClientPage.form().samlForm().setValues(client);
}
createClientPage.form().save();
clientSettingsPage.form().save();
}
private static ClientRepresentation createClientRep(String clientId) {
@ -149,21 +159,25 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
assertEqualsStringAttributes(c1.getClientId(), c2.getClientId());
assertEqualsStringAttributes(c1.getName(), c2.getName());
assertEqualsBooleanAttributes(c1.isEnabled(), c2.isEnabled());
assertEqualsBooleanAttributes(c1.isConsentRequired(), c2.isConsentRequired());
assertEqualsBooleanAttributes(c1.isDirectAccessGrantsEnabled(), c2.isDirectAccessGrantsEnabled());
assertEqualsStringAttributes(c1.getProtocol(), c2.getProtocol());
assertEqualsBooleanAttributes(c1.isBearerOnly(), c2.isBearerOnly());
assertEqualsBooleanAttributes(c1.isPublicClient(), c2.isPublicClient());
assertEqualsBooleanAttributes(c1.isSurrogateAuthRequired(), c2.isSurrogateAuthRequired());
assertEqualsBooleanAttributes(c1.isFrontchannelLogout(), c2.isFrontchannelLogout());
assertEqualsBooleanAttributes(c1.isServiceAccountsEnabled(), c2.isServiceAccountsEnabled());
assertEqualsListAttributes(c1.getRedirectUris(), c2.getRedirectUris());
assertEqualsStringAttributes(c1.getBaseUrl(), c2.getBaseUrl());
assertEqualsStringAttributes(c1.getAdminUrl(), c2.getAdminUrl());
assertEqualsListAttributes(c1.getWebOrigins(), c2.getWebOrigins());
assertEqualsBooleanAttributes(c1.isConsentRequired(), c2.isConsentRequired());
assertEqualsStringAttributes(c1.getProtocol(), c2.getProtocol());
assertEqualsListAttributes(c1.getRedirectUris(), c2.getRedirectUris());
if (c1.getProtocol().equals(OIDC)) {
assertEqualsBooleanAttributes(c1.isBearerOnly(), c2.isBearerOnly());
if (!c1.isBearerOnly()) {
assertEqualsBooleanAttributes(c1.isDirectAccessGrantsEnabled(), c2.isDirectAccessGrantsEnabled());
assertEqualsBooleanAttributes(c1.isPublicClient(), c2.isPublicClient());
assertEqualsListAttributes(c1.getWebOrigins(), c2.getWebOrigins());
assertEqualsStringAttributes(c1.getAdminUrl(), c2.getAdminUrl());
}
assertEqualsBooleanAttributes(c1.isSurrogateAuthRequired(), c2.isSurrogateAuthRequired());
assertEqualsBooleanAttributes(c1.isServiceAccountsEnabled(), c2.isServiceAccountsEnabled());
}
else if (c1.getProtocol().equals(SAML)) {
assertEqualsBooleanAttributes(c1.isFrontchannelLogout(), c2.isFrontchannelLogout());
}
}
public void assertClientSamlAttributes(Map<String, String> expected, Map<String, String> actual) {

View file

@ -49,7 +49,7 @@ public class ClientSettingsTest extends AbstractClientTest {
createClient(newClient);
assertAlertSuccess();
setExpectedWebOrigins(newClient);
//setExpectedWebOrigins(newClient);
// read & verify
ClientRepresentation found = findClientByClientId(newClient.getClientId());
@ -96,7 +96,7 @@ public class ClientSettingsTest extends AbstractClientTest {
createClient(newClient);
assertAlertSuccess();
setExpectedWebOrigins(newClient);
//setExpectedWebOrigins(newClient);
ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
@ -144,10 +144,6 @@ public class ClientSettingsTest extends AbstractClientTest {
clientsPage.table().createClient();
createClientPage.form().save();
assertAlertDanger();
createClientPage.form().setClientId("test-client");
createClientPage.form().save();
assertAlertDanger();
}
// @Test
@ -182,4 +178,5 @@ public class ClientSettingsTest extends AbstractClientTest {
clientsPage.navigateTo();
pause(120000);
}
}