Skip to content

Commit a7d06bf

Browse files
committed
Test remember terms-of-use acceptance
1 parent bd4e666 commit a7d06bf

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

src/org/labkey/test/tests/SiteWideTermsOfUseTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,29 @@
1515
*/
1616
package org.labkey.test.tests;
1717

18+
import org.apache.hc.core5.http.HttpStatus;
1819
import org.junit.Before;
1920
import org.junit.Test;
2021
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;
2126
import org.labkey.test.BaseWebDriverTest;
2227
import org.labkey.test.Locator;
2328
import org.labkey.test.Locators;
2429
import org.labkey.test.TestTimeoutException;
30+
import org.labkey.test.WebTestHelper;
2531
import org.labkey.test.categories.Daily;
2632
import org.labkey.test.util.PasswordUtil;
2733
import org.openqa.selenium.WebElement;
2834

35+
import java.io.IOException;
36+
import java.util.Map;
37+
2938
import static org.junit.Assert.assertEquals;
3039
import static org.junit.Assert.assertFalse;
40+
import static org.junit.Assert.assertTrue;
3141

3242
@Category({Daily.class})
3343
@BaseWebDriverTest.ClassTimeout(minutes = 7)
@@ -232,6 +242,64 @@ public void testFailedLoginBadPassword()
232242
waitForText(SITE_WIDE_TERMS_TEXT); // should show
233243
}
234244

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+
235303
protected void signOutWithSiteWideTerms(String termsText, boolean acceptTerms)
236304
{
237305
log("Signing out");

0 commit comments

Comments
 (0)