Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/org/labkey/test/LabKeySiteWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
26 changes: 21 additions & 5 deletions src/org/labkey/test/util/APIUserHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<CommandResponse>
{
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<CommandResponse>
{
private final String _password;
Expand Down
Loading