Merge pull request #1807 from vramik/KEYCLOAK-2031

KEYCLOAK-2031: Input validation in OTP Policy page fix, test
This commit is contained in:
Stian Thorgersen 2015-11-12 09:23:13 +01:00
commit db84571546
4 changed files with 38 additions and 6 deletions

View file

@ -54,7 +54,7 @@
<div class="form-group" data-ng-show="realm.otpPolicyType == 'hotp'">
<label class="col-md-2 control-label" for="counter">Initial Counter</label>
<div class="col-md-6">
<input class="form-control" type="text" id="counter" name="counter" data-ng-model="realm.otpPolicyInitialCounter" autofocus>
<input class="form-control" type="number" required min="1" max="120" id="counter" name="counter" data-ng-model="realm.otpPolicyInitialCounter" autofocus>
</div>
<kc-tooltip>What should the initial counter value be?</kc-tooltip>
</div>

View file

@ -3,7 +3,7 @@ package org.keycloak.testsuite.console.page.authentication;
import org.keycloak.testsuite.console.page.AdminConsoleRealm;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import static org.keycloak.testsuite.util.WaitUtils.waitAjaxForElement;
import static org.keycloak.testsuite.util.WaitUtils.*;
/**
* @author tkyjovsk
@ -20,6 +20,9 @@ public class Authentication extends AdminConsoleRealm {
@FindBy(xpath = "//div[contains(@class, 'alert-success')]")
private WebElement success;
@FindBy(xpath = "//button[@class='close']/span")
private WebElement close;
public String getSuccessMessage() {
waitAjaxForElement(success);
return success.getText();
@ -30,6 +33,13 @@ public class Authentication extends AdminConsoleRealm {
return error.getText();
}
public void closeNotification() {
if (close.isDisplayed()) {
close.click();
}
waitAjaxForElementNotVisible(close);
}
public AuthenticationTabs tabs() {
return authenticationTabs;
}

View file

@ -41,6 +41,11 @@ public final class WaitUtils {
.element(element).is().not().present();
}
public static void waitAjaxForElementNotVisible(WebElement element) {
waitAjax().until()
.element(element).is().not().visible();
}
public static void waitGuiForElement(By element, String message) {
waitGui().until(message)
.element(element).is().present();

View file

@ -24,6 +24,7 @@ package org.keycloak.testsuite.console.authentication;
import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.console.AbstractConsoleTest;
@ -66,42 +67,58 @@ public class OTPPolicyTest extends AbstractConsoleTest {
}
@Test
@Ignore //KEYCLOAK-2051 when you close notification, it is not displayed again
public void invalidValuesTest() {
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "", "30");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();// workaround: input.clear() doesn't work when <input type="number" ...
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, " ", "30");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "no number", "30");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
RealmRepresentation realm = testRealmResource().toRepresentation();
assertEquals(Integer.valueOf(1), realm.getOtpPolicyLookAheadWindow());
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", "");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", " ");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
otpPolicyPage.form().setValues(OTPType.TIME_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", "no number");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
realm = testRealmResource().toRepresentation();
assertEquals(Integer.valueOf(30), realm.getOtpPolicyPeriod());
otpPolicyPage.form().setValues(OTPType.COUNTER_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", "");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
otpPolicyPage.form().setValues(OTPType.COUNTER_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", " ");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
otpPolicyPage.form().setValues(OTPType.COUNTER_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", "no number");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.form().setValues(OTPType.COUNTER_BASED, OTPHashAlg.SHA1, Digits.EMPTY, "1", "1 2");
assertEquals("Error! Missing or invalid field(s). Please verify the fields in red.", otpPolicyPage.getErrorMessage());
otpPolicyPage.closeNotification();
otpPolicyPage.navigateTo();
realm = testRealmResource().toRepresentation();
assertEquals(Integer.valueOf(0), realm.getOtpPolicyInitialCounter());