-
Notifications
You must be signed in to change notification settings - Fork 9
Test remember terms-of-use acceptance #3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+74
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
| 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see setTermsOfUseFrequency action in AdminController.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.