diff --git a/src/org/labkey/test/pages/compliance/ComplianceLoginSettingsPage.java b/src/org/labkey/test/pages/compliance/ComplianceLoginSettingsPage.java index a7a08d90aa..4a98846a22 100644 --- a/src/org/labkey/test/pages/compliance/ComplianceLoginSettingsPage.java +++ b/src/org/labkey/test/pages/compliance/ComplianceLoginSettingsPage.java @@ -2,7 +2,6 @@ import org.labkey.test.Locator; import org.labkey.test.WebDriverWrapper; -import org.labkey.test.components.ext4.ComboBox; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -22,49 +21,6 @@ public static ComplianceLoginSettingsPage beginAt(WebDriverWrapper webDriverWrap return new ComplianceLoginSettingsPage(webDriverWrapper.getDriver()); } - - public void enableLoginControls() - { - checkCheckbox(elementCache().enableLoginChk); - shortWait().until(wd -> elementCache().loginAttemptCountCombo.isEnabled()); - } - - public void disableLoginControls() - { - uncheckCheckbox(elementCache().enableLoginChk); - shortWait().until(wd -> !elementCache().loginAttemptCountCombo.isEnabled()); - } - - public void setLoginAttemptCount(String count) - { - setFormElement(elementCache().loginAttemptCountInput, count); - } - - public void selectLoginAttemptCount(String count) - { - elementCache().loginAttemptCountCombo.selectComboBoxItem(count); - } - - public void selectLoginAttemptPeriod(String period) - { - elementCache().loginAttemptPeriodCombo.selectComboBoxItem(period); - } - - public void selectLoginAttemptRecoveryTime(String time) - { - elementCache().loginAttemptRecoveryTimeCombo.selectComboBoxItem(time); - } - - public void setLoginAttemptRecoveryTime(String time) - { - setFormElement(elementCache().loginAttemptRecoveryTimeInput, time); - } - - public void setLoginAttemptPeriod(String time) - { - setFormElement(elementCache().loginAttemptPeriodInput, time); - } - public void enableFicamProviders() { checkCheckbox(elementCache().acceptOnlyFicamChk); @@ -105,16 +61,7 @@ protected ElementCache newElementCache() protected class ElementCache extends BaseComplianceSettingsPage.ElementCache { - final WebElement enableLoginChk = Locator.checkboxById("enableLogin").findWhenNeeded(this); - final ComboBox loginAttemptCountCombo = new ComboBox.ComboBoxFinder(getDriver()).locatedBy(Locator.tagWithId("span", "loginAttemptCount")).findWhenNeeded(this); - final ComboBox loginAttemptPeriodCombo = new ComboBox.ComboBoxFinder(getDriver()).locatedBy(Locator.tagWithId("span", "loginAttemptPeriod")).findWhenNeeded(this); - final ComboBox loginAttemptRecoveryTimeCombo = new ComboBox.ComboBoxFinder(getDriver()).locatedBy(Locator.tagWithId("span", "loginAttemptRecoveryTime")).findWhenNeeded(this); - final WebElement loginAttemptCountInput = Locator.input("attemptLimit").findWhenNeeded(this); - final WebElement loginAttemptPeriodInput = Locator.input("attemptPeriod").findWhenNeeded(this); - final WebElement loginAttemptRecoveryTimeInput = Locator.input("resetTime").findWhenNeeded(this); - final WebElement acceptOnlyFicamChk = Locator.checkboxById("acceptOnlyFICAMProviders").findWhenNeeded(this); final WebElement ficamProvidersDiv = Locator.tagWithId("div", "FICAMProviders").findWhenNeeded(this); - } } diff --git a/src/org/labkey/test/pages/core/login/LoginConfigurePage.java b/src/org/labkey/test/pages/core/login/LoginConfigurePage.java index 72cd4ec2d3..63a8c9a192 100644 --- a/src/org/labkey/test/pages/core/login/LoginConfigurePage.java +++ b/src/org/labkey/test/pages/core/login/LoginConfigurePage.java @@ -3,9 +3,10 @@ import org.labkey.test.Locator; import org.labkey.test.WebDriverWrapper; import org.labkey.test.WebTestHelper; +import org.labkey.test.components.html.BootstrapMenu; import org.labkey.test.components.html.Checkbox; +import org.labkey.test.components.html.SelectWrapper; import org.labkey.test.components.react.MultiMenu; -import org.labkey.test.components.html.BootstrapMenu; import org.labkey.test.components.react.Tabs; import org.labkey.test.pages.LabKeyPage; import org.labkey.test.pages.core.admin.ShowAdminPage; @@ -13,6 +14,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; import java.util.List; @@ -140,6 +142,52 @@ public LoginConfigRow getSecondaryConfigurationRow(String description) .withDescription(description).waitFor(toggleSecondaryConfiguration()); } + // Login attempt settings (in the Global Settings panel) + + public LoginConfigurePage setLoginAttemptEnabled(boolean enable) + { + elementCache().loginAttemptEnabledCheckbox.set(enable); + return this; + } + + public boolean getLoginAttemptEnabled() + { + return elementCache().loginAttemptEnabledCheckbox.get(); + } + + public LoginConfigurePage setLoginAttemptLimit(String value) + { + elementCache().loginAttemptLimitSelect.selectByValue(value); + return this; + } + + public String getLoginAttemptLimit() + { + return elementCache().loginAttemptLimitSelect.getFirstSelectedOption().getAttribute("value"); + } + + public LoginConfigurePage setLoginAttemptPeriod(String value) + { + elementCache().loginAttemptPeriodSelect.selectByValue(value); + return this; + } + + public String getLoginAttemptPeriod() + { + return elementCache().loginAttemptPeriodSelect.getFirstSelectedOption().getAttribute("value"); + } + + public LoginConfigurePage setLoginAttemptResetTime(String value) + { + elementCache().loginAttemptResetTimeSelect.selectByValue(value); + return this; + } + + public String getLoginAttemptResetTime() + { + return elementCache().loginAttemptResetTimeSelect.getFirstSelectedOption().getAttribute("value"); + } + public ShowAdminPage clickSaveAndFinish() { shortWait().until(ExpectedConditions.elementToBeClickable(elementCache().saveAndFinishBtn())); @@ -166,6 +214,11 @@ protected class ElementCache extends LabKeyPage.ElementCache .withText("Add New Secondary Configuration").timeout(WAIT_FOR_JAVASCRIPT); MultiMenu addSecondaryMenu = secondaryMenuFinder.findWhenNeeded(this); + Checkbox loginAttemptEnabledCheckbox = new Checkbox(this, "Limit unsuccessful login attempts"); + Select loginAttemptLimitSelect = SelectWrapper.Select(Locator.css("select[name='LoginAttemptLimit']")).findWhenNeeded(this); + Select loginAttemptPeriodSelect = SelectWrapper.Select(Locator.css("select[name='LoginAttemptPeriod']")).findWhenNeeded(this); + Select loginAttemptResetTimeSelect = SelectWrapper.Select(Locator.css("select[name='LoginAttemptResetTime']")).findWhenNeeded(this); + WebElement globalSettingsPanel() { return Locator.tagWithClass("div", "panel-default") diff --git a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java index a7e3b20568..12e1e2bc29 100644 --- a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java +++ b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java @@ -50,13 +50,23 @@ public static void setupProject() throws Exception { BaseUpgradeTest currentTest = BaseWebDriverTest.getCurrentTest(); + Class testClass = currentTest.getClass(); + String earliestVersion = Optional.ofNullable(testClass.getAnnotation(EarliestVersion.class)) + .map(EarliestVersion::value).orElse(null); + String latestVersion = Optional.ofNullable(testClass.getAnnotation(LatestVersion.class)) + .map(LatestVersion::value).orElse(null); + + Assume.assumeTrue("Test class not valid when upgrading from version: " + setupVersion, + VersionRange.versionRange(earliestVersion, latestVersion).contains(setupVersion) + ); + if (isUpgradeSetupPhase) { currentTest.doSetup(); } else { - TestLogger.info("Skipping setup for %s. Verifying upgrade.". formatted(currentTest.getClass().getSimpleName())); + TestLogger.info("Skipping setup for %s. Verifying upgrade.". formatted(testClass.getSimpleName())); } } @@ -100,19 +110,19 @@ protected boolean wasSetupWithin(String earliestVersion, String latestVersion) * Specifies the earliest version of the test class that performed the required setup for the annotated method. */ @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) + @Target({ElementType.METHOD, ElementType.TYPE}) protected @interface EarliestVersion { String value(); } /** - * Annotates test methods that should only run when upgrading from particular LabKey versions, as specified in - * {@code webtest.upgradePreviousVersion}.
- * Specifies the latest version of the test class that performed the required setup for the annotated method. + * Annotates test methods or classes that should only run when upgrading from particular LabKey versions, as + * specified in {@code webtest.upgradePreviousVersion}.
+ * Specifies the latest version of the test class that performed the required setup for the annotated method or class. */ @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) + @Target({ElementType.METHOD, ElementType.TYPE}) protected @interface LatestVersion { String value(); } diff --git a/src/org/labkey/test/util/VersionRange.java b/src/org/labkey/test/util/VersionRange.java index 865974783e..083c425336 100644 --- a/src/org/labkey/test/util/VersionRange.java +++ b/src/org/labkey/test/util/VersionRange.java @@ -14,15 +14,13 @@ public class VersionRange * * @param earliestVersion The earliest version in the range (inclusive). If null, there is no lower bound. * @param latestVersion The latest version in the range (inclusive). If null, there is no upper bound. - * @throws IllegalArgumentException if both versions are null, or if earliestVersion is after latestVersion. + * @throws IllegalArgumentException if earliestVersion is after latestVersion. */ public VersionRange(Version earliestVersion, Version latestVersion) { this.earliestVersion = earliestVersion; this.latestVersion = latestVersion; - if (earliestVersion == null && latestVersion == null) - throw new IllegalArgumentException("Version range requires at least one version"); if (earliestVersion != null && latestVersion != null && earliestVersion.compareTo(latestVersion) > 0) throw new IllegalArgumentException("%s is after %s".formatted(earliestVersion, latestVersion));