X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FTestOrgManagement.java;h=4e606ae7abdd79fdaeab6ce32b5c761e101ce3d8;hb=bb73860be30af60fdcc26709066d932f91cb02fc;hp=80db6bde912939eb5cb3af3fcd7125367203d0a7;hpb=d23d7a6fa9dc38c6193fea70017e0bff11257be5;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java b/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java index 80db6bde..4e606ae7 100644 --- a/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java +++ b/tests/org/cacert/gigi/pages/orga/TestOrgManagement.java @@ -4,7 +4,9 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URLConnection; import java.net.URLEncoder; import java.sql.SQLException; @@ -36,10 +38,10 @@ public class TestOrgManagement extends OrgTest { for (Organisation i : Organisation.getOrganisations(0, 30)) { i.delete(); } - executeBasicWebInteraction(cookie, CreateOrgPage.DEFAULT_PATH, "action=new&O=name&contact=mail&L=K%C3%B6ln&ST=" + URLEncoder.encode(DIFFICULT_CHARS, "UTF-8") + "&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6&optionalName=opname&postalAddress=postaladdress", 0); + assertNull(executeBasicWebInteraction(cookie, CreateOrgPage.DEFAULT_PATH, "action=new&O=name&contact=mail@serv.tld&L=K%C3%B6ln&ST=" + URLEncoder.encode(DIFFICULT_CHARS, "UTF-8") + "&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6&optionalName=opname&postalAddress=postaladdress", 0)); Organisation[] orgs = Organisation.getOrganisations(0, 30); assertEquals(1, orgs.length); - assertEquals("mail", orgs[0].getContactEmail()); + assertEquals("mail@serv.tld", orgs[0].getContactEmail()); assertEquals("name", orgs[0].getName()); assertEquals("Köln", orgs[0].getCity()); assertEquals(DIFFICULT_CHARS, orgs[0].getProvince()); @@ -47,14 +49,14 @@ public class TestOrgManagement extends OrgTest { assertEquals("postaladdress", orgs[0].getPostalAddress()); User u2 = User.getById(createAssuranceUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); - executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1)); List allAdmins = orgs[0].getAllAdmins(); assertEquals(1, allAdmins.size()); Affiliation affiliation = allAdmins.get(0); assertSame(u2, affiliation.getTarget()); assertTrue(affiliation.isMaster()); - executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&do_affiliate=y", 1); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&do_affiliate=y", 1)); allAdmins = orgs[0].getAllAdmins(); assertEquals(2, allAdmins.size()); Affiliation affiliation2 = allAdmins.get(0); @@ -64,13 +66,13 @@ public class TestOrgManagement extends OrgTest { assertEquals(u.getId(), affiliation2.getTarget().getId()); assertFalse(affiliation2.isMaster()); - executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&email=&do_affiliate=y", 1); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&email=&do_affiliate=y", 1)); assertEquals(1, orgs[0].getAllAdmins().size()); - executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&email=&do_affiliate=y", 1); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&email=&do_affiliate=y", 1)); assertEquals(0, orgs[0].getAllAdmins().size()); - executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "action=updateCertificateData&O=name1&contact=&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "action=updateCertificateData&O=name1&contact=&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0)); clearCaches(); orgs = Organisation.getOrganisations(0, 30); assertEquals("name1", orgs[0].getName()); @@ -160,4 +162,87 @@ public class TestOrgManagement extends OrgTest { assertEquals("Köln" + DIFFICULT_CHARS, o1.getPostalAddress()); o1.delete(); } + + /** + * Tests various contraints on organisaion fields. + */ + @Test + public void testLengthConstraint() throws IOException, GigiApiException { + Organisation o1 = createUniqueOrg(); + String str128 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz-_"; + String se = ""; + String s64 = str128.substring(0, 64); + String s65 = str128.substring(0, 65); + + String s128 = str128; + String s129 = str128 + "a"; + + assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), o1.getCity())); + + // test organisation name + assertNotNull(upCertData(o1, "", o1.getState(), o1.getProvince(), o1.getCity())); + assertNull(upCertData(o1, "A", o1.getState(), o1.getProvince(), o1.getCity())); + assertNull(upCertData(o1, s64, o1.getState(), o1.getProvince(), o1.getCity())); + assertNotNull(upCertData(o1, s65, o1.getState(), o1.getProvince(), o1.getCity())); + + // test state + assertNotNull(upCertData(o1, o1.getName(), o1.getState(), se, o1.getCity())); + assertNull(upCertData(o1, o1.getName(), o1.getState(), "A", o1.getCity())); + assertNull(upCertData(o1, o1.getName(), o1.getState(), s128, o1.getCity())); + assertNotNull(upCertData(o1, o1.getName(), o1.getState(), s129, o1.getCity())); + + // test town + assertNotNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), se)); + assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), "A")); + assertNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), s128)); + assertNotNull(upCertData(o1, o1.getName(), o1.getState(), o1.getProvince(), s129)); + + // test country + assertNotNull(upCertData(o1, o1.getName(), "", o1.getProvince(), o1.getCity())); + assertNotNull(upCertData(o1, o1.getName(), "D", o1.getProvince(), o1.getCity())); + assertNull(upCertData(o1, o1.getName(), "DE", o1.getProvince(), o1.getCity())); + assertNotNull(upCertData(o1, o1.getName(), "DES", o1.getProvince(), o1.getCity())); + // country code does not exist + assertNotNull(upCertData(o1, o1.getName(), "DD", o1.getProvince(), o1.getCity())); + // 3-letter country code should not be accepted + assertNotNull(upCertData(o1, o1.getName(), "DEU", o1.getProvince(), o1.getCity())); + + // test contact mail + assertNull(upOptData(o1, o1.getContactEmail())); + assertNotNull(upOptData(o1, "_mail@domail")); + + } + + /** + * Updates Organisation optional data via web interface. + * + * @param o1 + * Organisation to update. + * @param email + * the new contact email + * @return an error message or null + */ + private String upOptData(Organisation o1, String email) throws IOException, MalformedURLException, UnsupportedEncodingException { + return executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "action=updateOrganisationData&contact=" + email + "&optionalName=" + o1.getOptionalName() + "&postalAddress=" + o1.getPostalAddress(), 0); + } + + /** + * Updates Organisation certificate data via web interface. + * + * @param o1 + * Organisation to update. + * @param o + * the new name + * @param c + * the new country + * @param province + * the new "province/state" + * @param ct + * the new city or "locality" + * @return an error message or null + */ + private String upCertData(Organisation o1, String o, String c, String province, String ct) throws IOException, MalformedURLException, UnsupportedEncodingException { + return executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "action=updateCertificateData&O=" + o + "&C=" + c + "&ST=" + province + "&L=" + ct, 0); + } + }