Search in sources :

Example 1 with AdministrationSectionPage

use of org.xwiki.administration.test.po.AdministrationSectionPage in project xwiki-platform by xwiki.

the class InvitationTest method setUp.

@Before
public void setUp() throws Exception {
    // Login as admin and delete existing messages.
    getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(getUtil().getURLToNonExistentPage()));
    getUtil().recacheSecretToken();
    getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS);
    getUtil().rest().deletePage("Invitation", "InvitationMessages");
    if (!initialized) {
        // We have to go to sender page before any config shows up.
        InvitationSenderPage.gotoPage();
        AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation");
        // Set port to 3025
        config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_smtp_port"), "3025");
        // Make sure that by default we don't allow non admin to send emails to multiple addresses
        config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" + "usersMaySendToMultiple"), "false");
        config.clickSave();
        // Make sure the users we're registering in testAcceptInvitation and testAcceptInvitationToCloseWiki don't
        // exist.
        // TODO: Fix this whole mess of having try/finally blocks in tests below which is an anti pattern. Instead
        // we need to separate tests by fixture.
        getUtil().rest().deletePage("XWiki", "InvitedMember");
        getUtil().rest().deletePage("XWiki", "AnotherInvitedMember");
        initialized = true;
    }
    setSenderPage(InvitationSenderPage.gotoPage());
    getSenderPage().fillInDefaultValues();
}
Also used : AdministrationSectionPage(org.xwiki.administration.test.po.AdministrationSectionPage) Before(org.junit.Before)

Example 2 with AdministrationSectionPage

use of org.xwiki.administration.test.po.AdministrationSectionPage in project xwiki-platform by xwiki.

the class InvitationTest method testUnpermittedUserCannotSendToMultipleAddresses.

/**
 * This test proves that: 1. Non administrators trying to send to multiple email addresses without permission will
 * get an error message. and said mail will not be sent. 2. After permission is granted sending to multiple users
 * will work and message will say mail was sent.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testUnpermittedUserCannotSendToMultipleAddresses() throws Exception {
    TestUtils.Session admin = getUtil().getSession();
    // Make sure users don't have the right to send to multiple.
    AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation");
    config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" + "usersMaySendToMultiple"), "false");
    config.clickSave();
    try {
        getUtil().forceGuestUser();
        getUtil().createUserAndLogin("NonMailAdminUser", "WeakPassword");
        setSenderPage(InvitationSenderPage.gotoPage());
        startGreenMail();
        getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null);
        InvitationSenderPage.InvitationSentPage sent = getSenderPage().send();
        getGreenMail().waitForIncomingEmail(2000, 2);
        MimeMessage[] messages = getGreenMail().getReceivedMessages();
        Assert.assertTrue("Messages were received when they shouldn't have been sent!", messages.length == 0);
        Assert.assertEquals("User was not shown the correct error message.", "Your message could not be sent because there were no valid email addresses to send to.", sent.getMessageBoxContent());
        stopGreenMail();
        // Become admin and allow users to send to multiple.
        TestUtils.Session nonAdmin = getUtil().getSession();
        getUtil().setSession(admin);
        config = AdministrationSectionPage.gotoPage("Invitation");
        config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" + "usersMaySendToMultiple"), "true");
        config.clickSave();
        getUtil().setSession(nonAdmin);
        // Prove that the user can now send to multiple recipients.
        startGreenMail();
        setSenderPage(InvitationSenderPage.gotoPage());
        getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null);
        sent = getSenderPage().send();
        getGreenMail().waitForIncomingEmail(10000, 2);
        messages = getGreenMail().getReceivedMessages();
        Assert.assertTrue("Non admins cannot send mail to even with permission", messages.length == 2);
        Assert.assertTrue("User was not given the message that their mail was sent.", sent.getMessageBoxContent().equals("Your message has been sent."));
    } finally {
        stopGreenMail();
        getUtil().setSession(admin);
        getUtil().rest().deletePage("XWiki", "NonMailAdminUser");
    }
}
Also used : TestUtils(org.xwiki.test.ui.TestUtils) AdministrationSectionPage(org.xwiki.administration.test.po.AdministrationSectionPage) MimeMessage(javax.mail.internet.MimeMessage) InvitationSenderPage(org.xwiki.invitation.test.po.InvitationSenderPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 3 with AdministrationSectionPage

use of org.xwiki.administration.test.po.AdministrationSectionPage in project xwiki-platform by xwiki.

the class InvitationTest method testSendManyToOneAddress.

/**
 * This test proves that:
 * 1. A user cannot send to the same address multiple (8000) times which would be very annoying for the recipient.
 */
