Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/org/labkey/test/tests/SiteWideTermsOfUseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.SimplePostCommand;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.Locators;
import org.labkey.test.TestTimeoutException;
import org.labkey.test.WebTestHelper;
import org.labkey.test.categories.Daily;
import org.labkey.test.util.PasswordUtil;
import org.openqa.selenium.WebElement;

import java.io.IOException;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@Category({Daily.class})
@BaseWebDriverTest.ClassTimeout(minutes = 7)
Expand Down Expand Up @@ -89,6 +97,7 @@ public void editTermsAdminConsoleLinkTest()
protected void assureSiteWideTermsOfUsePage()
{
createTermsOfUsePage(null, SITE_WIDE_TERMS_TEXT);
setFrequency(0);
}

// Test that the site-wide terms appear when you log out, even if you've accepted the terms when logged in
Expand Down Expand Up @@ -232,6 +241,71 @@ public void testFailedLoginBadPassword()
waitForText(SITE_WIDE_TERMS_TEXT); // should show
}

private final static int FREQUENCY_SECONDS = 10;

@Test
public void testRememberMeTerms()
{
log("Testing \"Require terms-of-use acceptance\" set to " + FREQUENCY_SECONDS + " seconds");

// Remember terms acceptance for FREQUENCY_SECONDS
setFrequency(FREQUENCY_SECONDS);
boolean firstSignIn = true;
boolean secondAcceptance = false;
long firstAcceptance = 0;
long diff;

// Sign out and back in again for up to FREQUENCY_SECONDS * 1.5 seconds
double max_millis = FREQUENCY_SECONDS * 1.5 * 1000;
do
{
simpleSignOut();
// Terms dialog doesn't show a sign-in link, so navigate directly to the login page
beginAt(WebTestHelper.buildURL("login", "login"));
assertTextNotPresent(SITE_WIDE_TERMS_TEXT);
doAndWaitForPageToLoad(() -> fillSignInFormAndSubmit("Sign In"));
if (isTextPresent(SITE_WIDE_TERMS_TEXT))
{
acceptTermsOfUse(SITE_WIDE_TERMS_TEXT, true);
if (firstSignIn)
{
firstAcceptance = System.currentTimeMillis();
firstSignIn = false;
}
else
{
secondAcceptance = true;
}
}
diff = System.currentTimeMillis() - firstAcceptance;
}
while (!secondAcceptance && !firstSignIn && diff < max_millis);

assertFalse("First sign in didn't result in TOU!", firstSignIn);
assertTrue("First acceptance time was 0!", firstAcceptance > 0);
assertTrue("Second acceptance didn't occur within 15 seconds!", diff < max_millis);
assertFalse("Second acceptance occurred too early (" + diff + "ms)", diff < FREQUENCY_SECONDS * 1000);

// Back to every sign-in
setFrequency(0);
Comment thread
labkey-adam marked this conversation as resolved.
}

private void setFrequency(int frequency)
{
// Use direct API call to set a value that may not appear in the drop-down list
Connection conn = createDefaultConnection();
SimplePostCommand frequencyCommand = new SimplePostCommand("admin", "setTermsOfUseFrequency");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see setTermsOfUseFrequency action in AdminController.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git pull on platform

frequencyCommand.setParameters(Map.of("seconds", frequency));
try
{
frequencyCommand.execute(conn, "/");
}
catch (IOException | CommandException e)
{
throw new RuntimeException(e);
}
}

protected void signOutWithSiteWideTerms(String termsText, boolean acceptTerms)
{
log("Signing out");
Expand Down