|
15 | 15 | */ |
16 | 16 | package org.labkey.test.tests; |
17 | 17 |
|
| 18 | +import org.apache.hc.core5.http.HttpStatus; |
18 | 19 | import org.junit.Before; |
19 | 20 | import org.junit.Test; |
20 | 21 | import org.junit.experimental.categories.Category; |
| 22 | +import org.labkey.remoteapi.CommandException; |
| 23 | +import org.labkey.remoteapi.CommandResponse; |
| 24 | +import org.labkey.remoteapi.Connection; |
| 25 | +import org.labkey.remoteapi.SimplePostCommand; |
21 | 26 | import org.labkey.test.BaseWebDriverTest; |
22 | 27 | import org.labkey.test.Locator; |
23 | 28 | import org.labkey.test.Locators; |
24 | 29 | import org.labkey.test.TestTimeoutException; |
| 30 | +import org.labkey.test.WebTestHelper; |
25 | 31 | import org.labkey.test.categories.Daily; |
26 | 32 | import org.labkey.test.util.PasswordUtil; |
27 | 33 | import org.openqa.selenium.WebElement; |
28 | 34 |
|
| 35 | +import java.io.IOException; |
| 36 | +import java.util.Map; |
| 37 | + |
29 | 38 | import static org.junit.Assert.assertEquals; |
30 | 39 | import static org.junit.Assert.assertFalse; |
| 40 | +import static org.junit.Assert.assertTrue; |
31 | 41 |
|
32 | 42 | @Category({Daily.class}) |
33 | 43 | @BaseWebDriverTest.ClassTimeout(minutes = 7) |
@@ -232,6 +242,64 @@ public void testFailedLoginBadPassword() |
232 | 242 | waitForText(SITE_WIDE_TERMS_TEXT); // should show |
233 | 243 | } |
234 | 244 |
|
| 245 | + private final static int FREQUENCY_SECONDS = 10; |
| 246 | + |
| 247 | + @Test |
| 248 | + public void testRememberMeTerms() throws IOException, CommandException |
| 249 | + { |
| 250 | + log("Testing \"Require terms-of-use acceptance\" set to " + FREQUENCY_SECONDS + " seconds"); |
| 251 | + |
| 252 | + // Remember terms acceptance for FREQUENCY_SECONDS |
| 253 | + setFrequency(FREQUENCY_SECONDS); |
| 254 | + boolean firstSignIn = true; |
| 255 | + boolean secondAcceptance = false; |
| 256 | + long firstAcceptance = 0; |
| 257 | + long diff; |
| 258 | + |
| 259 | + // Sign out and back in again for up to FREQUENCY_SECONDS * 1.5 seconds |
| 260 | + double max_millis = FREQUENCY_SECONDS * 1.5 * 1000; |
| 261 | + do |
| 262 | + { |
| 263 | + simpleSignOut(); |
| 264 | + // Terms dialog doesn't show a sign-in link, so navigate directly to the login page |
| 265 | + beginAt(WebTestHelper.buildURL("login", "login")); |
| 266 | + assertTextNotPresent(SITE_WIDE_TERMS_TEXT); |
| 267 | + doAndWaitForPageToLoad(() -> fillSignInFormAndSubmit("Sign In")); |
| 268 | + if (isTextPresent(SITE_WIDE_TERMS_TEXT)) |
| 269 | + { |
| 270 | + acceptTermsOfUse(SITE_WIDE_TERMS_TEXT, true); |
| 271 | + if (firstSignIn) |
| 272 | + { |
| 273 | + firstAcceptance = System.currentTimeMillis(); |
| 274 | + firstSignIn = false; |
| 275 | + } |
| 276 | + else |
| 277 | + { |
| 278 | + secondAcceptance = true; |
| 279 | + } |
| 280 | + } |
| 281 | + diff = System.currentTimeMillis() - firstAcceptance; |
| 282 | + } |
| 283 | + while (!secondAcceptance && !firstSignIn && diff < max_millis); |
| 284 | + |
| 285 | + assertFalse("First sign in didn't result in TOU!", firstSignIn); |
| 286 | + assertTrue("First acceptance time was 0!", firstAcceptance > 0); |
| 287 | + assertTrue("Second acceptance didn't occur within 15 seconds!", diff < max_millis); |
| 288 | + assertFalse("Second acceptance occurred too early (" + diff + "ms)", diff < FREQUENCY_SECONDS * 1000); |
| 289 | + |
| 290 | + setFrequency(0); |
| 291 | + } |
| 292 | + |
| 293 | + private void setFrequency(int frequency) throws IOException, CommandException |
| 294 | + { |
| 295 | + // Use direct API call to set a value that may not appear in the drop-down list |
| 296 | + Connection conn = createDefaultConnection(); |
| 297 | + SimplePostCommand frequencyCommand = new SimplePostCommand("admin", "setTermsOfUseFrequency"); |
| 298 | + frequencyCommand.setParameters(Map.of("seconds", frequency)); |
| 299 | + CommandResponse response = frequencyCommand.execute(conn, "/"); |
| 300 | + assertEquals(HttpStatus.SC_OK, response.getStatusCode()); |
| 301 | + } |
| 302 | + |
235 | 303 | protected void signOutWithSiteWideTerms(String termsText, boolean acceptTerms) |
236 | 304 | { |
237 | 305 | log("Signing out"); |
|
0 commit comments