Merge pull request #2405 from vramik/KEYCLOAK-2676

KEYCLOAK-2676 - Review clients tests
This commit is contained in:
Stian Thorgersen 2016-03-24 08:17:27 +00:00
commit 5181e95776
18 changed files with 271 additions and 360 deletions

View file

@ -17,7 +17,6 @@
package org.keycloak.testsuite.console.page.fragment; package org.keycloak.testsuite.console.page.fragment;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
@ -90,7 +89,7 @@ public class DataTable {
} }
public void clickRowActionButton(WebElement row, String buttonText) { public void clickRowActionButton(WebElement row, String buttonText) {
row.findElement(xpath(".//button[text()='" + buttonText + "']")).click(); row.findElement(xpath(".//td[contains(@class, 'kc-action-cell') and text()='" + buttonText + "']")).click();
} }
} }

View file

@ -18,6 +18,9 @@
package org.keycloak.testsuite.console.page.fragment; package org.keycloak.testsuite.console.page.fragment;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
import org.jboss.arquillian.graphene.fragment.Root;
import static org.keycloak.testsuite.util.WaitUtils.pause;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
@ -27,6 +30,9 @@ import org.openqa.selenium.support.FindBy;
*/ */
public class ModalDialog { public class ModalDialog {
@Root
private WebElement root;
@FindBy(xpath = ".//button[text()='Cancel']") @FindBy(xpath = ".//button[text()='Cancel']")
private WebElement cancelButton; private WebElement cancelButton;
@FindBy(xpath = ".//button[text()='Delete']") @FindBy(xpath = ".//button[text()='Delete']")
@ -40,16 +46,20 @@ public class ModalDialog {
public void ok() { public void ok() {
waitUntilElement(okButton).is().present(); waitUntilElement(okButton).is().present();
okButton.click(); okButton.click();
waitUntilElement(root).is().not().present();
} }
public void confirmDeletion() { public void confirmDeletion() {
waitUntilElement(deleteButton).is().present(); waitUntilElement(deleteButton).is().present();
deleteButton.click(); deleteButton.click();
waitUntilElement(root).is().not().present();
pause(100);
} }
public void cancel() { public void cancel() {
waitUntilElement(cancelButton).is().present(); waitUntilElement(cancelButton).is().present();
cancelButton.click(); cancelButton.click();
waitUntilElement(root).is().not().present();
} }
public void setName(String name) { public void setName(String name) {
@ -57,4 +67,4 @@ public class ModalDialog {
nameInput.clear(); nameInput.clear();
nameInput.sendKeys(name); nameInput.sendKeys(name);
} }
} }

View file

@ -1,13 +1,6 @@
package org.keycloak.testsuite.console.page.clients; package org.keycloak.testsuite.console.page.clients;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.jboss.arquillian.graphene.page.Page;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.auth.page.login.OIDCLogin.OIDC;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.*;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.page.Form;
import static org.keycloak.testsuite.page.Form.getInputValue; import static org.keycloak.testsuite.page.Form.getInputValue;
import static org.keycloak.testsuite.util.WaitUtils.*; import static org.keycloak.testsuite.util.WaitUtils.*;
@ -28,13 +21,6 @@ public class CreateClientForm extends Form {
@FindBy(id = "protocol") @FindBy(id = "protocol")
private Select protocolSelect; private Select protocolSelect;
@Page
private SAMLClientSettingsForm samlForm;
public SAMLClientSettingsForm samlForm() {
return samlForm;
}
public void setValues(ClientRepresentation client) { public void setValues(ClientRepresentation client) {
waitUntilElement(clientIdInput).is().present(); waitUntilElement(clientIdInput).is().present();
@ -50,22 +36,6 @@ public class CreateClientForm extends Form {
setInputValue(clientIdInput, clientId); setInputValue(clientIdInput, clientId);
} }
public enum OidcAccessType {
BEARER_ONLY("bearer-only"),
PUBLIC("public"),
CONFIDENTIAL("confidential");
private final String name;
private OidcAccessType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public String getProtocol() { public String getProtocol() {
waitUntilElement(protocolSelect.getFirstSelectedOption()).is().present(); waitUntilElement(protocolSelect.getFirstSelectedOption()).is().present();
return protocolSelect.getFirstSelectedOption().getText(); return protocolSelect.getFirstSelectedOption().getText();
@ -76,86 +46,4 @@ public class CreateClientForm extends Form {
protocolSelect.selectByVisibleText(protocol); protocolSelect.selectByVisibleText(protocol);
Timer.DEFAULT.reset("clientSettings.setProtocol()"); Timer.DEFAULT.reset("clientSettings.setProtocol()");
} }
}
public class SAMLClientSettingsForm extends Form {
public static final String SAML_ASSERTION_SIGNATURE = "saml.assertion.signature";
public static final String SAML_AUTHNSTATEMENT = "saml.authnstatement";
public static final String SAML_CLIENT_SIGNATURE = "saml.client.signature";
public static final String SAML_ENCRYPT = "saml.encrypt";
public static final String SAML_FORCE_POST_BINDING = "saml.force.post.binding";
public static final String SAML_MULTIVALUED_ROLES = "saml.multivalued.roles";
public static final String SAML_SERVER_SIGNATURE = "saml.server.signature";
public static final String SAML_SIGNATURE_ALGORITHM = "saml.signature.algorithm";
public static final String SAML_ASSERTION_CONSUMER_URL_POST = "saml_assertion_consumer_url_post";
public static final String SAML_ASSERTION_CONSUMER_URL_REDIRECT = "saml_assertion_consumer_url_redirect";
public static final String SAML_FORCE_NAME_ID_FORMAT = "saml_force_name_id_format";
public static final String SAML_NAME_ID_FORMAT = "saml_name_id_format";
public static final String SAML_SIGNATURE_CANONICALIZATION_METHOD = "saml_signature_canonicalization_method";
public static final String SAML_SINGLE_LOGOUT_SERVICE_URL_POST = "saml_single_logout_service_url_post";
public static final String SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT = "saml_single_logout_service_url_redirect";
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlAuthnStatement']]")
private OnOffSwitch samlAuthnStatement;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlServerSignature']]")
private OnOffSwitch samlServerSignature;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlAssertionSignature']]")
private OnOffSwitch samlAssertionSignature;
@FindBy(id = "signatureAlgorithm")
private Select signatureAlgorithm;
@FindBy(id = "canonicalization")
private Select canonicalization;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlEncrypt']]")
private OnOffSwitch samlEncrypt;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlClientSignature']]")
private OnOffSwitch samlClientSignature;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlForcePostBinding']]")
private OnOffSwitch samlForcePostBinding;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='frontchannelLogout']]")
private OnOffSwitch frontchannelLogout;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlForceNameIdFormat']]")
private OnOffSwitch samlForceNameIdFormat;
@FindBy(id = "samlNameIdFormat")
private Select samlNameIdFormat;
@FindBy(xpath = "//fieldset[contains(@data-ng-show, 'saml')]//i")
private WebElement fineGrainCollapsor;
@FindBy(id = "consumerServicePost")
private WebElement consumerServicePostInput;
@FindBy(id = "consumerServiceRedirect")
private WebElement consumerServiceRedirectInput;
@FindBy(id = "logoutPostBinding")
private WebElement logoutPostBindingInput;
@FindBy(id = "logoutRedirectBinding")
private WebElement logoutRedirectBindingInput;
public void setValues(ClientRepresentation client) {
waitUntilElement(fineGrainCollapsor).is().visible();
Map<String, String> attributes = client.getAttributes();
samlAuthnStatement.setOn("true".equals(attributes.get(SAML_AUTHNSTATEMENT)));
samlServerSignature.setOn("true".equals(attributes.get(SAML_SERVER_SIGNATURE)));
samlAssertionSignature.setOn("true".equals(attributes.get(SAML_ASSERTION_SIGNATURE)));
if (samlServerSignature.isOn() || samlAssertionSignature.isOn()) {
signatureAlgorithm.selectByVisibleText(attributes.get(SAML_SIGNATURE_ALGORITHM));
canonicalization.selectByValue("string:" + attributes.get(SAML_SIGNATURE_CANONICALIZATION_METHOD));
}
samlEncrypt.setOn("true".equals(attributes.get(SAML_ENCRYPT)));
samlClientSignature.setOn("true".equals(attributes.get(SAML_CLIENT_SIGNATURE)));
samlForcePostBinding.setOn("true".equals(attributes.get(SAML_FORCE_POST_BINDING)));
frontchannelLogout.setOn(client.isFrontchannelLogout());
samlForceNameIdFormat.setOn("true".equals(attributes.get(SAML_FORCE_NAME_ID_FORMAT)));
samlNameIdFormat.selectByVisibleText(attributes.get(SAML_NAME_ID_FORMAT));
fineGrainCollapsor.click();
waitUntilElement(consumerServicePostInput).is().present();
setInputValue(consumerServicePostInput, attributes.get(SAML_ASSERTION_CONSUMER_URL_POST));
setInputValue(consumerServiceRedirectInput, attributes.get(SAML_ASSERTION_CONSUMER_URL_REDIRECT));
setInputValue(logoutPostBindingInput, attributes.get(SAML_SINGLE_LOGOUT_SERVICE_URL_POST));
setInputValue(logoutRedirectBindingInput, attributes.get(SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT));
}
}
}

View file

@ -22,6 +22,7 @@
package org.keycloak.testsuite.console.page.clients.credentials; package org.keycloak.testsuite.console.page.clients.credentials;
import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.page.Form;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
@ -68,6 +69,7 @@ public class ClientCredentialsGeneratePrivateKeysForm extends Form {
} }
public void clickGenerateAndDownload() { public void clickGenerateAndDownload() {
waitUntilElement(generateAndDownloadButton).is().present();
generateAndDownloadButton.click(); generateAndDownloadButton.click();
} }
} }

