KPR-87 - Agreement on terms and conditions as part of authentication - Tests
This commit is contained in:
parent
229eca302f
commit
fa0335613f
7 changed files with 408 additions and 4 deletions
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.keycloak.testsuite.auth.page.login;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class TermsAndConditions extends LoginActions {
|
||||
|
||||
@FindBy(id = "kc-accept")
|
||||
private WebElement acceptButton;
|
||||
|
||||
@FindBy(id = "kc-decline")
|
||||
private WebElement declineButton;
|
||||
|
||||
@FindBy(id = "kc-terms-text")
|
||||
private WebElement textElem;
|
||||
|
||||
@Override
|
||||
public boolean isCurrent() {
|
||||
return driver.getTitle().equals("Terms and Conditions");
|
||||
}
|
||||
|
||||
public void acceptTerms() {
|
||||
acceptButton.click();
|
||||
}
|
||||
public void declineTerms() {
|
||||
declineButton.click();
|
||||
}
|
||||
|
||||
public String getAcceptButtonText() {
|
||||
return acceptButton.getAttribute("value");
|
||||
}
|
||||
|
||||
public String getDeclineButtonText() {
|
||||
return declineButton.getAttribute("value");
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return textElem.getText();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
package org.keycloak.testsuite;
|
||||
|
||||
import java.io.File;
|
||||
import org.keycloak.testsuite.arquillian.TestContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
|
@ -32,11 +32,16 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.keycloak.admin.client.Keycloak;
|
||||
import org.keycloak.admin.client.resource.AuthenticationManagementResource;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.admin.client.resource.RealmsResource;
|
||||
import org.keycloak.admin.client.resource.UserResource;
|
||||
import org.keycloak.admin.client.resource.UsersResource;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.RequiredActionProviderRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
||||
import org.keycloak.testsuite.arquillian.SuiteContext;
|
||||
import org.keycloak.testsuite.auth.page.WelcomePage;
|
||||
|
@ -50,10 +55,8 @@ import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
|
|||
import org.keycloak.testsuite.auth.page.account.Account;
|
||||
import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||
import org.keycloak.testsuite.util.Timer;
|
||||
import org.keycloak.testsuite.util.WaitUtils;
|
||||
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
|
||||
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -206,4 +209,63 @@ public abstract class AbstractKeycloakTest {
|
|||
return adminClient.realms();
|
||||
}
|
||||
|
||||
public void createRealm(String realm) {
|
||||
try {
|
||||
RealmResource realmResource = adminClient.realms().realm(realm);
|
||||
// Throws NotFoundException in case the realm does not exist! Ugly but there
|
||||
// does not seem to be a way to this just by asking.
|
||||
RealmRepresentation realmRepresentation = realmResource.toRepresentation();
|
||||
} catch (NotFoundException ex) {
|
||||
RealmRepresentation realmRepresentation = new RealmRepresentation();
|
||||
realmRepresentation.setRealm(realm);
|
||||
realmRepresentation.setEnabled(true);
|
||||
realmRepresentation.setRegistrationAllowed(true);
|
||||
adminClient.realms().create(realmRepresentation);
|
||||
|
||||
// List<RequiredActionProviderRepresentation> requiredActions = adminClient.realm(realm).flows().getRequiredActions();
|
||||
// for (RequiredActionProviderRepresentation a : requiredActions) {
|
||||
// a.setEnabled(false);
|
||||
// a.setDefaultAction(false);
|
||||
// adminClient.realm(realm).flows().updateRequiredAction(a.getAlias(), a);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public String createUser(String realm, String username, String password, String ... requiredActions) {
|
||||
List<String> requiredUserActions = Arrays.asList(requiredActions);
|
||||
|
||||
UserRepresentation homer = new UserRepresentation();
|
||||
homer.setEnabled(true);
|
||||
homer.setUsername(username);
|
||||
homer.setRequiredActions(requiredUserActions);
|
||||
|
||||
return ApiUtil.createUserAndResetPasswordWithAdminClient(adminClient.realm(realm), homer, password);
|
||||
}
|
||||
|
||||
public void setRequiredActionEnabled(String realm, String requiredAction, boolean enabled, boolean defaultAction) {
|
||||
AuthenticationManagementResource managementResource = adminClient.realm(realm).flows();
|
||||
|
||||
RequiredActionProviderRepresentation action = managementResource.getRequiredAction(requiredAction);
|
||||
action.setEnabled(enabled);
|
||||
action.setDefaultAction(defaultAction);
|
||||
|
||||
managementResource.updateRequiredAction(requiredAction, action);
|
||||
}
|
||||
|
||||
public void setRequiredActionEnabled(String realm, String userId, String requiredAction, boolean enabled) {
|
||||
UsersResource usersResource = adminClient.realm(realm).users();
|
||||
|
||||
UserResource userResource = usersResource.get(userId);
|
||||
UserRepresentation userRepresentation = userResource.toRepresentation();
|
||||
|
||||
List<String> requiredActions = userRepresentation.getRequiredActions();
|
||||
if (enabled && !requiredActions.contains(requiredAction)) {
|
||||
requiredActions.add(requiredAction);
|
||||
} else if (!enabled && requiredActions.contains(requiredAction)) {
|
||||
requiredActions.remove(requiredAction);
|
||||
}
|
||||
|
||||
userResource.update(userRepresentation);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,5 +30,33 @@
|
|||
<artifactId>integration-arquillian-tests-console</artifactId>
|
||||
|
||||
<name>Admin Console UI Tests</name>
|
||||
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-theme-files</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${keycloak.home}/themes</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources/themes</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
doAccept=Yes
|
||||
doDecline=No
|
||||
|
||||
termsText=<p>See <a href="https://en.wikipedia.org/wiki/Quality_assurance">QA</a> for more information.</p>
|
|
@ -0,0 +1 @@
|
|||
parent=base
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.keycloak.testsuite.console.authentication.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.auth.page.login.Registration;
|
||||
import org.keycloak.testsuite.auth.page.login.TermsAndConditions;
|
||||
import org.keycloak.testsuite.console.AbstractConsoleTest;
|
||||
import org.keycloak.testsuite.console.page.authentication.RequiredActions;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TermsAndConditionsTest extends AbstractConsoleTest {
|
||||
|
||||
private static final String TERMS_TEXT = "Terms and conditions to be defined";
|
||||
|
||||
private static final String REALM = "TermsAndConditions";
|
||||
|
||||
private static final String BART = "Bart";
|
||||
|
||||
private static final String BART_PASS = "Ay caramba!";
|
||||
|
||||
private static final String HOMER = "Homer";
|
||||
|
||||
private static final String HOMER_PASS = "Mmm donuts.";
|
||||
|
||||
@Page
|
||||
private TermsAndConditions termsAndConditionsPage;
|
||||
|
||||
@Page
|
||||
private Registration registrationPage;
|
||||
|
||||
@Override
|
||||
public void beforeConsoleTest() {
|
||||
// no operation - we don't need 'admin' user for this test.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
testRealmPage.setAuthRealm(REALM);
|
||||
testRealmAdminConsolePage.setAdminRealm(REALM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||
RealmRepresentation testRealmRep = new RealmRepresentation();
|
||||
testRealmRep.setRealm(REALM);
|
||||
testRealmRep.setEnabled(true);
|
||||
testRealms.add(testRealmRep);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingUser() {
|
||||
// create user
|
||||
String userId = createUser(REALM, HOMER, HOMER_PASS);
|
||||
|
||||
// test t&c - log in and make sure t&c is not displayed
|
||||
testRealmAdminConsolePage.navigateTo();
|
||||
testRealmLoginPage.form().login(HOMER, HOMER_PASS);
|
||||
testRealmAdminConsolePage.logOut();
|
||||
|
||||
// enable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
|
||||
setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
|
||||
|
||||
// test t&c - log in and accept
|
||||
testRealmLoginPage.form().login(HOMER, HOMER_PASS);
|
||||
Assert.assertEquals(TERMS_TEXT, termsAndConditionsPage.getText());
|
||||
termsAndConditionsPage.declineTerms();
|
||||
|
||||
testRealmLoginPage.form().login(HOMER, HOMER_PASS);
|
||||
Assert.assertEquals(TERMS_TEXT, termsAndConditionsPage.getText());
|
||||
|
||||
termsAndConditionsPage.acceptTerms();
|
||||
testRealmAdminConsolePage.logOut();
|
||||
|
||||
testRealmLoginPage.form().login(HOMER, HOMER_PASS);
|
||||
testRealmAdminConsolePage.logOut();
|
||||
|
||||
// disable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdminCreatedUser() {
|
||||
// enable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
|
||||
|
||||
// create user
|
||||
String userId = createUser(REALM, BART, BART_PASS);
|
||||
setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
|
||||
|
||||
// test t&c
|
||||
testRealmAdminConsolePage.navigateTo();
|
||||
testRealmLoginPage.form().login(BART, BART_PASS);
|
||||
Assert.assertTrue(termsAndConditionsPage.isCurrent());
|
||||
|
||||
// disable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelfRegisteredUser() {
|
||||
// enable self-registration
|
||||
RealmResource realmResource = adminClient.realm(REALM);
|
||||
RealmRepresentation realmRepresentation = realmResource.toRepresentation();
|
||||
realmRepresentation.setRegistrationAllowed(true);
|
||||
realmResource.update(realmRepresentation);
|
||||
|
||||
// enable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, true);
|
||||
|
||||
// self-register
|
||||
CredentialRepresentation mrBurnsPassword = new CredentialRepresentation();
|
||||
mrBurnsPassword.setType(CredentialRepresentation.PASSWORD);
|
||||
mrBurnsPassword.setValue("Excellent.");
|
||||
|
||||
List<CredentialRepresentation> credentials = new ArrayList<CredentialRepresentation>();
|
||||
credentials.add(mrBurnsPassword);
|
||||
|
||||
UserRepresentation mrBurns = new UserRepresentation();
|
||||
mrBurns.setUsername("mrburns");
|
||||
mrBurns.setFirstName("Montgomery");
|
||||
mrBurns.setLastName("Burns");
|
||||
mrBurns.setEmail("mburns@keycloak.org");
|
||||
mrBurns.setCredentials(credentials);
|
||||
|
||||
testRealmAdminConsolePage.navigateTo();
|
||||
testRealmLoginPage.form().register();
|
||||
|
||||
registrationPage.register(mrBurns);
|
||||
|
||||
// test t&c
|
||||
Assert.assertTrue(termsAndConditionsPage.isCurrent());
|
||||
|
||||
// disable terms
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.keycloak.testsuite.console.themes;
|
||||
|
||||
import java.util.List;
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.auth.page.login.TermsAndConditions;
|
||||
import org.keycloak.testsuite.console.AbstractConsoleTest;
|
||||
import org.keycloak.testsuite.console.page.authentication.RequiredActions;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TermsAndConditionsThemeTest extends AbstractConsoleTest {
|
||||
|
||||
private static final String REALM = "CustomLook";
|
||||
|
||||
private static final String HOMER = "Homer";
|
||||
|
||||
private static final String HOMER_PASS = "Mmm donuts.";
|
||||
|
||||
@Page
|
||||
private TermsAndConditions termsAndConditionsPage;
|
||||
|
||||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
testRealmPage.setAuthRealm(REALM);
|
||||
testRealmAdminConsolePage.setAdminRealm(REALM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||
RealmRepresentation testRealmRep = new RealmRepresentation();
|
||||
testRealmRep.setRealm(REALM);
|
||||
testRealmRep.setEnabled(true);
|
||||
testRealms.add(testRealmRep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeConsoleTest() {
|
||||
// no operation - we don't need 'admin' user for this test.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTermsAndConditions() {
|
||||
String userId = createUser(REALM, HOMER, HOMER_PASS);
|
||||
setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
|
||||
setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
|
||||
|
||||
RealmResource realmResource = adminClient.realm(REALM);
|
||||
RealmRepresentation realmRepresentation = realmResource.toRepresentation();
|
||||
realmRepresentation.setLoginTheme("qe");
|
||||
realmResource.update(realmRepresentation);
|
||||
|
||||
testRealmAdminConsolePage.navigateTo();
|
||||
testRealmLoginPage.form().login(HOMER, HOMER_PASS);
|
||||
|
||||
Assert.assertTrue(termsAndConditionsPage.isCurrent());
|
||||
Assert.assertTrue(termsAndConditionsPage.getText().contains("See QA for more information."));
|
||||
Assert.assertEquals("Yes", termsAndConditionsPage.getAcceptButtonText());
|
||||
Assert.assertEquals("No", termsAndConditionsPage.getDeclineButtonText());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue