X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FManagedTest.java;h=01ee4c5980b869b56054abc0b647a639eb0ff5bd;hp=a0228f161180b27d231887ebaea05bec063e2966;hb=0b86fb147b4a61f315770fa5bba4466ca18ddfa8;hpb=ab9818f784c71e0f75c1c1dd621da8a3a88cffa4 diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index a0228f16..01ee4c59 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -42,7 +42,6 @@ import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.Job; import org.cacert.gigi.dbObjects.ObjectCache; import org.cacert.gigi.dbObjects.User; -import org.cacert.gigi.pages.Manager; import org.cacert.gigi.pages.account.MyDetails; import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail; @@ -289,11 +288,9 @@ public class ManagedTest extends ConfiguredTest { } } - public static void grant(String email, Group g) throws IOException { - HttpURLConnection huc = (HttpURLConnection) new URL("https://" + getServerName() + Manager.PATH).openConnection(); - huc.setDoOutput(true); - huc.getOutputStream().write(("addpriv=y&priv=" + URLEncoder.encode(g.getDatabaseName(), "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8")).getBytes("UTF-8")); - assertEquals(200, huc.getResponseCode()); + public static void grant(User u, Group g) throws IOException, GigiApiException { + u.grantGroup(getSupporter(), g); + clearCaches(); } /** @@ -486,4 +483,21 @@ public class ManagedTest extends ConfiguredTest { return openConnection; } + private static User supporter; + + public static User getSupporter() throws GigiApiException, IOException { + if (supporter != null) { + return supporter; + } + int i = createVerifiedUser("fn", "ln", createUniqueName() + "@email.com", TEST_PASSWORD); + try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `user_groups` SET `user`=?, `permission`=?::`userGroup`, `grantedby`=?")) { + ps.setInt(1, i); + ps.setString(2, Group.SUPPORTER.getDBName()); + ps.setInt(3, i); + ps.execute(); + } + clearCaches(); + supporter = User.getById(i); + return supporter; + } }