View file

@ -2,6 +2,7 @@ package org.keycloak.testsuite.console.page.clients.mappers;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch; import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.page.Form;
import static org.keycloak.testsuite.util.WaitUtils.pause;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
@ -109,6 +110,7 @@ public class CreateClientMappersForm extends Form {
realmAvailable.selectByVisibleText(roleName); realmAvailable.selectByVisibleText(roleName);
} }
selectRealmRoleButton.click(); selectRealmRoleButton.click();
pause(500); // wait for the modal dialog to fade out
} }
public void selectClientRole(String clientName, String roleName) { public void selectClientRole(String clientName, String roleName) {
@ -117,6 +119,7 @@ public class CreateClientMappersForm extends Form {
clientAvailable.selectByVisibleText(roleName); clientAvailable.selectByVisibleText(roleName);
} }
selectClientRoleButton.click(); selectClientRoleButton.click();
pause(500); // wait for the modal dialog to fade out
} }
} }

View file

@ -8,14 +8,13 @@ import org.openqa.selenium.support.FindBy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.keycloak.testsuite.console.page.clients.CreateClientForm; import org.keycloak.testsuite.console.page.clients.CreateClientForm;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
import static org.keycloak.testsuite.auth.page.login.Login.OIDC; import org.keycloak.testsuite.page.Form;
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; import static org.keycloak.testsuite.util.WaitUtils.pause;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
/** /**
* @author tkyjovsk * @author tkyjovsk
@ -52,11 +51,11 @@ public class ClientSettingsForm extends CreateClientForm {
@FindBy(id = "newRedirectUri") @FindBy(id = "newRedirectUri")
private WebElement newRedirectUriInput; private WebElement newRedirectUriInput;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'newRedirectUri')]") @FindBy(xpath = ".//i[contains(@data-ng-click, 'newRedirectUri') and @class='fa fa-plus']")
private WebElement newRedirectUriSubmit; private WebElement newRedirectUriSubmit;
@FindBy(xpath = ".//input[@ng-model='client.redirectUris[i]']") @FindBy(xpath = ".//input[@ng-model='client.redirectUris[i]']")
private List<WebElement> redirectUriInputs; private List<WebElement> redirectUriInputs;
@FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteRedirectUri')]") @FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteRedirectUri') and @class='fa fa-minus']")
private List<WebElement> deleteRedirectUriIcons; private List<WebElement> deleteRedirectUriIcons;
@FindBy(id = "newWebOrigin") @FindBy(id = "newWebOrigin")
@ -68,9 +67,22 @@ public class ClientSettingsForm extends CreateClientForm {
@FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteWebOrigin')]") @FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteWebOrigin')]")
private List<WebElement> deleteWebOriginIcons; private List<WebElement> deleteWebOriginIcons;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='consentRequired']]") public enum OidcAccessType {
private OnOffSwitch consentRequired; BEARER_ONLY("bearer-only"),
PUBLIC("public"),
CONFIDENTIAL("confidential");
private final String name;
private OidcAccessType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public void setBaseUrl(String baseUrl) { public void setBaseUrl(String baseUrl) {
setInputValue(baseUrlInput, baseUrl); setInputValue(baseUrlInput, baseUrl);
} }
@ -113,32 +125,6 @@ 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());
}
}
public String getName() { public String getName() {
return getInputValue(nameInput); return getInputValue(nameInput);
} }
@ -163,14 +149,8 @@ public class ClientSettingsForm extends CreateClientForm {
consentRequiredSwitch.setOn(consentRequired); consentRequiredSwitch.setOn(consentRequired);
} }
public void setAccessType(ClientRepresentation client) { public void setAccessType(OidcAccessType accessType) {
if (client.isBearerOnly()) { accessTypeSelect.selectByVisibleText(accessType.getName());
accessTypeSelect.selectByVisibleText(BEARER_ONLY.getName());
} else if (client.isPublicClient()) {
accessTypeSelect.selectByVisibleText(PUBLIC.getName());
} else {
accessTypeSelect.selectByVisibleText(CONFIDENTIAL.getName());
}
} }
public void addRedirectUri(String redirectUri) { public void addRedirectUri(String redirectUri) {
@ -233,5 +213,86 @@ public class ClientSettingsForm extends CreateClientForm {
public void setServiceAccountsEnabled(boolean serviceAccountsEnabled) { public void setServiceAccountsEnabled(boolean serviceAccountsEnabled) {
serviceAccountsEnabledSwitch.setOn(serviceAccountsEnabled); serviceAccountsEnabledSwitch.setOn(serviceAccountsEnabled);
} }
public class SAMLClientSettingsForm extends Form {
} public static final String SAML_ASSERTION_SIGNATURE = "saml.assertion.signature";
public static final String SAML_AUTHNSTATEMENT = "saml.authnstatement";
public static final String SAML_CLIENT_SIGNATURE = "saml.client.signature";
public static final String SAML_ENCRYPT = "saml.encrypt";
public static final String SAML_FORCE_POST_BINDING = "saml.force.post.binding";
public static final String SAML_MULTIVALUED_ROLES = "saml.multivalued.roles";
public static final String SAML_SERVER_SIGNATURE = "saml.server.signature";
public static final String SAML_SIGNATURE_ALGORITHM = "saml.signature.algorithm";
public static final String SAML_ASSERTION_CONSUMER_URL_POST = "saml_assertion_consumer_url_post";
public static final String SAML_ASSERTION_CONSUMER_URL_REDIRECT = "saml_assertion_consumer_url_redirect";
public static final String SAML_FORCE_NAME_ID_FORMAT = "saml_force_name_id_format";
public static final String SAML_NAME_ID_FORMAT = "saml_name_id_format";
public static final String SAML_SIGNATURE_CANONICALIZATION_METHOD = "saml_signature_canonicalization_method";
public static final String SAML_SINGLE_LOGOUT_SERVICE_URL_POST = "saml_single_logout_service_url_post";
public static final String SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT = "saml_single_logout_service_url_redirect";
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlAuthnStatement']]")
private OnOffSwitch samlAuthnStatement;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlServerSignature']]")
private OnOffSwitch samlServerSignature;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlAssertionSignature']]")
private OnOffSwitch samlAssertionSignature;
@FindBy(id = "signatureAlgorithm")
private Select signatureAlgorithm;
@FindBy(id = "canonicalization")
private Select canonicalization;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlEncrypt']]")
private OnOffSwitch samlEncrypt;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlClientSignature']]")
private OnOffSwitch samlClientSignature;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlForcePostBinding']]")
private OnOffSwitch samlForcePostBinding;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='frontchannelLogout']]")
private OnOffSwitch frontchannelLogout;
@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='samlForceNameIdFormat']]")
private OnOffSwitch samlForceNameIdFormat;
@FindBy(id = "samlNameIdFormat")
private Select samlNameIdFormat;
@FindBy(xpath = "//fieldset[contains(@data-ng-show, 'saml')]//i")
private WebElement fineGrainCollapsor;
@FindBy(id = "consumerServicePost")
private WebElement consumerServicePostInput;
@FindBy(id = "consumerServiceRedirect")
private WebElement consumerServiceRedirectInput;
@FindBy(id = "logoutPostBinding")
private WebElement logoutPostBindingInput;
@FindBy(id = "logoutRedirectBinding")
private WebElement logoutRedirectBindingInput;
public void setValues(ClientRepresentation client) {
waitUntilElement(fineGrainCollapsor).is().visible();
Map<String, String> attributes = client.getAttributes();
samlAuthnStatement.setOn("true".equals(attributes.get(SAML_AUTHNSTATEMENT)));
samlServerSignature.setOn("true".equals(attributes.get(SAML_SERVER_SIGNATURE)));
samlAssertionSignature.setOn("true".equals(attributes.get(SAML_ASSERTION_SIGNATURE)));
if (samlServerSignature.isOn() || samlAssertionSignature.isOn()) {
signatureAlgorithm.selectByVisibleText(attributes.get(SAML_SIGNATURE_ALGORITHM));
canonicalization.selectByValue("string:" + attributes.get(SAML_SIGNATURE_CANONICALIZATION_METHOD));
}
samlEncrypt.setOn("true".equals(attributes.get(SAML_ENCRYPT)));
samlClientSignature.setOn("true".equals(attributes.get(SAML_CLIENT_SIGNATURE)));
samlForcePostBinding.setOn("true".equals(attributes.get(SAML_FORCE_POST_BINDING)));
frontchannelLogout.setOn(client.isFrontchannelLogout());
samlForceNameIdFormat.setOn("true".equals(attributes.get(SAML_FORCE_NAME_ID_FORMAT)));
samlNameIdFormat.selectByVisibleText(attributes.get(SAML_NAME_ID_FORMAT));
fineGrainCollapsor.click();
waitUntilElement(consumerServicePostInput).is().present();
setInputValue(consumerServicePostInput, attributes.get(SAML_ASSERTION_CONSUMER_URL_POST));
setInputValue(consumerServiceRedirectInput, attributes.get(SAML_ASSERTION_CONSUMER_URL_REDIRECT));
setInputValue(logoutPostBindingInput, attributes.get(SAML_SINGLE_LOGOUT_SERVICE_URL_POST));
setInputValue(logoutRedirectBindingInput, attributes.get(SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT));
}
}
}

View file

@ -11,9 +11,12 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.keycloak.representations.idm.RoleRepresentation.Composites; import org.keycloak.representations.idm.RoleRepresentation.Composites;
import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.page.Form;
import static org.keycloak.testsuite.util.WaitUtils.pause;
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.Select;
@ -106,6 +109,7 @@ public class RoleCompositeRoles extends Form {
select.selectByVisibleText(role); select.selectByVisibleText(role);
} }
} }
waitUntilElement(button).is().enabled();
button.click(); button.click();
} }
} }

View file

@ -1,12 +1,10 @@
package org.keycloak.testsuite.console.clients; package org.keycloak.testsuite.console.clients;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.assertEquals;
import org.junit.Before; import org.junit.Before;
import org.keycloak.admin.client.resource.ClientResource; import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.ClientsResource; import org.keycloak.admin.client.resource.ClientsResource;
@ -18,32 +16,20 @@ import org.keycloak.testsuite.console.AbstractConsoleTest;
import org.keycloak.testsuite.console.page.clients.Client; import org.keycloak.testsuite.console.page.clients.Client;
import org.keycloak.testsuite.console.page.clients.Clients; import org.keycloak.testsuite.console.page.clients.Clients;
import org.keycloak.testsuite.console.page.clients.CreateClient; 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.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By; 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;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_ASSERTION_SIGNATURE;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_AUTHNSTATEMENT;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_CLIENT_SIGNATURE;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_ENCRYPT;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_FORCE_NAME_ID_FORMAT;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_FORCE_POST_BINDING;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_MULTIVALUED_ROLES;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_NAME_ID_FORMAT;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_SERVER_SIGNATURE;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_SIGNATURE_ALGORITHM;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_SIGNATURE_CANONICALIZATION_METHOD;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_SINGLE_LOGOUT_SERVICE_URL_POST;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.SAMLClientSettingsForm.SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT;
import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsBooleanAttributes; import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsBooleanAttributes;
import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsListAttributes; import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsListAttributes;
import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsStringAttributes; import static org.keycloak.testsuite.util.AttributesAssert.assertEqualsStringAttributes;
import static org.junit.Assert.assertEquals;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_AUTHNSTATEMENT;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_CLIENT_SIGNATURE;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_FORCE_NAME_ID_FORMAT;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_FORCE_POST_BINDING;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_NAME_ID_FORMAT;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_SERVER_SIGNATURE;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.SAML_SIGNATURE_ALGORITHM;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import static org.keycloak.testsuite.util.WaitUtils.pause;
/** /**
* *
@ -52,7 +38,7 @@ import static org.keycloak.testsuite.util.WaitUtils.pause;
public abstract class AbstractClientTest extends AbstractConsoleTest { public abstract class AbstractClientTest extends AbstractConsoleTest {
public final String TEST_CLIENT_ID = "test-client"; public final String TEST_CLIENT_ID = "test-client";
public final String TEST_REDIRECT_URIS = "http://example.test/app/*"; public final List<String> TEST_REDIRECT_URIs = Arrays.asList(new String[]{"http://example.test/app/"});
@Page @Page
protected Clients clientsPage; protected Clients clientsPage;
@ -60,12 +46,9 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
protected Client clientPage; // note: cannot call navigateTo() unless client id is set protected Client clientPage; // note: cannot call navigateTo() unless client id is set
@Page @Page
protected CreateClient createClientPage; protected CreateClient createClientPage;
@Page
protected ClientSettings clientSettingsPage;
@Before @Before
public void beforeClientTest() { public void beforeClientTest() {
// configure().clients();
clientsPage.navigateTo(); clientsPage.navigateTo();
} }
@ -76,78 +59,35 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
createClientPage.form().setValues(client); createClientPage.form().setValues(client);
createClientPage.form().save(); createClientPage.form().save();
assertAlertSuccess(); assertAlertSuccess();
pause(500); // To ensure that the form will be loaded completely
clientSettingsPage.form().setValues(client);
if (SAML.equals(client.getProtocol())) {
createClientPage.form().samlForm().setValues(client);
}
clientSettingsPage.form().save();
} }
private static ClientRepresentation createClientRep(String clientId) { public static ClientRepresentation createClientRep(String clientId, String protocol) {
ClientRepresentation client = new ClientRepresentation(); ClientRepresentation client = new ClientRepresentation();
client.setClientId(clientId); client.setClientId(clientId);
client.setEnabled(true); client.setEnabled(true);
client.setConsentRequired(false); client.setProtocol(protocol);
return client;
} client.setDirectAccessGrantsEnabled(true);
client.setFullScopeAllowed(true);
public static ClientRepresentation createOidcClientRep(OidcAccessType accessType, String clientId, String... redirectUris) { client.setPublicClient(true);
ClientRepresentation client = createClientRep(clientId); client.setStandardFlowEnabled(true);
client.setProtocol(OIDC); if (protocol.equals(SAML)) {
client.setAttributes(getSAMLAttributes());
switch (accessType) {
case BEARER_ONLY:
client.setBearerOnly(true);
break;
case PUBLIC:
client.setBearerOnly(false);
client.setPublicClient(true);
client.setStandardFlowEnabled(true);
client.setImplicitFlowEnabled(false);
client.setDirectAccessGrantsEnabled(true);
setRedirectUris(client, redirectUris);
break;
case CONFIDENTIAL:
client.setBearerOnly(false);
client.setPublicClient(false);
client.setStandardFlowEnabled(true);
client.setDirectAccessGrantsEnabled(true);
client.setServiceAccountsEnabled(true);
setRedirectUris(client, redirectUris);
break;
} }
return client; return client;
} }
public static ClientRepresentation createSamlClientRep(String clinetId) { public static Map<String, String> getSAMLAttributes() {
ClientRepresentation client = createClientRep(clinetId); Map<String, String> attributes = new HashMap<>();
attributes.put(SAML_CLIENT_SIGNATURE, "true");
client.setProtocol(SAML); attributes.put(SAML_AUTHNSTATEMENT, "true");
attributes.put(SAML_FORCE_POST_BINDING, "true");
client.setFrontchannelLogout(true); attributes.put(SAML_SERVER_SIGNATURE, "true");
client.setAttributes(getSAMLAttributes()); attributes.put(SAML_SIGNATURE_ALGORITHM, "RSA_SHA256");
attributes.put(SAML_FORCE_NAME_ID_FORMAT, "false");
return client; attributes.put(SAML_NAME_ID_FORMAT, "username");
} return attributes;
private static void setRedirectUris(ClientRepresentation client, String... redirectUris) {
List<String> redirectUrisList = new ArrayList<>();
redirectUrisList.addAll(Arrays.asList(redirectUris));
client.setRedirectUris(redirectUrisList);
}
protected static void setExpectedWebOrigins(ClientRepresentation client) {
List<String> webOrigins = new ArrayList<>();
for (String redirectUri : client.getRedirectUris()) {
//parse webOrigin from redirectUri: take substring from index 0 to
//first occurence of "/", excluded "http://" by starting search on index 7
webOrigins.add(redirectUri.substring(0, redirectUri.indexOf("/", 7)));
}
client.setWebOrigins(webOrigins);
} }
public ClientRepresentation findClientByClientId(String clientId) { public ClientRepresentation findClientByClientId(String clientId) {
@ -172,16 +112,12 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
if (c1.getProtocol().equals(OIDC)) { if (c1.getProtocol().equals(OIDC)) {
assertEqualsBooleanAttributes(c1.isBearerOnly(), c2.isBearerOnly()); assertEqualsBooleanAttributes(c1.isBearerOnly(), c2.isBearerOnly());
if (!c1.isBearerOnly()) { assertEqualsBooleanAttributes(c1.isDirectAccessGrantsEnabled(), c2.isDirectAccessGrantsEnabled());
assertEqualsBooleanAttributes(c1.isDirectAccessGrantsEnabled(), c2.isDirectAccessGrantsEnabled()); assertEqualsBooleanAttributes(c1.isPublicClient(), c2.isPublicClient());
assertEqualsBooleanAttributes(c1.isPublicClient(), c2.isPublicClient()); assertEqualsListAttributes(c1.getWebOrigins(), c2.getWebOrigins());
assertEqualsListAttributes(c1.getWebOrigins(), c2.getWebOrigins()); assertEqualsStringAttributes(c1.getAdminUrl(), c2.getAdminUrl());
assertEqualsStringAttributes(c1.getAdminUrl(), c2.getAdminUrl());
}
assertEqualsBooleanAttributes(c1.isSurrogateAuthRequired(), c2.isSurrogateAuthRequired()); assertEqualsBooleanAttributes(c1.isSurrogateAuthRequired(), c2.isSurrogateAuthRequired());
assertEqualsBooleanAttributes(c1.isServiceAccountsEnabled(), c2.isServiceAccountsEnabled()); assertEqualsBooleanAttributes(c1.isServiceAccountsEnabled(), c2.isServiceAccountsEnabled());
} else if (c1.getProtocol().equals(SAML)) {
assertEqualsBooleanAttributes(c1.isFrontchannelLogout(), c2.isFrontchannelLogout());
} }
} }
@ -191,26 +127,6 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
} }
} }
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) { public ProtocolMapperRepresentation findClientMapperByName(String clientId, String mapperName) {
ProtocolMapperRepresentation found = null; ProtocolMapperRepresentation found = null;
for (ProtocolMapperRepresentation mapper : testRealmResource().clients().get(clientId).getProtocolMappers().getMappers()) { for (ProtocolMapperRepresentation mapper : testRealmResource().clients().get(clientId).getProtocolMappers().getMappers()) {
@ -229,4 +145,4 @@ public abstract class AbstractClientTest extends AbstractConsoleTest {
return clientsResource().get(id); return clientsResource().get(id);
} }
} }

View file

@ -26,8 +26,7 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createOidcClientRep; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
import org.keycloak.testsuite.console.page.clients.clustering.ClientClustering; import org.keycloak.testsuite.console.page.clients.clustering.ClientClustering;
/** /**
@ -44,7 +43,7 @@ public class ClientClusteringTest extends AbstractClientTest {
@Before @Before
public void before() { public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
found = findClientByClientId(TEST_CLIENT_ID); found = findClientByClientId(TEST_CLIENT_ID);
@ -95,4 +94,4 @@ public class ClientClusteringTest extends AbstractClientTest {
clientClusteringPage.form().addNode(""); clientClusteringPage.form().addNode("");
assertAlertDanger(); assertAlertDanger();
} }
} }

View file

@ -26,8 +26,7 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createOidcClientRep; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
import org.keycloak.testsuite.console.page.clients.credentials.ClientCredentials; import org.keycloak.testsuite.console.page.clients.credentials.ClientCredentials;
import org.keycloak.testsuite.console.page.clients.credentials.ClientCredentialsGeneratePrivateKeys; import org.keycloak.testsuite.console.page.clients.credentials.ClientCredentialsGeneratePrivateKeys;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
@ -47,7 +46,7 @@ public class ClientCredentialsTest extends AbstractClientTest {
@Before @Before
public void before() { public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID); ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
@ -83,4 +82,4 @@ public class ClientCredentialsTest extends AbstractClientTest {
// generatePrivateKeysPage.generateForm().setStorePassword("pass2"); // generatePrivateKeysPage.generateForm().setStorePassword("pass2");
// assertAlertSuccess();//fails with phantomjs // assertAlertSuccess();//fails with phantomjs
} }
} }

View file

@ -26,9 +26,8 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createOidcClientRep; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import org.keycloak.testsuite.console.page.clients.installation.ClientInstallation; import org.keycloak.testsuite.console.page.clients.installation.ClientInstallation;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
/** /**
* *
@ -44,7 +43,7 @@ public class ClientInstallationTest extends AbstractClientTest {
@Before @Before
public void before() { public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
found = findClientByClientId(TEST_CLIENT_ID); found = findClientByClientId(TEST_CLIENT_ID);
@ -64,4 +63,4 @@ public class ClientInstallationTest extends AbstractClientTest {
clientInstallationPage.form().setConfigFormat("Keycloak OIDC JBoss Subsystem XML"); clientInstallationPage.form().setConfigFormat("Keycloak OIDC JBoss Subsystem XML");
assertTrue(clientInstallationPage.form().getTextareaContent().contains("<realm>test</realm>")); assertTrue(clientInstallationPage.form().getTextareaContent().contains("<realm>test</realm>"));
} }
} }

View file

@ -31,7 +31,8 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createClientRep;
import org.keycloak.testsuite.console.page.clients.mappers.ClientMapper; 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.ClientMappers;
import org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappers; import org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappers;
@ -55,7 +56,7 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
@Before @Before
public void beforeClientMappersTest() { public void beforeClientMappersTest() {
ClientRepresentation newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); ClientRepresentation newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
id = findClientByClientId(TEST_CLIENT_ID).getId(); id = findClientByClientId(TEST_CLIENT_ID).getId();
@ -375,4 +376,4 @@ public class ClientMappersOIDCTest extends AbstractClientTest {
createClientMappersPage.form().save(); createClientMappersPage.form().save();
assertAlertDanger(); assertAlertDanger();
} }
} }

View file

@ -29,6 +29,8 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import static org.keycloak.testsuite.auth.page.login.Login.SAML;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createClientRep;
import org.keycloak.testsuite.console.page.clients.mappers.ClientMapper; 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.ClientMappers;
import org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappers; import org.keycloak.testsuite.console.page.clients.mappers.CreateClientMappers;
@ -52,7 +54,7 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
@Before @Before
public void beforeClientMappersTest() { public void beforeClientMappersTest() {
ClientRepresentation newClient = createSamlClientRep(TEST_CLIENT_ID); ClientRepresentation newClient = createClientRep(TEST_CLIENT_ID, SAML);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
id = findClientByClientId(TEST_CLIENT_ID).getId(); id = findClientByClientId(TEST_CLIENT_ID).getId();
@ -209,4 +211,4 @@ public class ClientMappersSAMLTest extends AbstractClientTest {
assertEquals(1, config.size()); assertEquals(1, config.size());
assertEquals("offline_access", config.get("role")); assertEquals("offline_access", config.get("role"));
} }
} }

View file

@ -9,7 +9,8 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.RoleRepresentation;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createClientRep;
import org.keycloak.testsuite.console.page.clients.roles.ClientRole; 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.ClientRoles;
import org.keycloak.testsuite.console.page.clients.roles.CreateClientRole; import org.keycloak.testsuite.console.page.clients.roles.CreateClientRole;
@ -39,7 +40,7 @@ public class ClientRolesTest extends AbstractClientTest {
@Before @Before
public void beforeClientRolesTest() { public void beforeClientRolesTest() {
ClientRepresentation newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); ClientRepresentation newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
id = findClientByClientId(TEST_CLIENT_ID).getId(); id = findClientByClientId(TEST_CLIENT_ID).getId();
@ -295,4 +296,4 @@ public class ClientRolesTest extends AbstractClientTest {
// assertTrue(flashMessage.getText(), flashMessage.isSuccess()); // assertTrue(flashMessage.getText(), flashMessage.isSuccess());
// assertNull(clients.findClient(newClient.getClientId())); // assertNull(clients.findClient(newClient.getClientId()));
// } // }
} }

View file

@ -26,13 +26,13 @@ import java.util.Map;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.keycloak.representations.idm.ClientMappingsRepresentation; import org.keycloak.representations.idm.ClientMappingsRepresentation;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.MappingsRepresentation; import org.keycloak.representations.idm.MappingsRepresentation;
import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.RoleRepresentation;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createOidcClientRep; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
import org.keycloak.testsuite.console.page.clients.scope.ClientScope; import org.keycloak.testsuite.console.page.clients.scope.ClientScope;
/** /**
@ -49,7 +49,7 @@ public class ClientScopeTest extends AbstractClientTest {
@Before @Before
public void before() { public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
found = findClientByClientId(TEST_CLIENT_ID); found = findClientByClientId(TEST_CLIENT_ID);
@ -59,6 +59,7 @@ public class ClientScopeTest extends AbstractClientTest {
} }
@Test @Test
@Ignore //phantomjs sometimes doens't enable "Add Selected >>" button when role is selected
public void clientScopeTest() { public void clientScopeTest() {
assertTrue(found.isFullScopeAllowed()); assertTrue(found.isFullScopeAllowed());
clientScopePage.scopeForm().setFullScopeAllowed(false); clientScopePage.scopeForm().setFullScopeAllowed(false);
@ -69,11 +70,11 @@ public class ClientScopeTest extends AbstractClientTest {
assertNull(getAllMappingsRepresentation().getRealmMappings()); assertNull(getAllMappingsRepresentation().getRealmMappings());
assertNull(getAllMappingsRepresentation().getClientMappings()); assertNull(getAllMappingsRepresentation().getClientMappings());
clientScopePage.roleForm().addRealmRole("offline_access"); clientScopePage.roleForm().addRealmRole("offline_access");//fails with phantomjs
assertAlertSuccess(); assertAlertSuccess();
clientScopePage.roleForm().selectClientRole("account"); clientScopePage.roleForm().selectClientRole("account");
clientScopePage.roleForm().addClientRole("view-profile"); clientScopePage.roleForm().addClientRole("view-profile");//fails with phantomjs
assertAlertSuccess(); assertAlertSuccess();
found = findClientByClientId(TEST_CLIENT_ID); found = findClientByClientId(TEST_CLIENT_ID);
@ -84,16 +85,16 @@ public class ClientScopeTest extends AbstractClientTest {
assertEquals(1, clientMappings.size()); assertEquals(1, clientMappings.size());
assertEquals("view-profile", clientMappings.get("account").getMappings().get(0).getName()); assertEquals("view-profile", clientMappings.get("account").getMappings().get(0).getName());
// clientScopePage.roleForm().removeAssignedRole("offline_access"); clientScopePage.roleForm().removeAssignedRole("offline_access");
// assertAlertSuccess();//fails with phantomjs assertAlertSuccess();//fails with phantomjs
// clientScopePage.roleForm().removeAssignedClientRole("view-profile"); clientScopePage.roleForm().removeAssignedClientRole("view-profile");
// assertAlertSuccess();//fails with phantomjs assertAlertSuccess();//fails with phantomjs
//
// assertNull(getAllMappingsRepresentation().getRealmMappings()); assertNull(getAllMappingsRepresentation().getRealmMappings());
// assertNull(getAllMappingsRepresentation().getClientMappings()); assertNull(getAllMappingsRepresentation().getClientMappings());
} }
private MappingsRepresentation getAllMappingsRepresentation() { private MappingsRepresentation getAllMappingsRepresentation() {
return testRealmResource().clients().get(found.getId()).getScopeMappings().getAll(); return testRealmResource().clients().get(found.getId()).getScopeMappings().getAll();
} }
} }

View file

@ -18,7 +18,9 @@
package org.keycloak.testsuite.console.clients; package org.keycloak.testsuite.console.clients;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -26,8 +28,12 @@ import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.admin.ApiUtil.getCreatedId; import static org.keycloak.testsuite.admin.ApiUtil.getCreatedId;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.*; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.auth.page.login.Login.SAML;
import org.keycloak.testsuite.console.page.clients.settings.ClientSettings; import org.keycloak.testsuite.console.page.clients.settings.ClientSettings;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.OidcAccessType.BEARER_ONLY;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.OidcAccessType.CONFIDENTIAL;
import static org.keycloak.testsuite.console.page.clients.settings.ClientSettingsForm.SAMLClientSettingsForm.*;
import static org.keycloak.testsuite.util.WaitUtils.pause; import static org.keycloak.testsuite.util.WaitUtils.pause;
import org.keycloak.testsuite.util.Timer; import org.keycloak.testsuite.util.Timer;
@ -45,20 +51,17 @@ public class ClientSettingsTest extends AbstractClientTest {
private ClientRepresentation newClient; private ClientRepresentation newClient;
@Test @Test
public void crudOIDCConfidential() { public void crudOIDCPublic() {
newClient = createOidcClientRep(CONFIDENTIAL, "oidc-confidential", TEST_REDIRECT_URIS); newClient = createClientRep("oidc-public", OIDC);
createClient(newClient); createClient(newClient);
assertAlertSuccess();
//setExpectedWebOrigins(newClient);
// read & verify // read & verify
ClientRepresentation found = findClientByClientId(newClient.getClientId()); ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found); assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found); assertClientSettingsEqual(newClient, found);
// update & verify // update & verify
newClient.setClientId("oidc-confidential-updated"); newClient.setClientId("oidc-public-updated");
newClient.setName("updatedName"); newClient.setName("updatedName");
List<String> redirectUris = new ArrayList<>(); List<String> redirectUris = new ArrayList<>();
@ -73,7 +76,7 @@ public class ClientSettingsTest extends AbstractClientTest {
webOrigins.add("http://example3.test"); webOrigins.add("http://example3.test");
newClient.setWebOrigins(webOrigins); newClient.setWebOrigins(webOrigins);
clientSettingsPage.form().setClientId("oidc-confidential-updated"); clientSettingsPage.form().setClientId("oidc-public-updated");
clientSettingsPage.form().setName("updatedName"); clientSettingsPage.form().setName("updatedName");
clientSettingsPage.form().setRedirectUris(redirectUris); clientSettingsPage.form().setRedirectUris(redirectUris);
clientSettingsPage.form().setWebOrigins(webOrigins); clientSettingsPage.form().setWebOrigins(webOrigins);
@ -92,36 +95,43 @@ public class ClientSettingsTest extends AbstractClientTest {
} }
@Test @Test
public void createOIDCPublic() { public void createOIDCConfidential() {
newClient = createOidcClientRep(PUBLIC, "oidc-public", TEST_REDIRECT_URIS); newClient = createClientRep("oidc-confidetial", OIDC);
createClient(newClient); createClient(newClient);
assertAlertSuccess();
//setExpectedWebOrigins(newClient);
newClient.setRedirectUris(TEST_REDIRECT_URIs);
newClient.setPublicClient(false);
clientSettingsPage.form().setAccessType(CONFIDENTIAL);
clientSettingsPage.form().setRedirectUris(TEST_REDIRECT_URIs);
clientSettingsPage.form().save();
ClientRepresentation found = findClientByClientId(newClient.getClientId()); ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found); assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found); assertClientSettingsEqual(newClient, found);
} }
@Test @Test
public void createOIDCPublicWithoutRedirectURIs() { public void saveOIDCConfidentialWithoutRedirectURIs() {
newClient = createOidcClientRep(PUBLIC, "oidc-public"); newClient = createClientRep("oidc-confidential", OIDC);
newClient.setStandardFlowEnabled(false);
createClient(newClient); createClient(newClient);
assertAlertSuccess();
ClientRepresentation found = findClientByClientId(newClient.getClientId()); clientSettingsPage.form().setName("name");
assertNotNull("Client " + newClient.getClientId() + " was not found.", found); clientSettingsPage.form().save();
assertClientSettingsEqual(newClient, found); assertAlertDanger();
} }
@Test @Test
public void createOIDCBearerOnly() { public void createOIDCBearerOnly() {
newClient = createOidcClientRep(BEARER_ONLY, "oidc-bearer-only"); newClient = createClientRep("oidc-bearer-only", OIDC);
createClient(newClient); createClient(newClient);
assertAlertSuccess();
clientSettingsPage.form().setAccessType(BEARER_ONLY);
clientSettingsPage.form().save();
newClient.setBearerOnly(true);
newClient.setPublicClient(false);
ClientRepresentation found = findClientByClientId(newClient.getClientId()); ClientRepresentation found = findClientByClientId(newClient.getClientId());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found); assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found); assertClientSettingsEqual(newClient, found);
@ -129,12 +139,10 @@ public class ClientSettingsTest extends AbstractClientTest {
@Test @Test
public void createSAML() { public void createSAML() {
newClient = createSamlClientRep("saml"); newClient = createClientRep("saml", SAML);
createClient(newClient); createClient(newClient);
assertAlertSuccess();
ClientRepresentation found = findClientByClientId(newClient.getClientId()); ClientRepresentation found = findClientByClientId(newClient.getClientId());
System.out.println("...." + found.isFrontchannelLogout());
assertNotNull("Client " + newClient.getClientId() + " was not found.", found); assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
assertClientSettingsEqual(newClient, found); assertClientSettingsEqual(newClient, found);
assertClientSamlAttributes(getSAMLAttributes(), found.getAttributes()); assertClientSamlAttributes(getSAMLAttributes(), found.getAttributes());
@ -145,27 +153,22 @@ public class ClientSettingsTest extends AbstractClientTest {
clientsPage.table().createClient(); clientsPage.table().createClient();
createClientPage.form().save(); createClientPage.form().save();
assertAlertDanger(); assertAlertDanger();
}
clientsPage.navigateTo();
// @Test newClient = createClientRep(TEST_CLIENT_ID, OIDC);
public void createInconsistentClient() { createClient(newClient);
ClientRepresentation c = createOidcClientRep(CONFIDENTIAL, "inconsistent_client");
c.setPublicClient(true); clientsPage.navigateTo();
c.setBearerOnly(true); clientsPage.table().createClient();
createClientPage.form().setClientId(TEST_CLIENT_ID);
Response r = clientsResource().create(c); createClientPage.form().save();
r.close(); assertAlertDanger();
clientSettingsPage.setId(getCreatedId(r));
c = clientResource(clientSettingsPage.getId()).toRepresentation();
assertTrue(c.isBearerOnly());
assertTrue(c.isPublicClient());
} }
public void createClients(String clientIdPrefix, int count) { public void createClients(String clientIdPrefix, int count) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String clientId = String.format("%s%02d", clientIdPrefix, i); String clientId = String.format("%s%02d", clientIdPrefix, i);
ClientRepresentation cr = createOidcClientRep(CONFIDENTIAL, clientId, "http://example.test/*"); ClientRepresentation cr = createClientRep(clientId, OIDC);
Timer.DEFAULT.reset(); Timer.DEFAULT.reset();
Response r = testRealmResource().clients().create(cr); Response r = testRealmResource().clients().create(cr);
r.close(); r.close();
@ -182,11 +185,11 @@ public class ClientSettingsTest extends AbstractClientTest {
@Test @Test
public void disabledClient() { public void disabledClient() {
newClient = createOidcClientRep(CONFIDENTIAL, "disabled-client"); newClient = createClientRep("disabled-client", OIDC);
newClient.setEnabled(false); newClient.setEnabled(false);
createClient(newClient); createClient(newClient);
ClientRepresentation clientRepre = findClientByClientId("disabled-client"); ClientRepresentation clientRepre = findClientByClientId("disabled-client");
assertTrue("Client should be disabled", clientRepre.isEnabled()); assertTrue("Client should be disabled", clientRepre.isEnabled());
} }
} }

View file

@ -26,9 +26,11 @@ import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createClientRep;
import org.keycloak.testsuite.console.page.clients.settings.ClientSettings; import org.keycloak.testsuite.console.page.clients.settings.ClientSettings;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
/** /**
* *
@ -43,7 +45,7 @@ public class ClientsTest extends AbstractClientTest {
@Before @Before
public void beforeClientsTest() { public void beforeClientsTest() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createClientRep(TEST_CLIENT_ID, OIDC);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID); ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
@ -71,4 +73,4 @@ public class ClientsTest extends AbstractClientTest {
ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID); ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
assertNull("Deleted client " + TEST_CLIENT_ID + " was found.", found); assertNull("Deleted client " + TEST_CLIENT_ID + " was found.", found);
} }
} }

View file

@ -1,3 +1,24 @@
/*
* 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.events; package org.keycloak.testsuite.console.events;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
@ -7,7 +28,6 @@ import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.admin.ApiUtil; import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.console.AbstractConsoleTest; import org.keycloak.testsuite.console.AbstractConsoleTest;
import org.keycloak.testsuite.console.clients.AbstractClientTest;
import org.keycloak.testsuite.console.page.clients.Clients; import org.keycloak.testsuite.console.page.clients.Clients;
import org.keycloak.testsuite.console.page.events.AdminEvents; import org.keycloak.testsuite.console.page.events.AdminEvents;
import org.keycloak.testsuite.console.page.events.Config; import org.keycloak.testsuite.console.page.events.Config;
@ -19,7 +39,8 @@ import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.keycloak.admin.client.resource.ClientsResource; import org.keycloak.admin.client.resource.ClientsResource;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createClientRep;
/** /**
@ -50,7 +71,7 @@ public class AdminEventsTest extends AbstractConsoleTest {
@Test @Test
public void clientsAdminEventsTest() { public void clientsAdminEventsTest() {
newClient = AbstractClientTest.createOidcClientRep(CONFIDENTIAL, "test_client", "http://example.test/test_client/*"); newClient = createClientRep("test_client", OIDC);
Response response = clientsResource().create(newClient); Response response = clientsResource().create(newClient);
String id = ApiUtil.getCreatedId(response); String id = ApiUtil.getCreatedId(response);
response.close(); response.close();
@ -90,4 +111,4 @@ public class AdminEventsTest extends AbstractConsoleTest {
public ClientsResource clientsResource() { public ClientsResource clientsResource() {
return testRealmResource().clients(); return testRealmResource().clients();
} }
} }