@Test
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177")
public void testSendManyToOneAddress() throws Exception {
    TestUtils.Session admin = getUtil().getSession();
    try {
        // Allow users to send to multiple.
        AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation");
        config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_" + "usersMaySendToMultiple"), "true");
        config.clickSave();
        // Now switch to a wizeguy user
        getUtil().forceGuestUser();
        getUtil().createUserAndLogin("tr0ll", "StrongPassword");
        setSenderPage(InvitationSenderPage.gotoPage());
        startGreenMail();
        getSenderPage().fillForm("user@localhost.localdomain user@localhost.localdomain " + "user@localhost.localdomain user@localhost.localdomain", null, null);
        getSenderPage().send();
        getGreenMail().waitForIncomingEmail(10000, 1);
        MimeMessage[] messages = getGreenMail().getReceivedMessages();
        Assert.assertTrue("One user is able to send multiple messages to the same poor recipient.", messages.length == 1);
    } finally {
        stopGreenMail();
        getUtil().setSession(admin);
        getUtil().rest().deletePage("XWiki", "tr0ll");
    }
}
Also used : TestUtils(org.xwiki.test.ui.TestUtils) AdministrationSectionPage(org.xwiki.administration.test.po.AdministrationSectionPage) MimeMessage(javax.mail.internet.MimeMessage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 4 with AdministrationSectionPage

use of org.xwiki.administration.test.po.AdministrationSectionPage in project xwiki-platform by xwiki.

the class RegisterTest method setUp.

@Before
public void setUp() throws Exception {
    deleteUser("JohnSmith");
    switchUser();
    this.registrationPage = this.getRegistrationPage();
    // Switch LiveValidation on or off as needed.
    int x = 0;
    while (this.registrationPage.isLiveValidationEnabled() != useLiveValidation()) {
        AdministrationSectionPage sectionPage = new AdministrationSectionPage("Registration");
        getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(sectionPage.getURL()));
        getUtil().recacheSecretToken();
        getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS);
        getUtil().assertOnPage(sectionPage.getURL());
        sectionPage.getForm().setFieldValue(By.name("XWiki.Registration_0_liveValidation_enabled"), Boolean.valueOf(useLiveValidation()).toString());
        sectionPage.clickSave();
        if (x > 2) {
            throw new WebDriverException("Unable to set useLiveValidation to " + useLiveValidation());
        }
        x++;
        this.registrationPage = this.getRegistrationPage();
    }
    // The prepareName javascript function is the cause of endless flickering
    // since it trys to suggest a username every time the field is focused.
    getDriver().executeJavascript("document.getElementById('xwikiname').onfocus = null;");
    this.registrationPage.fillInJohnSmithValues();
}
Also used : AdministrationSectionPage(org.xwiki.administration.test.po.AdministrationSectionPage) WebDriverException(org.openqa.selenium.WebDriverException) Before(org.junit.Before)

Aggregations

AdministrationSectionPage (org.xwiki.administration.test.po.AdministrationSectionPage)4 MimeMessage (javax.mail.internet.MimeMessage)2 Before (org.junit.Before)2 Test (org.junit.Test)2 AbstractTest (org.xwiki.test.ui.AbstractTest)2 TestUtils (org.xwiki.test.ui.TestUtils)2 WebDriverException (org.openqa.selenium.WebDriverException)1 InvitationSenderPage (org.xwiki.invitation.test.po.InvitationSenderPage)1 IgnoreBrowser (org.xwiki.test.ui.browser.IgnoreBrowser)1 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)1