Skip to content
Snippets Groups Projects
Commit 47c39912 authored by Vincent Massol's avatar Vincent Massol
Browse files

[Misc] Move more admin tests to docker-based tests

parent 01383d2b
No related merge requests found
...@@ -59,6 +59,17 @@ ...@@ -59,6 +59,17 @@
<artifactId>xwiki-platform-refactoring-default</artifactId> <artifactId>xwiki-platform-refactoring-default</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- We currently need to depend on mail-ui in the test because it contains the Mail.SendMailConfigClass. We can
not have administration-ui depend on mail-ui, because mail-ui already depends on administration-ui which would
create a loop. mail-ui ust needs the configurable class stuff from administration-ui, so when that gets
refactored out, we can fix the dependency directly in administration-ui and not have anything here specific to
mail. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-mail-ui</artifactId>
<version>${project.version}</version>
<type>xar</type>
</dependency>
<!-- ================================ <!-- ================================
Test only dependencies Test only dependencies
================================ --> ================================ -->
...@@ -74,17 +85,6 @@ ...@@ -74,17 +85,6 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- We currently need to depend on mail-ui in the test because it contains the Mail.SendMailConfigClass. We can
not have administration-ui depend on mail-ui, because mail-ui already depends on administration-ui which would
create a loop. mail-ui ust needs the configurable class stuff from administration-ui, so when that gets
refactored out, we can fix the dependency directly in administration-ui and not have anything here specific to
mail. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-mail-ui</artifactId>
<version>${project.version}</version>
<type>xar</type>
</dependency>
<dependency> <dependency>
<groupId>com.icegreen</groupId> <groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId> <artifactId>greenmail</artifactId>
......
...@@ -29,7 +29,24 @@ ...@@ -29,7 +29,24 @@
* @version $Id$ * @version $Id$
* @since 11.2RC1 * @since 11.2RC1
*/ */
@UITest @UITest(sshPorts = {
// Open the GreenMail port so that the XWiki instance inside a Docker container can use the SMTP server provided
// by GreenMail running on the host.
3025
},
properties = {
// The Mail module contributes a Hibernate mapping that needs to be added to hibernate.cfg.xml
"xwikiDbHbmCommonExtraMappings=mailsender.hbm.xml",
// Pages created in the tests need to have PR since we ask for PR to send mails so we need to exclude them from
// the PR checker.
"xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:XWiki\\.ResetPassword|.*:XWiki\\.ResetPasswordComplete"
},
extraJARs = {
// It's currently not possible to install a JAR contributing a Hibernate mapping file as an Extension. Thus
// we need to provide the JAR inside WEB-INF/lib -->
"org.xwiki.platform:xwiki-platform-mail-send-storage"
}
)
public class AllIT public class AllIT
{ {
@Nested @Nested
......
...@@ -31,86 +31,91 @@ ...@@ -31,86 +31,91 @@
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Rule;
import org.junit.Test;
import org.xwiki.administration.test.po.ResetPasswordCompletePage; import org.xwiki.administration.test.po.ResetPasswordCompletePage;
import org.xwiki.administration.test.po.ResetPasswordPage; import org.xwiki.administration.test.po.ResetPasswordPage;
import org.xwiki.test.ui.AbstractTest; import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.SuperAdminAuthenticationRule; import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.LoginPage; import org.xwiki.test.ui.po.LoginPage;
import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetupTest; import com.icegreen.greenmail.util.ServerSetupTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Verify the Reset Password feature. * Verify the Reset Password feature.
* *
* @version $Id$ * @version $Id$
* @since 7.0M2 * @since 7.0M2
*/ */
public class ResetPasswordIT extends AbstractTest @UITest(sshPorts = {
// Open the GreenMail port so that the XWiki instance inside a Docker container can use the SMTP server provided
// by GreenMail running on the host.
3025
},
properties = {
// The Mail module contributes a Hibernate mapping that needs to be added to hibernate.cfg.xml
"xwikiDbHbmCommonExtraMappings=mailsender.hbm.xml",
// Pages created in the tests need to have PR since we ask for PR to send mails so we need to exclude them from
// the PR checker.
"xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:XWiki\\.ResetPassword|.*:XWiki\\.ResetPasswordComplete"
},
extraJARs = {
// It's currently not possible to install a JAR contributing a Hibernate mapping file as an Extension. Thus
// we need to provide the JAR inside WEB-INF/lib -->
"org.xwiki.platform:xwiki-platform-mail-send-storage"
}
)
public class ResetPasswordIT
{ {
@Rule
public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
private GreenMail mail; private GreenMail mail;
@Before @BeforeEach
public void startMail() public void startMail(TestUtils setup)
{ {
this.mail = new GreenMail(ServerSetupTest.SMTP); this.mail = new GreenMail(ServerSetupTest.SMTP);
this.mail.start(); this.mail.start();
configureEmail(); configureEmail(setup);
} }
@After @AfterEach
public void stopMail() public void stopMail(TestUtils setup)
{ {
if (this.mail != null) { if (this.mail != null) {
this.mail.stop(); this.mail.stop();
} }
restoreSettings(); restoreSettings(setup);
}
private void configureEmail()
{
getUtil().updateObject("Mail", "MailConfig", "Mail.SendMailConfigClass", 0, "host", "localhost", "port",
"3025", "sendWaitTime", "0");
}
private void restoreSettings()
{
// Make sure we can restore the settings, so we log back with superadmin to finish the work
getUtil().loginAsSuperAdmin();
// Remove the previous version that the setup has created.
getUtil().deleteLatestVersion("Mail", "MailConfig");
} }
@Test @Test
public void resetForgottenPassword() throws Exception public void resetForgottenPassword(TestUtils setup) throws Exception
{ {
setup.loginAsSuperAdmin();
String userName = "testUser" + RandomStringUtils.randomAlphanumeric(6); String userName = "testUser" + RandomStringUtils.randomAlphanumeric(6);
String password = "password"; String password = "password";
String newPassword = "newPassword"; String newPassword = "newPassword";
// Create a user // Create a user
getUtil().createUser(userName, password, null); setup.createUser(userName, password, null);
// Make sure we are not logged in and go to the reset password page // Make sure we are not logged in and go to the reset password page
getUtil().forceGuestUser(); setup.forceGuestUser();
ResetPasswordPage resetPasswordPage = ResetPasswordPage.gotoPage(); ResetPasswordPage resetPasswordPage = ResetPasswordPage.gotoPage();
// Try to reset the password of a non existent user // Try to reset the password of a non existent user
resetPasswordPage.setUserName("SomeUserThatDoesNotExist"); resetPasswordPage.setUserName("SomeUserThatDoesNotExist");
resetPasswordPage.clickResetPassword(); resetPasswordPage.clickResetPassword();
Assert.assertFalse(resetPasswordPage.isResetPasswordSent()); assertFalse(resetPasswordPage.isResetPasswordSent());
Assert.assertTrue(resetPasswordPage.getMessage().contains("user does not exist")); assertTrue(resetPasswordPage.getMessage().contains("user does not exist"));
// Try again // Try again
resetPasswordPage = resetPasswordPage.clickRetry(); resetPasswordPage = resetPasswordPage.clickRetry();
...@@ -118,14 +123,14 @@ public void resetForgottenPassword() throws Exception ...@@ -118,14 +123,14 @@ public void resetForgottenPassword() throws Exception
// Try to reset the password of our user, when he has no email set // Try to reset the password of our user, when he has no email set
resetPasswordPage.setUserName(userName); resetPasswordPage.setUserName(userName);
resetPasswordPage.clickResetPassword(); resetPasswordPage.clickResetPassword();
Assert.assertFalse(resetPasswordPage.isResetPasswordSent()); assertFalse(resetPasswordPage.isResetPasswordSent());
Assert.assertTrue(resetPasswordPage.getMessage().contains("email address not provided")); assertTrue(resetPasswordPage.getMessage().contains("email address not provided"));
// Try again. This time, set the user's email address in the profile // Try again. This time, set the user's email address in the profile
getUtil().loginAsSuperAdmin(); setup.loginAsSuperAdmin();
getUtil().updateObject("XWiki", userName, "XWiki.XWikiUsers", 0, "email", "foo@bar.com", "form_token", setup.updateObject("XWiki", userName, "XWiki.XWikiUsers", 0, "email", "foo@bar.com", "form_token",
getUtil().getSecretToken()); setup.getSecretToken());
getUtil().forceGuestUser(); setup.forceGuestUser();
// Actually reset the user's password // Actually reset the user's password
resetPasswordPage = ResetPasswordPage.gotoPage(); resetPasswordPage = ResetPasswordPage.gotoPage();
...@@ -133,41 +138,41 @@ public void resetForgottenPassword() throws Exception ...@@ -133,41 +138,41 @@ public void resetForgottenPassword() throws Exception
resetPasswordPage.clickResetPassword(); resetPasswordPage.clickResetPassword();
// Check the result // Check the result
Assert.assertTrue(resetPasswordPage.isResetPasswordSent()); assertTrue(resetPasswordPage.isResetPasswordSent());
// Check the emails received by the user // Check the emails received by the user
MimeMessage[] receivedEmails = this.mail.getReceivedMessages(); MimeMessage[] receivedEmails = this.mail.getReceivedMessages();
Assert.assertEquals(1, receivedEmails.length); assertEquals(1, receivedEmails.length);
MimeMessage receivedEmail = receivedEmails[0]; MimeMessage receivedEmail = receivedEmails[0];
Assert.assertEquals("Password reset request for " + userName, receivedEmail.getSubject()); assertEquals("Password reset request for " + userName, receivedEmail.getSubject());
String receivedMailContent = getMessageContent(receivedEmail).get("textPart"); String receivedMailContent = getMessageContent(receivedEmail).get("textPart");
String passwordResetLink = getResetLink(receivedMailContent, "xwiki%3AXWiki." + userName); String passwordResetLink = getResetLink(receivedMailContent, "xwiki%3AXWiki." + userName);
Assert.assertNotNull(passwordResetLink); assertNotNull(passwordResetLink);
// Use the password reset link // Use the password reset link
getUtil().gotoPage(passwordResetLink); setup.gotoPage(passwordResetLink);
// We should now be on the ResetPasswordComplete page // We should now be on the ResetPasswordComplete page
ResetPasswordCompletePage resetPasswordCompletePage = new ResetPasswordCompletePage(); ResetPasswordCompletePage resetPasswordCompletePage = new ResetPasswordCompletePage();
// Check that the link was valid // Check that the link was valid
Assert.assertTrue(resetPasswordCompletePage.isResetLinkValid()); assertTrue(resetPasswordCompletePage.isResetLinkValid());
resetPasswordCompletePage.setPassword(newPassword); resetPasswordCompletePage.setPassword(newPassword);
resetPasswordCompletePage.setPasswordConfirmation(newPassword); resetPasswordCompletePage.setPasswordConfirmation(newPassword);
resetPasswordCompletePage = resetPasswordCompletePage.clickSave(); resetPasswordCompletePage = resetPasswordCompletePage.clickSave();
// Check the result // Check the result
Assert.assertTrue(resetPasswordCompletePage.isPasswordSuccessfullyReset()); assertTrue(resetPasswordCompletePage.isPasswordSuccessfullyReset());
LoginPage loginPage = resetPasswordCompletePage.clickLogin(); LoginPage loginPage = resetPasswordCompletePage.clickLogin();
// Check the new password // Check the new password
loginPage.loginAs(userName, newPassword); loginPage.loginAs(userName, newPassword);
Assert.assertEquals(userName, getUtil().getLoggedInUserName()); assertEquals(userName, setup.getLoggedInUserName());
} }
protected Map<String, String> getMessageContent(MimeMessage message) throws Exception private Map<String, String> getMessageContent(MimeMessage message) throws Exception
{ {
Map<String, String> messageMap = new HashMap<String, String>(); Map<String, String> messageMap = new HashMap<>();
Address[] addresses = message.getAllRecipients(); Address[] addresses = message.getAllRecipients();
Assert.assertTrue(addresses.length == 1); assertTrue(addresses.length == 1);
messageMap.put("recipient", addresses[0].toString()); messageMap.put("recipient", addresses[0].toString());
messageMap.put("subjectLine", message.getSubject()); messageMap.put("subjectLine", message.getSubject());
...@@ -176,17 +181,17 @@ protected Map<String, String> getMessageContent(MimeMessage message) throws Exce ...@@ -176,17 +181,17 @@ protected Map<String, String> getMessageContent(MimeMessage message) throws Exce
BodyPart plain = getPart(mp, "text/plain"); BodyPart plain = getPart(mp, "text/plain");
if (plain != null) { if (plain != null) {
messageMap.put("textPart", IOUtils.toString(plain.getInputStream())); messageMap.put("textPart", IOUtils.toString(plain.getInputStream(), "UTF-8"));
} }
BodyPart html = getPart(mp, "text/html"); BodyPart html = getPart(mp, "text/html");
if (html != null) { if (html != null) {
messageMap.put("htmlPart", IOUtils.toString(html.getInputStream())); messageMap.put("htmlPart", IOUtils.toString(html.getInputStream(), "UTF-8"));
} }
return messageMap; return messageMap;
} }
protected BodyPart getPart(Multipart messageContent, String mimeType) throws Exception private BodyPart getPart(Multipart messageContent, String mimeType) throws Exception
{ {
for (int i = 0; i < messageContent.getCount(); i++) { for (int i = 0; i < messageContent.getCount(); i++) {
BodyPart part = messageContent.getBodyPart(i); BodyPart part = messageContent.getBodyPart(i);
...@@ -196,7 +201,8 @@ protected BodyPart getPart(Multipart messageContent, String mimeType) throws Exc ...@@ -196,7 +201,8 @@ protected BodyPart getPart(Multipart messageContent, String mimeType) throws Exc
} }
if (part.isMimeType("multipart/related") || part.isMimeType("multipart/alternative") if (part.isMimeType("multipart/related") || part.isMimeType("multipart/alternative")
|| part.isMimeType("multipart/mixed")) { || part.isMimeType("multipart/mixed"))
{
BodyPart out = getPart((Multipart) part.getContent(), mimeType); BodyPart out = getPart((Multipart) part.getContent(), mimeType);
if (out != null) { if (out != null) {
return out; return out;
...@@ -219,4 +225,19 @@ private String getResetLink(String emailContent, String userName) ...@@ -219,4 +225,19 @@ private String getResetLink(String emailContent, String userName)
return result; return result;
} }
private void configureEmail(TestUtils setup)
{
setup.updateObject("Mail", "MailConfig", "Mail.SendMailConfigClass", 0, "host", "localhost", "port",
"3025", "sendWaitTime", "0");
}
private void restoreSettings(TestUtils setup)
{
// Make sure we can restore the settings, so we log back with superadmin to finish the work
setup.loginAsSuperAdmin();
// Remove the previous version that the setup has created.
setup.deleteLatestVersion("Mail", "MailConfig");
}
} }
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
3025 3025
}, },
properties = { properties = {
// The Mail module contribures a Hibernate mapping that needs to be added to hibernate.cfg.xml // The Mail module contributes a Hibernate mapping that needs to be added to hibernate.cfg.xml
"xwikiDbHbmCommonExtraMappings=mailsender.hbm.xml", "xwikiDbHbmCommonExtraMappings=mailsender.hbm.xml",
// Pages created in the tests need to have PR since we ask for PR to send mails so we need to exclude them from // Pages created in the tests need to have PR since we ask for PR to send mails so we need to exclude them from
// the PR checker. // the PR checker.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment