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) {
|
||||
waitGuiForElement(addPolicySelectElement);
|
||||
addPolicySelect.selectByVisibleText(policy.getName());
|
||||
|
||||
//addPolicySelect.selectByValue(policy.getName());
|
||||
setPolicyValue(policy, value);
|
||||
primaryButton.click();
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue