X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fwot%2FTestTTPAdmin.java;h=d04b0b66cd921f22cef3649fc9cee94045400c5b;hp=32c4268afc120846f613a5a72d07917b9953e824;hb=d0470c5987aaecbc444c7100319df69b6f740680;hpb=8af6231b22da4fef795bcb54913faad6592b1a02 diff --git a/tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java b/tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java index 32c4268a..d04b0b66 100644 --- a/tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java +++ b/tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java @@ -3,10 +3,9 @@ package org.cacert.gigi.pages.wot; import static org.junit.Assert.*; import java.io.IOException; -import java.net.HttpURLConnection; import java.net.MalformedURLException; -import java.net.URL; +import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.pages.admin.TTPAdminPage; @@ -22,31 +21,30 @@ public class TestTTPAdmin extends ClientTest { } @Test - public void testHasRight() throws IOException { + public void testHasRight() throws IOException, GigiApiException { testTTPAdmin(true); } @Test - public void testHasNoRight() throws IOException { + public void testHasNoRight() throws IOException, GigiApiException { testTTPAdmin(false); } - public void testTTPAdmin(boolean hasRight) throws IOException { + public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException { if (hasRight) { - grant(email, Group.getByString("ttp-assurer")); + grant(u, Group.getByString("ttp-assurer")); } - grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT); + grant(u, TTPAdminPage.TTP_APPLICANT); cookie = login(u.getEmail(), TEST_PASSWORD); - assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH)); - assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/")); - assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + u.getId())); - assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us2.getId())); - assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + 100)); + assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH)); + assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/")); + assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId())); + assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId())); + assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100)); } private int fetchStatusCode(String path) throws MalformedURLException, IOException { - URL u = new URL(path); - return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode(); + return get(path).getResponseCode(); } }