]> WPIA git - gigi.git/blobdiff - util-testing/org/cacert/gigi/pages/Manager.java
upd: new Manager function, adding exp-points
[gigi.git] / util-testing / org / cacert / gigi / pages / Manager.java
index 30daa4d0216d7245d5762971c9cc63739e63c42f..3ac191ac030bf4d4fc886cb685237d08e4c5977f 100644 (file)
@@ -17,6 +17,7 @@ import java.util.LinkedList;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+import java.util.TreeSet;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -24,8 +25,8 @@ import javax.servlet.http.HttpServletResponse;
 import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.crypto.SPKAC;
-import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
 import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.dbObjects.CertificateOwner;
@@ -89,41 +90,45 @@ public class Manager extends Page {
         }
     }
 
-    public User[] getAssurers() {
-        if (assurers != null) {
-            return assurers;
+    public User getAssurer(int i) {
+        if (assurers[i] != null) {
+            return assurers[i];
         }
-        assurers = new User[10];
         try {
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?");
-            for (int i = 0; i < assurers.length; i++) {
-                String mail = "test-assurer" + i + "@example.com";
-                User u = User.getByEmail(mail);
-                if (u == null) {
-                    System.out.println("Creating assurer");
-                    createUser(mail);
-                    u = User.getByEmail(mail);
-                    passCATS(u);
-                    ps.setInt(1, u.getId());
-                    ps.setInt(2, u.getId());
-                    ps.setInt(3, 100);
-                    ps.setString(4, "Manager init code");
-                    ps.setString(5, "1990-01-01");
-                    ps.execute();
-                }
-                assurers[i] = u;
+            User u = createAssurer(i);
+            assurers[i] = u;
 
-            }
         } catch (ReflectiveOperationException | GigiApiException e) {
             e.printStackTrace();
         }
-        return assurers;
+        return assurers[i];
+    }
+
+    private User createAssurer(int i) throws GigiApiException, IllegalAccessException {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?")) {
+            String mail = "test-assurer" + i + "@example.com";
+            User u = User.getByEmail(mail);
+            if (u == null) {
+                System.out.println("Creating assurer");
+                createUser(mail);
+                u = User.getByEmail(mail);
+                passCATS(u);
+                ps.setInt(1, u.getId());
+                ps.setInt(2, u.getId());
+                ps.setInt(3, 100);
+                ps.setString(4, "Manager init code");
+                ps.setString(5, "1990-01-01");
+                ps.execute();
+            }
+            return u;
+        }
     }
 
     private void passCATS(User u) {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO cats_passed SET user_id=?, variant_id=1");
-        ps.setInt(1, u.getId());
-        ps.execute();
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO cats_passed SET user_id=?, variant_id=1")) {
+            ps.setInt(1, u.getId());
+            ps.execute();
+        }
     }
 
     private static Manager instance;
@@ -132,6 +137,8 @@ public class Manager extends Page {
 
     HashMap<String, LinkedList<String>> emails = new HashMap<>();
 
+    private static TreeSet<String> pingExempt = new TreeSet<>();
+
     public static Manager getInstance() {
         if (instance == null) {
             instance = new Manager();
@@ -160,7 +167,7 @@ public class Manager extends Page {
 
     }
 
-    public static class PingerFetcher extends DomainPinger {
+    public class PingerFetcher extends DomainPinger {
 
         private DomainPingType dpt;
 
@@ -171,7 +178,11 @@ public class Manager extends Page {
         @Override
         public void ping(Domain domain, String configuration, CertificateOwner target, int confId) {
             System.out.println("Test: " + domain);
-            dps.get(dpt).ping(domain, configuration, target, confId);
+            if (pingExempt.contains(domain.getSuffix())) {
+                enterPingResult(confId, DomainPinger.PING_SUCCEDED, "Succeeded by TestManager pass-by", null);
+            } else {
+                dps.get(dpt).ping(domain, configuration, target, confId);
+            }
         }
 
     }
@@ -210,7 +221,7 @@ public class Manager extends Page {
         ea.verify(hash);
     }
 
-    User[] assurers;
+    User[] assurers = new User[25];
 
     @Override
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
@@ -250,13 +261,24 @@ public class Manager extends Page {
                 return;
             }
             try {
-                for (int i = 0; i < getAssurers().length; i++) {
-                    Notary.assure(getAssurers()[i], byEmail, byEmail.getName(), byEmail.getDoB(), 10, "Testmanager Assure up code", "2014-11-06");
+                for (int i = 0; i < 10; i++) {
+                    Notary.assure(getAssurer(i), byEmail, byEmail.getName(), byEmail.getDoB(), 10, "Testmanager Assure up code", "2014-11-06", AssuranceType.FACE_TO_FACE);
                 }
             } catch (GigiApiException e) {
                 throw new Error(e);
             }
             resp.getWriter().println("User has been assured.");
+        } else if (req.getParameter("letassure") != null) {
+            String mail = req.getParameter("letassureEmail");
+            User byEmail = User.getByEmail(mail);
+            try {
+                for (int i = 0; i < 25; i++) {
+                    User a = getAssurer(i);
+                    Notary.assure(byEmail, a, a.getName(), a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE);
+                }
+            } catch (GigiApiException e) {
+                throw new Error(e);
+            }
         } else if (req.getParameter("addEmail") != null) {
             User u = User.getByEmail(req.getParameter("addEmailEmail"));
             try {
@@ -308,6 +330,16 @@ public class Manager extends Page {
                 resp.getWriter().println("interrupted");
             }
 
+        } else if (req.getParameter("addExDom") != null) {
+            String dom = req.getParameter("exemtDom");
+            pingExempt.add(dom);
+            resp.getWriter().println("Updated domains exempt from pings. Current set: <br/>");
+            resp.getWriter().println(pingExempt);
+        } else if (req.getParameter("delExDom") != null) {
+            String dom = req.getParameter("exemtDom");
+            pingExempt.remove(dom);
+            resp.getWriter().println("Updated domains exempt from pings. Current set: <br/>");
+            resp.getWriter().println(pingExempt);
         }
     }
 
@@ -346,7 +378,6 @@ public class Manager extends Page {
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        getAssurers();
         String pi = req.getPathInfo().substring(PATH.length());
         if (pi.length() > 1 && pi.startsWith("/fetch-")) {
             String mail = pi.substring(pi.indexOf('-', 2) + 1);