Skip to content

Commit

Permalink
LPD-38816 Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
evibudai committed Oct 29, 2024
1 parent 9d288f9 commit fce714f
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.liferay.portal.security.auto.login.test;

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.action.UpdatePasswordAction;
import com.liferay.portal.kernel.model.Company;
Expand All @@ -29,11 +30,18 @@
import com.liferay.portal.kernel.test.util.UserTestUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.struts.Action;
import com.liferay.portal.test.rule.Inject;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.net.HttpURLConnection;
import java.net.URL;

import java.util.Date;

import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -81,6 +89,44 @@ public void testExecute() throws Exception {
company.getCompanyId(), user.getEmailAddress());

Assert.assertNotNull(user.getLastLoginDate());

// Update password returns alert message when the ticket is no longer valid

URL url = new URL(
StringBundler.concat(
"http://localhost:8080/c/portal/update_password?languageId=",
user.getLanguageId(), "&ticketId=", _ticketId, "&ticketKey=",
_ticketKey));

HttpURLConnection connection = (HttpURLConnection)url.openConnection();

connection.setRequestMethod("GET");
connection.setRequestMethod("GET");

BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));

boolean findText = false;
String searchText = "Your password reset link is no longer valid";

StringBuilder response = new StringBuilder();
String line;

while (((line = reader.readLine()) != null) && !findText) {
findText = line.contains(searchText);

if (findText) {
response.append(StringUtil.trim(line));
}
}

reader.close();

Assert.assertTrue(
response.toString(
).contains(
searchText
));
}

private MockHttpServletRequest _mockHttpServletRequest(
Expand Down Expand Up @@ -128,6 +174,9 @@ private MockHttpServletRequest _mockHttpServletRequest(
TicketConstants.TYPE_PASSWORD, null, expirationDate,
new ServiceContext());

_ticketId = String.valueOf(ticket.getTicketId());
_ticketKey = ticket.getKey();

mockHttpServletRequest.setParameter(
"ticketId", String.valueOf(ticket.getTicketId()));
mockHttpServletRequest.setParameter("ticketKey", ticket.getKey());
Expand All @@ -149,6 +198,9 @@ private MockHttpServletRequest _mockHttpServletRequest(
return mockHttpServletRequest;
}

private String _ticketId;
private String _ticketKey;

@Inject
private TicketLocalService _ticketLocalService;

Expand Down

0 comments on commit fce714f

Please sign in to comment.