From 8acbd2d2953748d8465230570f8c94b248ea26fe Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 20 Oct 2026 21:34:11 -0700 Subject: [PATCH] Database readers can take over accounts that have a pending setup or reset link --- src/org/labkey/test/LabKeySiteWrapper.java | 1 + .../core/login/SetPasswordForm.java | 1 + src/org/labkey/test/util/APIUserHelper.java | 26 +++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/org/labkey/test/LabKeySiteWrapper.java b/src/org/labkey/test/LabKeySiteWrapper.java index d277990120..b79da667f3 100644 --- a/src/org/labkey/test/LabKeySiteWrapper.java +++ b/src/org/labkey/test/LabKeySiteWrapper.java @@ -464,6 +464,7 @@ protected String setInitialPassword(int userId) protected String getPasswordResetUrl(int userId) { beginAt(buildURL("security", "showResetEmail", Map.of("userId", userId))); + clickButton("Generate New Link"); WebElement resetLink = Locator.xpath("//a[contains(@href, 'setPassword.view')]").findElement(getDriver()); shortWait().until(ExpectedConditions.elementToBeClickable(resetLink)); diff --git a/src/org/labkey/test/components/core/login/SetPasswordForm.java b/src/org/labkey/test/components/core/login/SetPasswordForm.java index d978b0313c..2c16ca0116 100644 --- a/src/org/labkey/test/components/core/login/SetPasswordForm.java +++ b/src/org/labkey/test/components/core/login/SetPasswordForm.java @@ -73,6 +73,7 @@ public SetPasswordForm(WebDriver driver) public static SetPasswordForm goToInitialPasswordForUser(WebDriverWrapper wrapper, int userId) { wrapper.beginAt(WebTestHelper.buildURL("security", "showRegistrationEmail", Map.of("userId", userId))); + wrapper.clickButton("Generate New Link"); // Get setPassword URL from notification email. WebElement resetLink = Locator.linkWithHref("setPassword.view").findElement(wrapper.getDriver()); diff --git a/src/org/labkey/test/util/APIUserHelper.java b/src/org/labkey/test/util/APIUserHelper.java index b765198994..7978d5552b 100644 --- a/src/org/labkey/test/util/APIUserHelper.java +++ b/src/org/labkey/test/util/APIUserHelper.java @@ -27,7 +27,6 @@ import org.labkey.remoteapi.CommandResponse; import org.labkey.remoteapi.Connection; import org.labkey.remoteapi.PostCommand; -import org.labkey.remoteapi.SimpleGetCommand; import org.labkey.remoteapi.SimplePostCommand; import org.labkey.remoteapi.security.CreateUserCommand; import org.labkey.remoteapi.security.CreateUserResponse; @@ -262,10 +261,7 @@ public String setInitialPassword(int userId) try { - SimpleGetCommand getRegEmailCommand = new SimpleGetCommand("security", "showRegistrationEmail"); - getRegEmailCommand.setParameters(Map.of("userId", userId)); - - String responseText = getRegEmailCommand.execute(connectionSupplier.get(), null).getText(); + String responseText = new GenerateRegistrationLinkCommand(userId).execute(connectionSupplier.get(), null).getText(); Matcher matcher = regEmailVerification.matcher(responseText); if (matcher.find()) @@ -324,6 +320,26 @@ private void updateUsersState(boolean activate, boolean delete, int... userIds) } } +// Replaces the user's verification token and returns the registration email containing the new link +class GenerateRegistrationLinkCommand extends PostCommand +{ + private final int _userId; + + public GenerateRegistrationLinkCommand(int userId) + { + super("security", "showRegistrationEmail"); + _userId = userId; + } + + @Override + protected HttpPost createRequest(URI uri) + { + HttpPost request = new HttpPost(uri); + request.setEntity(new UrlEncodedFormEntity(List.of(new BasicNameValuePair("userId", String.valueOf(_userId))))); + return request; + } +} + class SetPasswordCommand extends PostCommand { private final String _password;