1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui.invitation; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.mail.Address; |
27 |
|
import javax.mail.BodyPart; |
28 |
|
import javax.mail.Multipart; |
29 |
|
import javax.mail.internet.MimeMessage; |
30 |
|
|
31 |
|
import org.junit.Assert; |
32 |
|
import org.junit.Before; |
33 |
|
import org.junit.Test; |
34 |
|
import org.openqa.selenium.By; |
35 |
|
import org.openqa.selenium.WebElement; |
36 |
|
import org.xwiki.administration.test.po.AdministrationSectionPage; |
37 |
|
import org.xwiki.invitation.test.po.InspectInvitationsPage; |
38 |
|
import org.xwiki.invitation.test.po.InvitationActionConfirmationElement; |
39 |
|
import org.xwiki.invitation.test.po.InvitationGuestActionsPage; |
40 |
|
import org.xwiki.invitation.test.po.InvitationMessageDisplayElement; |
41 |
|
import org.xwiki.invitation.test.po.InvitationSenderPage; |
42 |
|
import org.xwiki.test.ui.AbstractTest; |
43 |
|
import org.xwiki.test.ui.TestUtils; |
44 |
|
import org.xwiki.test.ui.browser.IgnoreBrowser; |
45 |
|
import org.xwiki.test.ui.browser.IgnoreBrowsers; |
46 |
|
import org.xwiki.test.ui.po.RegistrationPage; |
47 |
|
import org.xwiki.test.ui.po.TableElement; |
48 |
|
import org.xwiki.test.ui.po.editor.ObjectEditPage; |
49 |
|
|
50 |
|
import com.icegreen.greenmail.util.GreenMail; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@version |
56 |
|
@since |
57 |
|
|
|
|
| 96.2% |
Uncovered Elements: 14 (369) |
Complexity: 32 |
Complexity Density: 0.1 |
|
58 |
|
public class InvitationTest extends AbstractTest |
59 |
|
{ |
60 |
|
private static boolean initialized; |
61 |
|
|
62 |
|
private InvitationSenderPage senderPage; |
63 |
|
|
64 |
|
private GreenMail greenMail; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
66 |
11 |
@Before... |
67 |
|
public void setUp() throws Exception |
68 |
|
{ |
69 |
|
|
70 |
11 |
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(getUtil().getURLToNonExistentPage())); |
71 |
11 |
getUtil().recacheSecretToken(); |
72 |
11 |
getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS); |
73 |
11 |
getUtil().rest().deletePage("Invitation", "InvitationMessages"); |
74 |
|
|
75 |
11 |
if (!initialized) { |
76 |
|
|
77 |
1 |
InvitationSenderPage.gotoPage(); |
78 |
|
|
79 |
1 |
AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation"); |
80 |
|
|
81 |
1 |
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_smtp_port"), |
82 |
|
"3025"); |
83 |
|
|
84 |
1 |
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" |
85 |
|
+ "usersMaySendToMultiple"), "false"); |
86 |
1 |
config.clickSave(); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
1 |
getUtil().rest().deletePage("XWiki", "InvitedMember"); |
93 |
1 |
getUtil().rest().deletePage("XWiki", "AnotherInvitedMember"); |
94 |
|
|
95 |
1 |
initialized = true; |
96 |
|
} |
97 |
|
|
98 |
11 |
setSenderPage(InvitationSenderPage.gotoPage()); |
99 |
11 |
getSenderPage().fillInDefaultValues(); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void testGuestActionsOnNonexistantMessage() throws Exception |
104 |
|
{ |
105 |
1 |
TestUtils.Session s = getUtil().getSession(); |
106 |
1 |
try { |
107 |
1 |
getUtil().forceGuestUser(); |
108 |
|
|
109 |
|
|
110 |
1 |
getUtil().gotoPage("Invitation", "InvitationGuestActions", "view", "doAction_accept&messageID=12345"); |
111 |
1 |
InvitationGuestActionsPage guestPage = new InvitationGuestActionsPage(); |
112 |
1 |
Assert.assertNotNull("Guests able to accept nonexistent invitation", guestPage.getMessage()); |
113 |
1 |
Assert.assertEquals("No message was found by the given ID. It might have been deleted " |
114 |
|
+ "or maybe the system is experiencing difficulties.", guestPage.getMessage()); |
115 |
|
|
116 |
|
|
117 |
1 |
getUtil().gotoPage("Invitation", "InvitationGuestActions", "view", "doAction_decline&messageID=12345"); |
118 |
1 |
Assert.assertNotNull("Guests able to decline nonexistent invitation", guestPage.getMessage()); |
119 |
1 |
Assert.assertEquals("No invitation was found by the given ID. It might have been deleted or " |
120 |
|
+ "maybe the system is experiencing difficulties.", guestPage.getMessage()); |
121 |
|
|
122 |
|
|
123 |
1 |
getUtil().gotoPage("Invitation", "InvitationGuestActions", "view", "doAction_report&messageID=12345"); |
124 |
1 |
Assert.assertNotNull("Guests able to report nonexistent invitation as spam", guestPage.getMessage()); |
125 |
1 |
Assert.assertEquals("There was no message found by the given ID. Maybe an administrator " |
126 |
|
+ "deleted the message from our system.", guestPage.getMessage()); |
127 |
|
} finally { |
128 |
1 |
getUtil().setSession(s); |
129 |
|
} |
130 |
|
} |
131 |
|
|
|
|
| 81.2% |
Uncovered Elements: 6 (32) |
Complexity: 2 |
Complexity Density: 0.07 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146") |
134 |
|
public void testSendMailToTwoAddresses() throws Exception |
135 |
|
{ |
136 |
1 |
try { |
137 |
1 |
startGreenMail(); |
138 |
1 |
getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null); |
139 |
1 |
InvitationSenderPage.InvitationSentPage sent = getSenderPage().send(); |
140 |
1 |
getGreenMail().waitForIncomingEmail(10000, 2); |
141 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
142 |
|
|
143 |
1 |
Assert.assertTrue("wrong number of messages", messages.length == 2); |
144 |
|
|
145 |
|
|
146 |
1 |
int a = 1, b = 2; |
147 |
|
|
148 |
1 |
Map<String, String> messageA = getMessageContent(messages[0]); |
149 |
1 |
Map<String, String> messageB = getMessageContent(messages[1]); |
150 |
|
|
151 |
1 |
Assert.assertFalse("Both messages are going to the same recipient", |
152 |
|
messageA.get("recipient").equals(messageB.get("recipient"))); |
153 |
|
|
154 |
|
|
155 |
1 |
if (messageA.get("recipient").contains("anotheruser@localhost.localdomain")) { |
156 |
0 |
Map<String, String> temp = messageB; |
157 |
0 |
messageB = messageA; |
158 |
0 |
messageA = temp; |
159 |
0 |
b = 1; |
160 |
0 |
a = 2; |
161 |
|
} |
162 |
|
|
163 |
1 |
Assert.assertTrue("Wrong recipient name.\nExpecting:user@localhost.localdomain\n Got:" |
164 |
|
+ messageA.get("recipient"), |
165 |
|
messageA.get("recipient").contains("user@localhost.localdomain")); |
166 |
|
|
167 |
1 |
Assert.assertTrue("Wrong recipient name.\nExpecting:anotheruser@localhost.localdomain\n Got:" |
168 |
|
+ messageB.get("recipient"), |
169 |
|
messageB.get("recipient").contains("anotheruser@localhost.localdomain")); |
170 |
|
|
171 |
1 |
assertMessageValid(messageA); |
172 |
1 |
assertMessageValid(messageB); |
173 |
|
|
174 |
|
|
175 |
1 |
Assert.assertTrue(sent.getMessageBoxContent().contains("Your message has been sent.")); |
176 |
1 |
TableElement table = sent.getTable(); |
177 |
1 |
Assert.assertTrue(table.numberOfRows() == 3); |
178 |
1 |
Assert.assertTrue(table.numberOfColumns() == 3); |
179 |
1 |
Assert.assertTrue(table.getRow(a).get(1).getText().contains("user@localhost.localdomain")); |
180 |
1 |
Assert.assertTrue(table.getRow(a).get(2).getText().contains("Pending")); |
181 |
1 |
Assert.assertTrue(table.getRow(b).get(1).getText().contains("anotheruser@localhost.localdomain")); |
182 |
1 |
Assert.assertTrue(table.getRow(b).get(2).getText().contains("Pending")); |
183 |
|
} finally { |
184 |
1 |
stopGreenMail(); |
185 |
|
} |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
188 |
1 |
@Test... |
189 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146") |
190 |
|
public void testPreviewMessage() |
191 |
|
{ |
192 |
1 |
InvitationMessageDisplayElement preview = getSenderPage().preview(); |
193 |
1 |
Assert.assertTrue(preview.getSubjectLine().contains("has invited you to join")); |
194 |
1 |
Assert.assertTrue(preview.getMessageBody().contains("If this message looks like abuse of our system")); |
195 |
1 |
Assert.assertTrue(preview.getValidRecipients().get(0).getText().contains("user@localhost.localdomain")); |
196 |
|
} |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
198 |
1 |
@Test... |
199 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146") |
200 |
|
public void testNonAdminCanSend() throws Exception |
201 |
|
{ |
202 |
1 |
TestUtils.Session s = getUtil().getSession(); |
203 |
1 |
try { |
204 |
1 |
getUtil().forceGuestUser(); |
205 |
1 |
getUtil().createUserAndLogin("NonMailAdminUser", "WeakPassword"); |
206 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
207 |
1 |
startGreenMail(); |
208 |
1 |
getSenderPage().fillForm("user@localhost.localdomain", null, null); |
209 |
1 |
InvitationSenderPage.InvitationSentPage sent = getSenderPage().send(); |
210 |
|
|
211 |
|
|
212 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
213 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
214 |
1 |
Map<String, String> message = getMessageContent(messages[0]); |
215 |
1 |
Assert.assertTrue(message.get("recipient").contains("user@localhost.localdomain")); |
216 |
1 |
assertMessageValid(message); |
217 |
|
|
218 |
|
|
219 |
1 |
Assert.assertTrue(sent.getMessageBoxContent().contains("Your message has been sent.")); |
220 |
1 |
TableElement table = sent.getTable(); |
221 |
1 |
Assert.assertTrue(table.numberOfRows() == 2); |
222 |
1 |
Assert.assertTrue(table.numberOfColumns() == 3); |
223 |
1 |
Assert.assertTrue(table.getRow(1).get(1).getText().contains("user@localhost.localdomain")); |
224 |
1 |
Assert.assertTrue(table.getRow(1).get(2).getText().contains("Pending")); |
225 |
|
} finally { |
226 |
1 |
stopGreenMail(); |
227 |
1 |
getUtil().setSession(s); |
228 |
1 |
getUtil().rest().deletePage("XWiki", "NonMailAdminUser"); |
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
237 |
1 |
@Test... |
238 |
|
@IgnoreBrowsers({ |
239 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
240 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
241 |
|
}) |
242 |
|
public void testUnpermittedUserCannotSendToMultipleAddresses() throws Exception |
243 |
|
{ |
244 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
245 |
|
|
246 |
|
|
247 |
1 |
AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation"); |
248 |
1 |
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" |
249 |
|
+ "usersMaySendToMultiple"), "false"); |
250 |
1 |
config.clickSave(); |
251 |
|
|
252 |
1 |
try { |
253 |
1 |
getUtil().forceGuestUser(); |
254 |
1 |
getUtil().createUserAndLogin("NonMailAdminUser", "WeakPassword"); |
255 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
256 |
1 |
startGreenMail(); |
257 |
1 |
getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null); |
258 |
1 |
InvitationSenderPage.InvitationSentPage sent = getSenderPage().send(); |
259 |
1 |
getGreenMail().waitForIncomingEmail(2000, 2); |
260 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
261 |
1 |
Assert.assertTrue("Messages were received when they shouldn't have been sent!", messages.length == 0); |
262 |
1 |
Assert.assertTrue("User was not shown the correct error message.", |
263 |
|
sent.getMessageBoxContent().equals("Your message couldn't be sent because there were no valid email " |
264 |
|
+ "addresses to send to.")); |
265 |
1 |
stopGreenMail(); |
266 |
|
|
267 |
|
|
268 |
1 |
TestUtils.Session nonAdmin = getUtil().getSession(); |
269 |
1 |
getUtil().setSession(admin); |
270 |
1 |
config = AdministrationSectionPage.gotoPage("Invitation"); |
271 |
1 |
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" |
272 |
|
+ "usersMaySendToMultiple"), "true"); |
273 |
1 |
config.clickSave(); |
274 |
1 |
getUtil().setSession(nonAdmin); |
275 |
|
|
276 |
|
|
277 |
1 |
startGreenMail(); |
278 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
279 |
1 |
getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null); |
280 |
1 |
sent = getSenderPage().send(); |
281 |
1 |
getGreenMail().waitForIncomingEmail(10000, 2); |
282 |
1 |
messages = getGreenMail().getReceivedMessages(); |
283 |
1 |
Assert.assertTrue("Non admins cannot send mail to even with permission", messages.length == 2); |
284 |
1 |
Assert.assertTrue("User was not given the message that their mail was sent.", |
285 |
|
sent.getMessageBoxContent().equals("Your message has been sent.")); |
286 |
|
} finally { |
287 |
1 |
stopGreenMail(); |
288 |
1 |
getUtil().setSession(admin); |
289 |
1 |
getUtil().rest().deletePage("XWiki", "NonMailAdminUser"); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
300 |
1 |
@Test... |
301 |
|
@IgnoreBrowsers({ |
302 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
303 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
304 |
|
}) |
305 |
|
public void testSpamReporting() throws Exception |
306 |
|
{ |
307 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
308 |
1 |
try { |
309 |
1 |
getUtil().forceGuestUser(); |
310 |
1 |
getUtil().createUserAndLogin("spam", "andEggs"); |
311 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
312 |
1 |
startGreenMail(); |
313 |
1 |
getSenderPage().fillForm("undisclosed-recipients@localhost.localdomain", null, |
314 |
|
"You have won the email lottery!"); |
315 |
1 |
getSenderPage().send(); |
316 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
317 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
318 |
1 |
String htmlMessage = getMessageContent(messages[0]).get("htmlPart"); |
319 |
|
|
320 |
|
|
321 |
1 |
stopGreenMail(); |
322 |
1 |
startGreenMail(); |
323 |
|
|
324 |
|
|
325 |
1 |
TestUtils.Session spammer = getUtil().getSession(); |
326 |
1 |
getUtil().forceGuestUser(); |
327 |
|
|
328 |
1 |
InvitationGuestActionsPage guestPage = |
329 |
|
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT); |
330 |
1 |
guestPage.setMemo("It's the email lottery, they have taken over your server!"); |
331 |
1 |
guestPage.confirm(); |
332 |
1 |
Assert.assertTrue("Failed to report spam", |
333 |
|
guestPage.getMessage().contains("Your report has been logged and the situation")); |
334 |
|
|
335 |
|
|
336 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
337 |
1 |
Assert.assertTrue("After a message is reported a user can accept it, clearing the spam report", |
338 |
|
guestPage.getMessage().equals("This invitation has been reported as spam and is no longer valid.")); |
339 |
|
|
340 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE); |
341 |
1 |
Assert.assertTrue("After a message is reported a user can decline it, clearing the spam report", |
342 |
|
guestPage.getMessage().equals("This invitation has already been reported as " |
343 |
|
+ "spam and thus cannot be declined.")); |
344 |
|
|
345 |
1 |
getUtil().setSession(admin); |
346 |
|
|
347 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
348 |
|
|
349 |
1 |
getUtil().setSession(spammer); |
350 |
1 |
getSenderPage().send(); |
351 |
1 |
getGreenMail().waitForIncomingEmail(2000, 1); |
352 |
1 |
Assert.assertTrue("Reported spammers can send mail!", getGreenMail().getReceivedMessages().length == 0); |
353 |
1 |
Assert.assertTrue("No message telling user he's reported spammer.", getSenderPage().userIsSpammer()); |
354 |
|
|
355 |
|
|
356 |
1 |
getUtil().setSession(admin); |
357 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
358 |
1 |
Assert.assertTrue("No warning in footer that a message is reported as spam", |
359 |
|
getSenderPage().getFooter().spamReports() == 1); |
360 |
|
|
361 |
1 |
InspectInvitationsPage inspectPage = getSenderPage().getFooter().inspectAllInvitations(); |
362 |
1 |
InspectInvitationsPage.OneMessage inspect = |
363 |
|
inspectPage.getMessageWhere("Subject", "spam has invited you to join localhost"); |
364 |
|
|
365 |
1 |
String expectedMessage = "Reported as spam with message: It's the email lottery, they have taken over " |
366 |
|
+ "your server!"; |
367 |
1 |
Assert.assertTrue("The message by the spam reporter is not shown to the admin.\nExpecting:" |
368 |
|
+ expectedMessage + "\n Got:" + inspect.getStatusAndMemo(), |
369 |
|
inspect.getStatusAndMemo().equals(expectedMessage)); |
370 |
|
|
371 |
1 |
String memo = "Actually the email lottery is quite legitimate."; |
372 |
1 |
String expectedSuccessMessage = "Invitation successfully marked as not spam. Log entry: " + memo; |
373 |
|
|
374 |
1 |
String successMessage = inspect.notSpam("Actually the email lottery is quite legitimate."); |
375 |
|
|
376 |
|
|
377 |
1 |
Assert.assertTrue("Admin got incorrect message after marking invitation as not spam\nExpecting:" |
378 |
|
+ expectedSuccessMessage + "\n Got:" + successMessage, |
379 |
|
expectedSuccessMessage.equals(successMessage)); |
380 |
|
|
381 |
1 |
getUtil().setSession(spammer); |
382 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
383 |
1 |
Assert.assertFalse("User permission to send not returned by admin action.", |
384 |
|
getSenderPage().userIsSpammer()); |
385 |
|
} finally { |
386 |
1 |
stopGreenMail(); |
387 |
1 |
getUtil().setSession(admin); |
388 |
1 |
getUtil().rest().deletePage("XWiki", "spam"); |
389 |
|
} |
390 |
|
} |
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
400 |
1 |
@Test... |
401 |
|
@IgnoreBrowsers({ |
402 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
403 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
404 |
|
}) |
405 |
|
public void testDeclineInvitation() throws Exception |
406 |
|
{ |
407 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
408 |
1 |
try { |
409 |
1 |
startGreenMail(); |
410 |
1 |
getSenderPage().send(); |
411 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
412 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
413 |
1 |
String htmlMessage = getMessageContent(messages[0]).get("htmlPart"); |
414 |
1 |
Assert.assertTrue("New invitation is not listed as pending in the footer.", |
415 |
|
getSenderPage().getFooter().myPendingInvitations() == 1); |
416 |
|
|
417 |
1 |
getUtil().forceGuestUser(); |
418 |
|
|
419 |
1 |
InvitationGuestActionsPage guestPage = |
420 |
|
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE); |
421 |
1 |
guestPage.setMemo("I'm not interested thank you."); |
422 |
1 |
guestPage.confirm(); |
423 |
1 |
Assert.assertTrue("Failed to decline invitation", |
424 |
|
getDriver().getPageSource().contains("This invitation has successfully been declined.")); |
425 |
|
|
426 |
1 |
getUtil().setSession(admin); |
427 |
|
|
428 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
429 |
1 |
Assert.assertTrue("Declined invitation is still listed as pending in the footer.", |
430 |
|
getSenderPage().getFooter().spamReports() == 0); |
431 |
|
|
432 |
|
|
433 |
1 |
InspectInvitationsPage inspectPage = getSenderPage().getFooter().inspectMyInvitations(); |
434 |
1 |
InspectInvitationsPage.OneMessage inspect = inspectPage.getMessageWhere("Status", "Declined"); |
435 |
|
|
436 |
1 |
Assert.assertTrue("Not showing message box to say the invitation has been declined", |
437 |
|
inspect.getStatusAndMemo().equals("Declined with message: I'm not interested thank you.")); |
438 |
|
|
439 |
|
|
440 |
1 |
TableElement messageHistoryTable = inspect.clickMessageHistory(); |
441 |
1 |
List<WebElement> row2 = messageHistoryTable.getRow(2); |
442 |
1 |
Assert.assertTrue("Message history table not showing correctly.", |
443 |
|
row2.get(0).getText().equals("Declined")); |
444 |
1 |
Assert.assertTrue("Message history table not showing correctly.", |
445 |
|
row2.get(2).getText().equals("I'm not interested thank you.")); |
446 |
|
|
447 |
|
|
448 |
1 |
getUtil().forceGuestUser(); |
449 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
450 |
1 |
Assert.assertTrue("After a message is declined a user can still accept it!", |
451 |
|
guestPage.getMessage().equals("This invitation has been declined and cannot be accepted now.")); |
452 |
|
|
453 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE); |
454 |
1 |
Assert.assertTrue("User was allowed to decline an invitation twice.", |
455 |
|
guestPage.getMessage().equals("This invitation has already been declined and " |
456 |
|
+ "cannot be declined again.")); |
457 |
|
|
458 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT); |
459 |
1 |
Assert.assertTrue("After the invitation was declined it now cannot be reported as spam.", |
460 |
|
guestPage.getMessage().equals("")); |
461 |
|
} finally { |
462 |
1 |
stopGreenMail(); |
463 |
1 |
getUtil().setSession(admin); |
464 |
|
} |
465 |
|
} |
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
474 |
1 |
@Test... |
475 |
|
@IgnoreBrowsers({ |
476 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
477 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
478 |
|
}) |
479 |
|
public void testAcceptInvitation() throws Exception |
480 |
|
{ |
481 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
482 |
1 |
try { |
483 |
1 |
startGreenMail(); |
484 |
1 |
getSenderPage().send(); |
485 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
486 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
487 |
1 |
String htmlMessage = getMessageContent(messages[0]).get("htmlPart"); |
488 |
1 |
Assert.assertTrue("New invitation is not listed as pending in the footer.", |
489 |
|
getSenderPage().getFooter().myPendingInvitations() == 1); |
490 |
|
|
491 |
1 |
getUtil().forceGuestUser(); |
492 |
|
|
493 |
1 |
InvitationGuestActionsPage guestPage = |
494 |
|
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
495 |
1 |
Assert.assertTrue("There was an error message when accepting the invitation message:\n" |
496 |
|
+ guestPage.getMessage(), |
497 |
|
guestPage.getMessage().equals("")); |
498 |
|
|
499 |
1 |
RegistrationPage rp = new RegistrationPage(); |
500 |
1 |
rp.fillRegisterForm(null, null, "InvitedMember", "WeakPassword", "WeakPassword", null); |
501 |
1 |
rp.clickRegister(); |
502 |
1 |
Assert.assertTrue("There were failure messages when registering.", |
503 |
|
rp.getValidationFailureMessages().isEmpty()); |
504 |
1 |
getDriver().get(getUtil().getURLToLoginAs("InvitedMember", "WeakPassword")); |
505 |
|
|
506 |
1 |
Assert.assertTrue("Failed to log user in after registering from invitation.", rp.isAuthenticated()); |
507 |
|
|
508 |
|
|
509 |
1 |
getUtil().forceGuestUser(); |
510 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
511 |
1 |
Assert.assertTrue("After the invitation was accepted a user was allowed to accept it again.", |
512 |
|
guestPage.getMessage().equals("This invitation has already been accepted and the " |
513 |
|
+ "offer is no longer valid.")); |
514 |
|
|
515 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE); |
516 |
1 |
Assert.assertTrue("After the invitation was accepted a user was allowed to decline it.", |
517 |
|
guestPage.getMessage().equals("This invitation has already been accepted and " |
518 |
|
+ "now cannot be declined.")); |
519 |
|
|
520 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT); |
521 |
1 |
Assert.assertTrue("After the invitation was accepted it now cannot be reported as spam.", |
522 |
|
guestPage.getMessage().equals("")); |
523 |
|
} finally { |
524 |
1 |
stopGreenMail(); |
525 |
1 |
getUtil().setSession(admin); |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
534 |
1 |
@Test... |
535 |
|
@IgnoreBrowsers({ |
536 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
537 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
538 |
|
}) |
539 |
|
public void testAcceptInvitationToClosedWiki() throws Exception |
540 |
|
{ |
541 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
542 |
1 |
try { |
543 |
|
|
544 |
1 |
ObjectEditPage oep = ObjectEditPage.gotoPage("XWiki", "XWikiPreferences"); |
545 |
|
|
546 |
1 |
oep.getObjectsOfClass("XWiki.XWikiGlobalRights").get(2) |
547 |
|
.getSelectElement(By.name("XWiki.XWikiGlobalRights_2_levels")).unSelect("register"); |
548 |
|
|
549 |
1 |
oep.clickSaveAndContinue(); |
550 |
|
|
551 |
1 |
getUtil().forceGuestUser(); |
552 |
1 |
RegistrationPage.gotoPage(); |
553 |
1 |
getUtil().assertOnPage(getUtil().getURL("XWiki", "XWikiLogin", "login")); |
554 |
|
|
555 |
|
|
556 |
1 |
getUtil().setSession(admin); |
557 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
558 |
1 |
getSenderPage().fillInDefaultValues(); |
559 |
|
|
560 |
1 |
startGreenMail(); |
561 |
1 |
getSenderPage().send(); |
562 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
563 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
564 |
1 |
String htmlMessage = getMessageContent(messages[0]).get("htmlPart"); |
565 |
1 |
Assert.assertTrue("New invitation is not listed as pending in the footer.", |
566 |
|
getSenderPage().getFooter().myPendingInvitations() == 1); |
567 |
|
|
568 |
1 |
getUtil().forceGuestUser(); |
569 |
|
|
570 |
1 |
InvitationGuestActionsPage guestPage = |
571 |
|
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
572 |
1 |
Assert.assertTrue("There was an error message when accepting the invitation message:\n" |
573 |
|
+ guestPage.getMessage(), |
574 |
|
guestPage.getMessage().equals("")); |
575 |
|
|
576 |
1 |
RegistrationPage rp = new RegistrationPage(); |
577 |
1 |
rp.fillRegisterForm(null, null, "AnotherInvitedMember", "WeakPassword", "WeakPassword", null); |
578 |
1 |
rp.clickRegister(); |
579 |
1 |
Assert.assertTrue("There were failure messages when registering.", |
580 |
|
rp.getValidationFailureMessages().isEmpty()); |
581 |
1 |
getDriver().get(getUtil().getURLToLoginAs("AnotherInvitedMember", "WeakPassword")); |
582 |
|
|
583 |
1 |
Assert.assertTrue("Failed to log user in after registering from invitation.", rp.isAuthenticated()); |
584 |
|
} finally { |
585 |
1 |
stopGreenMail(); |
586 |
1 |
getUtil().setSession(admin); |
587 |
|
|
588 |
|
|
589 |
1 |
ObjectEditPage oep = ObjectEditPage.gotoPage("XWiki", "XWikiPreferences"); |
590 |
|
|
591 |
1 |
oep.getObjectsOfClass("XWiki.XWikiGlobalRights").get(2) |
592 |
|
.getSelectElement(By.name("XWiki.XWikiGlobalRights_2_levels")).select("register"); |
593 |
|
|
594 |
1 |
oep.clickSaveAndContinue(); |
595 |
|
} |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
607 |
1 |
@Test... |
608 |
|
@IgnoreBrowsers({ |
609 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
610 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
611 |
|
}) |
612 |
|
public void testCancelInvitation() throws Exception |
613 |
|
{ |
614 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
615 |
1 |
try { |
616 |
1 |
startGreenMail(); |
617 |
1 |
getSenderPage().send(); |
618 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
619 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
620 |
1 |
String htmlMessage = getMessageContent(messages[0]).get("htmlPart"); |
621 |
1 |
Assert.assertTrue("New invitation is not listed as pending in the footer.", |
622 |
|
getSenderPage().getFooter().myPendingInvitations() == 1); |
623 |
|
|
624 |
1 |
InspectInvitationsPage.OneMessage message = getSenderPage().getFooter().inspectMyInvitations() |
625 |
|
.getMessageWhere("Subject", "Admin has invited you to join localhost This is a subject line."); |
626 |
|
|
627 |
1 |
InvitationActionConfirmationElement confirm = message.cancel(); |
628 |
|
|
629 |
1 |
Assert.assertEquals("leave a message in case the invitee(s) try to register.", |
630 |
|
confirm.getLabel().toLowerCase()); |
631 |
|
|
632 |
1 |
confirm.setMemo("Sorry, wrong email address."); |
633 |
1 |
Assert.assertEquals("Invitation successfully rescinded.", confirm.confirm()); |
634 |
|
|
635 |
|
|
636 |
1 |
getUtil().forceGuestUser(); |
637 |
|
|
638 |
1 |
String commonPart = "\nAdministrator left you this message when rescinding the invitation.\n" |
639 |
|
+ "Sorry, wrong email address."; |
640 |
|
|
641 |
|
|
642 |
1 |
InvitationGuestActionsPage guestPage = |
643 |
|
InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT); |
644 |
1 |
Assert.assertFalse("Guest was able to accept a message which had been canceled.", |
645 |
|
guestPage.getMessage().equals("")); |
646 |
1 |
Assert.assertEquals("We're sorry but this invitation has been rescinded." + commonPart, |
647 |
|
guestPage.getMessage()); |
648 |
|
|
649 |
|
|
650 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE); |
651 |
1 |
Assert.assertFalse("Guest was able to decline a message which had been canceled.", |
652 |
|
guestPage.getMessage().equals("")); |
653 |
1 |
Assert.assertEquals("This invitation has been rescinded and thus cannot be declined." + commonPart, |
654 |
|
guestPage.getMessage()); |
655 |
|
|
656 |
|
|
657 |
1 |
guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT); |
658 |
1 |
Assert.assertTrue("Guest was not able to report canceled invitation as spam", |
659 |
|
guestPage.getMessage().equals("")); |
660 |
1 |
guestPage.setMemo("Canceled message is spam."); |
661 |
1 |
Assert.assertEquals("Your report has been logged and the situation will " |
662 |
|
+ "be investigated as soon as possible, we apologize for the inconvenience.", guestPage.confirm()); |
663 |
|
} finally { |
664 |
1 |
stopGreenMail(); |
665 |
1 |
getUtil().setSession(admin); |
666 |
|
} |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
673 |
1 |
@Test... |
674 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
675 |
|
public void testSendManyToOneAddress() throws Exception |
676 |
|
{ |
677 |
1 |
TestUtils.Session admin = getUtil().getSession(); |
678 |
1 |
try { |
679 |
|
|
680 |
1 |
AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation"); |
681 |
1 |
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" |
682 |
|
+ "usersMaySendToMultiple"), "true"); |
683 |
1 |
config.clickSave(); |
684 |
|
|
685 |
|
|
686 |
1 |
getUtil().forceGuestUser(); |
687 |
1 |
getUtil().createUserAndLogin("tr0ll", "StrongPassword"); |
688 |
1 |
setSenderPage(InvitationSenderPage.gotoPage()); |
689 |
|
|
690 |
1 |
startGreenMail(); |
691 |
1 |
getSenderPage().fillForm("user@localhost.localdomain user@localhost.localdomain " |
692 |
|
+ "user@localhost.localdomain user@localhost.localdomain", null, null); |
693 |
1 |
getSenderPage().send(); |
694 |
1 |
getGreenMail().waitForIncomingEmail(10000, 1); |
695 |
1 |
MimeMessage[] messages = getGreenMail().getReceivedMessages(); |
696 |
1 |
Assert.assertTrue("One user is able to send multiple messages to the same poor recipient.", |
697 |
|
messages.length == 1); |
698 |
|
} finally { |
699 |
1 |
stopGreenMail(); |
700 |
1 |
getUtil().setSession(admin); |
701 |
1 |
getUtil().rest().deletePage("XWiki", "tr0ll"); |
702 |
|
} |
703 |
|
} |
704 |
|
|
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
709 |
0 |
protected InvitationSenderPage newSenderPage()... |
710 |
|
{ |
711 |
0 |
return new InvitationSenderPage(); |
712 |
|
} |
713 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
714 |
3 |
protected void assertMessageValid(Map<String, String> message)... |
715 |
|
{ |
716 |
3 |
Assert.assertTrue(message.get("htmlPart").contains("If this message looks like abuse of our system")); |
717 |
3 |
Assert.assertTrue(message.get("subjectLine").contains("has invited you to join")); |
718 |
|
} |
719 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
720 |
8 |
protected Map<String, String> getMessageContent(MimeMessage message) throws Exception... |
721 |
|
{ |
722 |
8 |
Map<String, String> messageMap = new HashMap<String, String>(); |
723 |
|
|
724 |
8 |
Address[] addresses = message.getAllRecipients(); |
725 |
8 |
Assert.assertTrue(addresses.length == 1); |
726 |
8 |
messageMap.put("recipient", addresses[0].toString()); |
727 |
|
|
728 |
8 |
messageMap.put("subjectLine", message.getSubject()); |
729 |
|
|
730 |
8 |
Multipart mp = (Multipart) message.getContent(); |
731 |
|
|
732 |
8 |
BodyPart plain = getPart(mp, "text/plain"); |
733 |
8 |
if (plain != null) { |
734 |
8 |
messageMap.put("textPart", plain.getContent().toString()); |
735 |
|
} |
736 |
8 |
BodyPart html = getPart(mp, "text/html"); |
737 |
8 |
if (html != null) { |
738 |
8 |
messageMap.put("htmlPart", html.getContent().toString()); |
739 |
|
} |
740 |
|
|
741 |
8 |
return messageMap; |
742 |
|
} |
743 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 7 |
Complexity Density: 0.78 |
|
744 |
40 |
protected BodyPart getPart(Multipart messageContent, String mimeType) throws Exception... |
745 |
|
{ |
746 |
48 |
for (int i = 0; i < messageContent.getCount(); i++) { |
747 |
48 |
BodyPart part = messageContent.getBodyPart(i); |
748 |
|
|
749 |
48 |
if (part.isMimeType(mimeType)) { |
750 |
16 |
return part; |
751 |
|
} |
752 |
|
|
753 |
32 |
if (part.isMimeType("multipart/related") |
754 |
|
|| part.isMimeType("multipart/alternative") |
755 |
|
|| part.isMimeType("multipart/mixed")) { |
756 |
24 |
BodyPart out = getPart((Multipart) part.getContent(), mimeType); |
757 |
24 |
if (out != null) { |
758 |
24 |
return out; |
759 |
|
} |
760 |
|
} |
761 |
|
} |
762 |
0 |
return null; |
763 |
|
} |
764 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
765 |
11 |
protected void startGreenMail() throws Exception... |
766 |
|
{ |
767 |
11 |
this.greenMail = new GreenMail(); |
768 |
11 |
this.greenMail.start(); |
769 |
|
} |
770 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
771 |
11 |
protected void stopGreenMail() throws Exception... |
772 |
|
{ |
773 |
11 |
if (getGreenMail() != null) { |
774 |
11 |
getGreenMail().stop(); |
775 |
|
} |
776 |
|
} |
777 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
778 |
44 |
protected GreenMail getGreenMail()... |
779 |
|
{ |
780 |
44 |
return this.greenMail; |
781 |
|
} |
782 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
783 |
41 |
protected InvitationSenderPage getSenderPage()... |
784 |
|
{ |
785 |
41 |
return this.senderPage; |
786 |
|
} |
787 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
788 |
21 |
protected void setSenderPage(InvitationSenderPage senderPage)... |
789 |
|
{ |
790 |
21 |
this.senderPage = senderPage; |
791 |
|
} |
792 |
|
} |