Test password policies using REST

This commit is contained in:
mhajas 2015-10-15 12:44:27 +02:00
parent 96099e0798
commit 2c460c3adc
2 changed files with 43 additions and 14 deletions

View file

@ -34,6 +34,8 @@ public class PasswordPolicy extends Authentication {
public void addPolicy(PasswordPolicy.Type policy, String value) {
waitGuiForElement(addPolicySelectElement);
addPolicySelect.selectByVisibleText(policy.getName());
//addPolicySelect.selectByValue(policy.getName());
setPolicyValue(policy, value);
primaryButton.click();
}
@ -82,10 +84,10 @@ public class PasswordPolicy extends Authentication {
public enum Type {
HASH_ITERATIONS("Hash Iterations"), LENGTH("Length"), DIGITS("Digits"), LOWER_CASE("Lower Case"),
UPPER_CASE("Upper Case"), SPECIAL_CHARS("Special Chars"), NOT_USERNAME("Not Username"),
REGEX_PATTERN("Regex Pattern"), PASSWORD_HISTORY("Password History"),
FORCE_EXPIRED_PASSWORD_CHANGE("Force Expired Password Change");
HASH_ITERATIONS("HashIterations"), LENGTH("Length"), DIGITS("Digits"), LOWER_CASE("LowerCase"),
UPPER_CASE("UpperCase"), SPECIAL_CHARS("SpecialChars"), NOT_USERNAME("NotUsername"),
REGEX_PATTERN("RegexPattern"), PASSWORD_HISTORY("PasswordHistory"),
FORCE_EXPIRED_PASSWORD_CHANGE("ForceExpiredPasswordChange");
private String name;

View file

@ -21,11 +21,13 @@ import org.jboss.arquillian.graphene.page.Page;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.console.AbstractConsoleTest;
import org.keycloak.testsuite.console.page.authentication.PasswordPolicy;
import org.keycloak.testsuite.console.page.users.UserCredentials;
import static org.keycloak.testsuite.console.page.authentication.PasswordPolicy.Type.*;
import static org.keycloak.testsuite.console.page.authentication.PasswordPolicy.Type.HASH_ITERATIONS;
import static org.keycloak.testsuite.console.page.authentication.PasswordPolicy.Type.REGEX_PATTERN;
/**
* @author Petr Mensik
@ -43,11 +45,11 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Before
public void beforePasswordPolicyTest() {
testUserCredentialsPage.setId(testUser.getId());
passwordPolicyPage.navigateTo();
}
@Test
public void testAddAndRemovePolicy() {
passwordPolicyPage.navigateTo();
passwordPolicyPage.addPolicy(HASH_ITERATIONS, 5);
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
assertFlashMessageSuccess();
@ -55,6 +57,7 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testInvalidPolicyValues() {
passwordPolicyPage.navigateTo();
passwordPolicyPage.addPolicy(HASH_ITERATIONS, "asd");
assertFlashMessageDanger();
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
@ -65,7 +68,10 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testLengthPolicy() {
passwordPolicyPage.addPolicy(LENGTH, 8);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("length(8) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("1234567");
@ -77,7 +83,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testDigitsPolicy() {
passwordPolicyPage.addPolicy(DIGITS, 2);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("digits(2) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("invalidPassword1");
@ -89,7 +97,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testLowerCasePolicy() {
passwordPolicyPage.addPolicy(LOWER_CASE, 2);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("lowerCase(2) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("iNVALIDPASSWORD");
@ -101,7 +111,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testUpperCasePolicy() {
passwordPolicyPage.addPolicy(UPPER_CASE, 2);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("upperCase(2) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("Invalidpassword");
@ -113,7 +125,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testSpecialCharsPolicy() {
passwordPolicyPage.addPolicy(SPECIAL_CHARS, 2);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("specialChars(2) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("invalidPassword*");
@ -125,7 +139,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testNotUsernamePolicy() {
passwordPolicyPage.addPolicy(NOT_USERNAME);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("notUsername(1) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword(testUser.getUsername());
@ -137,7 +153,16 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testRegexPatternsPolicy() {
passwordPolicyPage.addPolicy(REGEX_PATTERN, "^[A-Z]+#[a-z]{8}$");
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("regexPattern(^[A-Z]+#[a-z]{8}$) and ");
System.out.println(realm.getPasswordPolicy());
testRealmResource().update(realm);
/* try {
Thread.sleep(45000000);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("invalidPassword");
@ -149,7 +174,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
@Test
public void testPasswordHistoryPolicy() {
passwordPolicyPage.addPolicy(PASSWORD_HISTORY, 2);
RealmRepresentation realm = testRealmResource().toRepresentation();
realm.setPasswordPolicy("passwordHistory(2) and ");
testRealmResource().update(realm);
testUserCredentialsPage.navigateTo();
testUserCredentialsPage.resetPassword("firstPassword");