X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2Fadmin%2FTestSEAdminNotificationMail.java;h=97ac6a0065a05d6c8800f7c0b3777b666bb3d0c0;hb=150cc0ac00db36ed7610683319a3177b0cb62da2;hp=9bcaa825411f4e9b311adc601b445c0e57964990;hpb=8822b2ffdda7eb4109415a7867388a321ea6b56f;p=gigi.git diff --git a/tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java b/tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java index 9bcaa825..97ac6a00 100644 --- a/tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java +++ b/tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.net.MalformedURLException; +import java.net.URLConnection; import java.net.URLEncoder; import java.util.HashMap; import java.util.Locale; @@ -17,23 +18,21 @@ import club.wpia.gigi.GigiApiException; import club.wpia.gigi.dbObjects.Group; import club.wpia.gigi.dbObjects.User; import club.wpia.gigi.localisation.Language; -import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage; +import club.wpia.gigi.pages.account.MyDetails; import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage; -import club.wpia.gigi.testUtils.ClientTest; +import club.wpia.gigi.testUtils.IOUtils; +import club.wpia.gigi.testUtils.SEClientTest; import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail; import club.wpia.gigi.util.ServerConstants; +import club.wpia.gigi.util.ServerConstants.Host; -public class TestSEAdminNotificationMail extends ClientTest { +public class TestSEAdminNotificationMail extends SEClientTest { private int targetID; private String targetEmail; public TestSEAdminNotificationMail() throws IOException, GigiApiException { - grant(u, Group.SUPPORTER); - cookie = login(email, TEST_PASSWORD); - assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode()); - targetEmail = createUniqueName() + "@example.com"; String fname = "Först"; String lname = "Secönd"; @@ -146,4 +145,34 @@ public class TestSEAdminNotificationMail extends ClientTest { message = getMailReceiver().receive(targetEmail).getMessage(); assertThat(message, containsString("All certificates in your account have been revoked.")); } + + @Test + public void testSupportSupporterGroup() throws MalformedURLException, IOException { + // supporter adds to his own groups + String s = IOUtils.readURL(post(SupportUserDetailsPage.PATH + u.getId() + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.ORG_AGENT.getDBName(), "UTF-8"))); + assertThat(s, containsString("Supporter may not modify himself.")); + + // supporter removes from his own groups + s = IOUtils.readURL(post(SupportUserDetailsPage.PATH + u.getId() + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.ORG_AGENT.getDBName(), "UTF-8"))); + assertThat(s, containsString("Supporter may not modify himself.")); + + // supporter removes supporter flag + URLConnection uc = post(SupportUserDetailsPage.PATH + u.getId() + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8")); + assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + MyDetails.PATH, uc.getHeaderField("Location")); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap()); + // mail to support + String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage(); + assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked.")); + // mail to user + message = getMailReceiver().receive(u.getEmail()).getMessage(); + assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account.")); + // mail to board + message = getMailReceiver().receive(ServerConstants.getBoardMailAddress()).getMessage(); + assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + u.getPreferredName().toString() + "'.")); + s = IOUtils.readURL(get(cookie, MyDetails.PATH)); + assertThat(s, not(containsString("supporter"))); + } + }