Test password policies using REST
This commit is contained in:
parent
96099e0798
commit
2c460c3adc
2 changed files with 43 additions and 14 deletions
|
@ -34,6 +34,8 @@ public class PasswordPolicy extends Authentication {
|
||||||
public void addPolicy(PasswordPolicy.Type policy, String value) {
|
public void addPolicy(PasswordPolicy.Type policy, String value) {
|
||||||
waitGuiForElement(addPolicySelectElement);
|
waitGuiForElement(addPolicySelectElement);
|
||||||
addPolicySelect.selectByVisibleText(policy.getName());
|
addPolicySelect.selectByVisibleText(policy.getName());
|
||||||
|
|
||||||
|
//addPolicySelect.selectByValue(policy.getName());
|
||||||
setPolicyValue(policy, value);
|
setPolicyValue(policy, value);
|
||||||
primaryButton.click();
|
primaryButton.click();
|
||||||
}
|
}
|
||||||
|
@ -82,10 +84,10 @@ public class PasswordPolicy extends Authentication {
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
|
|
||||||
HASH_ITERATIONS("Hash Iterations"), LENGTH("Length"), DIGITS("Digits"), LOWER_CASE("Lower Case"),
|
HASH_ITERATIONS("HashIterations"), LENGTH("Length"), DIGITS("Digits"), LOWER_CASE("LowerCase"),
|
||||||
UPPER_CASE("Upper Case"), SPECIAL_CHARS("Special Chars"), NOT_USERNAME("Not Username"),
|
UPPER_CASE("UpperCase"), SPECIAL_CHARS("SpecialChars"), NOT_USERNAME("NotUsername"),
|
||||||
REGEX_PATTERN("Regex Pattern"), PASSWORD_HISTORY("Password History"),
|
REGEX_PATTERN("RegexPattern"), PASSWORD_HISTORY("PasswordHistory"),
|
||||||
FORCE_EXPIRED_PASSWORD_CHANGE("Force Expired Password Change");
|
FORCE_EXPIRED_PASSWORD_CHANGE("ForceExpiredPasswordChange");
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,13 @@ import org.jboss.arquillian.graphene.page.Page;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.testsuite.console.AbstractConsoleTest;
|
import org.keycloak.testsuite.console.AbstractConsoleTest;
|
||||||
import org.keycloak.testsuite.console.page.authentication.PasswordPolicy;
|
import org.keycloak.testsuite.console.page.authentication.PasswordPolicy;
|
||||||
import org.keycloak.testsuite.console.page.users.UserCredentials;
|
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
|
* @author Petr Mensik
|
||||||
|
@ -43,11 +45,11 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
@Before
|
@Before
|
||||||
public void beforePasswordPolicyTest() {
|
public void beforePasswordPolicyTest() {
|
||||||
testUserCredentialsPage.setId(testUser.getId());
|
testUserCredentialsPage.setId(testUser.getId());
|
||||||
passwordPolicyPage.navigateTo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddAndRemovePolicy() {
|
public void testAddAndRemovePolicy() {
|
||||||
|
passwordPolicyPage.navigateTo();
|
||||||
passwordPolicyPage.addPolicy(HASH_ITERATIONS, 5);
|
passwordPolicyPage.addPolicy(HASH_ITERATIONS, 5);
|
||||||
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
|
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
|
||||||
assertFlashMessageSuccess();
|
assertFlashMessageSuccess();
|
||||||
|
@ -55,6 +57,7 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidPolicyValues() {
|
public void testInvalidPolicyValues() {
|
||||||
|
passwordPolicyPage.navigateTo();
|
||||||
passwordPolicyPage.addPolicy(HASH_ITERATIONS, "asd");
|
passwordPolicyPage.addPolicy(HASH_ITERATIONS, "asd");
|
||||||
assertFlashMessageDanger();
|
assertFlashMessageDanger();
|
||||||
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
|
passwordPolicyPage.removePolicy(HASH_ITERATIONS);
|
||||||
|
@ -65,7 +68,10 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLengthPolicy() {
|
public void testLengthPolicy() {
|
||||||
passwordPolicyPage.addPolicy(LENGTH, 8);
|
|
||||||
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("length(8) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("1234567");
|
testUserCredentialsPage.resetPassword("1234567");
|
||||||
|
@ -77,7 +83,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDigitsPolicy() {
|
public void testDigitsPolicy() {
|
||||||
passwordPolicyPage.addPolicy(DIGITS, 2);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("digits(2) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("invalidPassword1");
|
testUserCredentialsPage.resetPassword("invalidPassword1");
|
||||||
|
@ -89,7 +97,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLowerCasePolicy() {
|
public void testLowerCasePolicy() {
|
||||||
passwordPolicyPage.addPolicy(LOWER_CASE, 2);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("lowerCase(2) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("iNVALIDPASSWORD");
|
testUserCredentialsPage.resetPassword("iNVALIDPASSWORD");
|
||||||
|
@ -101,7 +111,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpperCasePolicy() {
|
public void testUpperCasePolicy() {
|
||||||
passwordPolicyPage.addPolicy(UPPER_CASE, 2);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("upperCase(2) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("Invalidpassword");
|
testUserCredentialsPage.resetPassword("Invalidpassword");
|
||||||
|
@ -113,7 +125,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpecialCharsPolicy() {
|
public void testSpecialCharsPolicy() {
|
||||||
passwordPolicyPage.addPolicy(SPECIAL_CHARS, 2);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("specialChars(2) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("invalidPassword*");
|
testUserCredentialsPage.resetPassword("invalidPassword*");
|
||||||
|
@ -125,7 +139,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotUsernamePolicy() {
|
public void testNotUsernamePolicy() {
|
||||||
passwordPolicyPage.addPolicy(NOT_USERNAME);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("notUsername(1) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword(testUser.getUsername());
|
testUserCredentialsPage.resetPassword(testUser.getUsername());
|
||||||
|
@ -137,7 +153,16 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegexPatternsPolicy() {
|
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.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("invalidPassword");
|
testUserCredentialsPage.resetPassword("invalidPassword");
|
||||||
|
@ -149,7 +174,9 @@ public class PasswordPolicyTest extends AbstractConsoleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasswordHistoryPolicy() {
|
public void testPasswordHistoryPolicy() {
|
||||||
passwordPolicyPage.addPolicy(PASSWORD_HISTORY, 2);
|
RealmRepresentation realm = testRealmResource().toRepresentation();
|
||||||
|
realm.setPasswordPolicy("passwordHistory(2) and ");
|
||||||
|
testRealmResource().update(realm);
|
||||||
|
|
||||||
testUserCredentialsPage.navigateTo();
|
testUserCredentialsPage.navigateTo();
|
||||||
testUserCredentialsPage.resetPassword("firstPassword");
|
testUserCredentialsPage.resetPassword("firstPassword");
|
||||||
|
|
Loading…
Reference in a new issue