X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FTestOrgaManagement.java;h=c8a6c1394d8627dd1303bf6134b4468dfc32deaa;hb=280be756fb425fc8148ade698f51528e1e9106c2;hp=bd0b8f4b5cb46241b55b80c587ffb1ad93f76b83;hpb=da72882d9ff14bd4077d9f71ae134a67581c49cb;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java b/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java index bd0b8f4b..c8a6c139 100644 --- a/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java +++ b/tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java @@ -10,44 +10,43 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.util.List; +import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.Organisation; import org.cacert.gigi.dbObjects.Organisation.Affiliation; import org.cacert.gigi.dbObjects.User; +import org.cacert.gigi.testUtils.ClientTest; import org.cacert.gigi.testUtils.IOUtils; -import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Test; -public class TestOrgaManagement extends ManagedTest { - - public User u = User.getById(createVerifiedUser("testuser", "testname", uniq + "@testdom.com", TEST_PASSWORD)); - - public String session; +public class TestOrgaManagement extends ClientTest { public TestOrgaManagement() throws IOException { - u.grantGroup(u, Group.getByString("orgassurer")); + u.grantGroup(u, Group.ORGASSURER); + makeAssurer(u.getId()); clearCaches(); - session = login(uniq + "@testdom.com", TEST_PASSWORD); + cookie = login(email, TEST_PASSWORD); } @Test public void testAdd() throws IOException { - executeBasicWebInteraction(session, CreateOrgPage.DEFAULT_PATH, "O=name&contact=&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0); + executeBasicWebInteraction(cookie, CreateOrgPage.DEFAULT_PATH, "O=name&contact=mail&L=K%C3%B6ln&ST=%C3%9C%C3%96%C3%84%C3%9F&C=DE&comments=jkl%C3%B6loiuzfdfgjlh%C3%B6", 0); Organisation[] orgs = Organisation.getOrganisations(0, 30); assertEquals(1, orgs.length); + assertEquals("mail", orgs[0].getContactEmail()); assertEquals("name", orgs[0].getName()); assertEquals("Köln", orgs[0].getCity()); assertEquals("ÜÖÄß", orgs[0].getProvince()); - User u2 = User.getById(createVerifiedUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); - executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&affiliate=y&master=y", 1); + 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); List allAdmins = orgs[0].getAllAdmins(); assertEquals(1, allAdmins.size()); Affiliation affiliation = allAdmins.get(0); assertSame(u2, affiliation.getTarget()); assertTrue(affiliation.isMaster()); - executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&affiliate=y", 1); + 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); @@ -57,24 +56,24 @@ public class TestOrgaManagement extends ManagedTest { assertSame(u.getId(), affiliation2.getTarget().getId()); assertFalse(affiliation2.isMaster()); - executeBasicWebInteraction(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u.getEmail(), "UTF-8") + "&email=&affiliate=y", 1); + 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(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "del=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&email=&affiliate=y", 1); + 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(session, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "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); + executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "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()); } @Test - public void testNonAssurerSeeOnlyOwn() throws IOException { - User u2 = User.getById(createVerifiedUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); - Organisation o1 = new Organisation("name21", "DE", "sder", "Rostov", u); - Organisation o2 = new Organisation("name12", "DE", "sder", "Rostov", u); - o1.addAdmin(u2, u2, false); + public void testNonAssurerSeeOnlyOwn() throws IOException, GigiApiException { + User u2 = User.getById(createAssuranceUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); + Organisation o1 = new Organisation("name21", "DE", "sder", "Rostov", "email", u); + Organisation o2 = new Organisation("name12", "DE", "sder", "Rostov", "email", u); + o1.addAdmin(u2, u, false); String session2 = login(u2.getEmail(), TEST_PASSWORD); URLConnection uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection(); @@ -88,15 +87,47 @@ public class TestOrgaManagement extends ManagedTest { assertEquals(404, ((HttpURLConnection) uc).getResponseCode()); uc = new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH).openConnection(); - uc.addRequestProperty("Cookie", session); + uc.addRequestProperty("Cookie", cookie); content = IOUtils.readURL(uc); assertThat(content, containsString("name21")); assertThat(content, containsString("name12")); - uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), session); + uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o1.getId()).openConnection(), cookie); assertEquals(200, ((HttpURLConnection) uc).getResponseCode()); - uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), session); + uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), cookie); assertEquals(200, ((HttpURLConnection) uc).getResponseCode()); o1.delete(); o2.delete(); } + + @Test + public void testAffiliationRights() throws IOException, GigiApiException { + User u2 = User.getById(createAssuranceUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); + User u3 = User.getById(createAssuranceUser("testmaster", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); + User u4_dummy = User.getById(createVerifiedUser("testmaster", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); + Organisation o1 = new Organisation("name21", "DE", "sder", "Rostov", "email", u); + o1.addAdmin(u3, u, true); + try { + // must fail because u4 is no assurer + o1.addAdmin(u4_dummy, u3, false); + fail("No exception!"); + } catch (GigiApiException e) { + } + o1.addAdmin(u2, u3, false); + try { + // must fail because u2 may not add admins + o1.addAdmin(u3, u2, false); + fail("No exception!"); + } catch (GigiApiException e) { + } + try { + // must fail because u4 is no assurer + o1.addAdmin(u4_dummy, u, false); + fail("No exception!"); + } catch (GigiApiException e) { + } + o1.removeAdmin(u2, u3); + o1.removeAdmin(u3, u3); + assertEquals(0, o1.getAllAdmins().size()); + o1.delete(); + } }