From: Felix Dörre Date: Tue, 10 Nov 2015 23:44:15 +0000 (+0100) Subject: upd: move my Listing to WOT pages ( + testCase) X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=49d8f1404d62a69e552c12e61d78a33c6f903e20 upd: move my Listing to WOT pages ( + testCase) --- diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index 43251ab5..eb6b612f 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -60,6 +60,7 @@ import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.pages.orga.CreateOrgPage; import org.cacert.gigi.pages.orga.ViewOrgPage; import org.cacert.gigi.pages.wot.AssurePage; +import org.cacert.gigi.pages.wot.MyListingPage; import org.cacert.gigi.pages.wot.MyPoints; import org.cacert.gigi.pages.wot.RequestTTPPage; import org.cacert.gigi.ping.PingerDaemon; @@ -135,6 +136,7 @@ public class Gigi extends HttpServlet { putPage(MailOverview.DEFAULT_PATH, new MailOverview("Email addresses"), "Certificates"); putPage(DomainOverview.PATH + "*", new DomainOverview("Domains"), "Certificates"); putPage(MyPoints.PATH, new MyPoints("My Points"), "Web of Trust"); + putPage(MyListingPage.PATH, new MyListingPage(), "Web of Trust"); putPage(RequestTTPPage.PATH, new RequestTTPPage(), "Web of Trust"); putPage(TTPAdminPage.PATH + "/*", new TTPAdminPage(), "Admin"); putPage(CreateOrgPage.DEFAULT_PATH, new CreateOrgPage(), "Organisation Admin"); diff --git a/src/org/cacert/gigi/pages/account/MyDetails.java b/src/org/cacert/gigi/pages/account/MyDetails.java index 3cbe5ef4..4b0aa992 100644 --- a/src/org/cacert/gigi/pages/account/MyDetails.java +++ b/src/org/cacert/gigi/pages/account/MyDetails.java @@ -24,9 +24,7 @@ public class MyDetails extends Page { PrintWriter out = resp.getWriter(); HashMap map = new HashMap(); MyDetailsForm form = new MyDetailsForm(req, getUser(req)); - MyListingForm listingForm = new MyListingForm(req, getUser(req)); map.put("detailsForm", form); - map.put("contactMeForm", listingForm); if (LoginPage.getUser(req).getOrganisations().size() != 0) { map.put("orgaForm", new MyOrganisationsForm(req)); } @@ -46,9 +44,7 @@ public class MyDetails extends Page { @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { - if (req.getParameter("processContact") != null) { - Form.getForm(req, MyListingForm.class).submit(resp.getWriter(), req); - } else if (req.getParameter("processDetails") != null) { + if (req.getParameter("processDetails") != null) { Form.getForm(req, MyDetailsForm.class).submit(resp.getWriter(), req); } super.doPost(req, resp); diff --git a/src/org/cacert/gigi/pages/account/MyDetails.templ b/src/org/cacert/gigi/pages/account/MyDetails.templ index a4940ceb..db8d4f4e 100644 --- a/src/org/cacert/gigi/pages/account/MyDetails.templ +++ b/src/org/cacert/gigi/pages/account/MyDetails.templ @@ -1,6 +1,4 @@ -

- diff --git a/src/org/cacert/gigi/pages/account/MyOrganisationsForm.java b/src/org/cacert/gigi/pages/account/MyOrganisationsForm.java index ead00a46..443a9efe 100644 --- a/src/org/cacert/gigi/pages/account/MyOrganisationsForm.java +++ b/src/org/cacert/gigi/pages/account/MyOrganisationsForm.java @@ -29,7 +29,7 @@ public class MyOrganisationsForm extends Form { private static Template template; static { - template = new Template(MyListingForm.class.getResource("MyOrganisationsForm.templ")); + template = new Template(MyOrganisationsForm.class.getResource("MyOrganisationsForm.templ")); } @Override diff --git a/src/org/cacert/gigi/pages/account/MyListingForm.java b/src/org/cacert/gigi/pages/wot/MyListingForm.java similarity index 76% rename from src/org/cacert/gigi/pages/account/MyListingForm.java rename to src/org/cacert/gigi/pages/wot/MyListingForm.java index b3e83182..97218a5c 100644 --- a/src/org/cacert/gigi/pages/account/MyListingForm.java +++ b/src/org/cacert/gigi/pages/wot/MyListingForm.java @@ -1,4 +1,4 @@ -package org.cacert.gigi.pages.account; +package org.cacert.gigi.pages.wot; import java.io.PrintWriter; import java.util.Map; @@ -28,8 +28,13 @@ public class MyListingForm extends Form { @Override public boolean submit(PrintWriter out, HttpServletRequest req) { if (req.getParameter("listme") != null && req.getParameter("contactinfo") != null) { - target.setDirectoryListing( !req.getParameter("listme").equals("0")); - target.setContactInformation(req.getParameter("contactinfo")); + boolean on = !req.getParameter("listme").equals("0"); + target.setDirectoryListing(on); + if (on) { + target.setContactInformation(req.getParameter("contactinfo")); + } else { + target.setContactInformation(""); + } return true; } return false; @@ -44,7 +49,7 @@ public class MyListingForm extends Form { } else { vars.put("selected", ""); vars.put("notSelected", "selected"); - vars.put("activeInfo", ""); + vars.put("activeInfo", target.getContactInformation()); } template.output(out, l, vars); } diff --git a/src/org/cacert/gigi/pages/account/MyListingForm.templ b/src/org/cacert/gigi/pages/wot/MyListingForm.templ similarity index 100% rename from src/org/cacert/gigi/pages/account/MyListingForm.templ rename to src/org/cacert/gigi/pages/wot/MyListingForm.templ diff --git a/src/org/cacert/gigi/pages/wot/MyListingPage.java b/src/org/cacert/gigi/pages/wot/MyListingPage.java new file mode 100644 index 00000000..0b64b2e4 --- /dev/null +++ b/src/org/cacert/gigi/pages/wot/MyListingPage.java @@ -0,0 +1,41 @@ +package org.cacert.gigi.pages.wot; + +import java.io.IOException; +import java.util.HashMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.output.template.Form; +import org.cacert.gigi.pages.Page; +import org.cacert.gigi.util.AuthorizationContext; + +public class MyListingPage extends Page { + + public static final String PATH = "/wot/listing"; + + public MyListingPage() { + super("My Listing"); + } + + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + if (Form.getForm(req, MyListingForm.class).submit(resp.getWriter(), req)) { + resp.sendRedirect(PATH); + return; + } + super.doPost(req, resp); + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + new MyListingForm(req, getUser(req)).output(resp.getWriter(), getLanguage(req), new HashMap()); + } + + @Override + public boolean isPermitted(AuthorizationContext ac) { + return ac != null && ac.getTarget() instanceof User; + } + +} diff --git a/tests/org/cacert/gigi/pages/account/TestContactInformation.java b/tests/org/cacert/gigi/pages/account/TestContactInformation.java deleted file mode 100644 index c63e36d2..00000000 --- a/tests/org/cacert/gigi/pages/account/TestContactInformation.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.cacert.gigi.pages.account; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; - -import org.cacert.gigi.testUtils.ClientTest; -import org.cacert.gigi.testUtils.IOUtils; -import org.junit.Test; - -public class TestContactInformation extends ClientTest { - - @Test - public void testDirectoryListingToggle() throws IOException { - assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=&processContact", 1)); - URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection(); - url.setRequestProperty("Cookie", cookie); - String res = IOUtils.readURL(url); - res = res.split(java.util.regex.Pattern.quote(""))[1]; - assertThat(res, containsString("value=\"1\" selected")); - assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=0&contactinfo=&processContact", 1)); - url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection(); - url.setRequestProperty("Cookie", cookie); - res = IOUtils.readURL(url); - res = res.split(java.util.regex.Pattern.quote(""))[1]; - assertTrue(res.contains("value=\"0\" selected")); - } - - @Test - public void testContactinfoSet() throws IOException { - String text = createUniqueName(); - assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=" + text + "&processContact", 1)); - URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection(); - url.setRequestProperty("Cookie", cookie); - String res = IOUtils.readURL(url); - res = res.split(java.util.regex.Pattern.quote(""))[1]; - assertThat(res, containsString(text)); - } -} diff --git a/tests/org/cacert/gigi/pages/wot/TestListing.java b/tests/org/cacert/gigi/pages/wot/TestListing.java new file mode 100644 index 00000000..2747c50b --- /dev/null +++ b/tests/org/cacert/gigi/pages/wot/TestListing.java @@ -0,0 +1,47 @@ +package org.cacert.gigi.pages.wot; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.testUtils.ClientTest; +import org.cacert.gigi.testUtils.IOUtils; +import org.junit.Test; + +public class TestListing extends ClientTest { + + @Test + public void testListing() throws IOException, GigiApiException { + String c = IOUtils.readURL(get(MyListingPage.PATH)); + // Default settings not listed, empty text + assertThat(c, not(containsString("value=\"1\" selected"))); + assertThat(c, containsString("value=\"0\" selected")); + assertThat(c, containsString(">")); + + assertEquals(302, post(MyListingPage.PATH, "listme=0&contactinfo=a").getResponseCode()); + c = IOUtils.readURL(get(MyListingPage.PATH)); + assertThat(c, not(containsString("value=\"1\" selected"))); + assertThat(c, containsString("value=\"0\" selected")); + assertThat(c, containsString(">")); + + assertEquals(302, post(MyListingPage.PATH, "listme=1&contactinfo=a").getResponseCode()); + c = IOUtils.readURL(get(MyListingPage.PATH)); + assertThat(c, containsString("value=\"1\" selected")); + assertThat(c, not(containsString("value=\"0\" selected"))); + assertThat(c, containsString(">a")); + + assertEquals(302, post(MyListingPage.PATH, "listme=1&contactinfo=b").getResponseCode()); + c = IOUtils.readURL(get(MyListingPage.PATH)); + assertThat(c, containsString("value=\"1\" selected")); + assertThat(c, not(containsString("value=\"0\" selected"))); + assertThat(c, containsString(">b")); + + assertEquals(302, post(MyListingPage.PATH, "listme=0&contactinfo=b").getResponseCode()); + c = IOUtils.readURL(get(MyListingPage.PATH)); + assertThat(c, containsString("value=\"0\" selected")); + assertThat(c, not(containsString("value=\"1\" selected"))); + assertThat(c, containsString(">")); + } +} diff --git a/util-testing/org/cacert/gigi/util/SimpleSigner.java b/util-testing/org/cacert/gigi/util/SimpleSigner.java index 843867b6..f8ee1e90 100644 --- a/util-testing/org/cacert/gigi/util/SimpleSigner.java +++ b/util-testing/org/cacert/gigi/util/SimpleSigner.java @@ -196,6 +196,7 @@ public class SimpleSigner { int id = rs.getInt(1); File crt = KeyStorage.locateCrt(id); worked = true; + System.out.println("Revoke faked: " + id); revokeCompleted.setInt(1, id); revokeCompleted.execute(); finishJob.setInt(1, rs.getInt(3));