]> WPIA git - gigi.git/commitdiff
Merge branch 'felix-work'
authorFelix Dörre <felix@dogcraft.de>
Sun, 1 Feb 2015 01:46:44 +0000 (02:46 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sun, 1 Feb 2015 01:46:44 +0000 (02:46 +0100)
30 files changed:
doc/tableStructure.sql
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/Gigi.templ
src/org/cacert/gigi/GigiApiException.java
src/org/cacert/gigi/database/DatabaseConnection.java
src/org/cacert/gigi/database/GigiPreparedStatement.java
src/org/cacert/gigi/database/GigiResultSet.java
src/org/cacert/gigi/dbObjects/Certificate.java
src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/output/template/Scope.java [new file with mode: 0644]
src/org/cacert/gigi/pages/LoginPage.java
src/org/cacert/gigi/pages/account/domain/DomainOverview.java
src/org/cacert/gigi/pages/account/domain/PingConfigForm.java
src/org/cacert/gigi/ping/PingerDaemon.java
src/org/cacert/gigi/util/DNSUtil.java
tests/org/cacert/gigi/pages/account/TestCertificateAdd.java
tests/org/cacert/gigi/pages/account/TestChangePassword.java
tests/org/cacert/gigi/pages/account/TestContactInformation.java
tests/org/cacert/gigi/pages/account/TestDomain.java
tests/org/cacert/gigi/pages/account/TestMailManagement.java
tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java
tests/org/cacert/gigi/pages/wot/TestTTP.java
tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java
tests/org/cacert/gigi/ping/TestHTTP.java
tests/org/cacert/gigi/ping/TestSSL.java
tests/org/cacert/gigi/testUtils/ClientTest.java
tests/org/cacert/gigi/testUtils/ConfiguredTest.java
tests/org/cacert/gigi/testUtils/ManagedTest.java
tests/org/cacert/gigi/testUtils/PingTest.java

index 7ff0769c2e336a966b5769d6da5a8791f8e4d839..867a1c63704dc3bd70582d3a397c1a8f9fbc2373 100644 (file)
@@ -92,7 +92,6 @@ CREATE TABLE `pingconfig` (
   `domainid` int(11) NOT NULL,
   `type` enum('email', 'ssl', 'http', 'dns') NOT NULL,
   `info` varchar(255) NOT NULL,
-  `reping` enum('y','n') NOT NULL DEFAULT 'n',
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
index 54c1ecf8437123575ee16a519c2f8800191bf089..8c4a234c5a30a3f14ab9fa26eb12e7fd3745a573 100644 (file)
@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.Menu;
@@ -69,6 +70,8 @@ public class Gigi extends HttpServlet {
 
     public static final String USER = "user";
 
+    public static final String LOGIN_METHOD = "org.cacert.gigi.loginMethod";
+
     private static final long serialVersionUID = -6386785421902852904L;
 
     private Template baseTemplate;
@@ -303,17 +306,20 @@ public class Gigi extends HttpServlet {
 
                 }
             };
+            Language lang = Page.getLanguage(req);
+
             vars.put(Menu.USER_VALUE, currentPageUser);
             vars.put("menu", rootMenu);
-            vars.put("title", Page.getLanguage(req).getTranslation(p.getTitle()));
+            vars.put("title", lang.getTranslation(p.getTitle()));
             vars.put("static", getStaticTemplateVar(isSecure));
             vars.put("year", Calendar.getInstance().get(Calendar.YEAR));
             vars.put("content", content);
             if (currentPageUser != null) {
                 vars.put("loggedInAs", currentPageUser.getName().toString());
+                vars.put("loginMethod", lang.getTranslation((String) req.getSession().getAttribute(LOGIN_METHOD)));
             }
             resp.setContentType("text/html; charset=utf-8");
-            baseTemplate.output(resp.getWriter(), Page.getLanguage(req), vars);
+            baseTemplate.output(resp.getWriter(), lang, vars);
         } else {
             resp.sendError(404, "Page not found.");
         }
@@ -395,7 +401,17 @@ public class Gigi extends HttpServlet {
         return instance.reveresePages.get(p).replaceFirst("/?\\*$", "");
     }
 
-    public static void notifyPinger() {
+    /**
+     * Requests Pinging of domains.
+     * 
+     * @param toReping
+     *            if not null, the {@link DomainPingConfiguration} to test, if
+     *            null, just re-check if there is something to do.
+     */
+    public static void notifyPinger(DomainPingConfiguration toReping) {
+        if (toReping != null) {
+            instance.pinger.queue(toReping);
+        }
         instance.pinger.interrupt();
     }
 
index dc9c08befd7e63943b89ffa8df1ac49c5b41c3a9..478c9e9bbca1a89cf1920bcf37b27ce05804cab3 100644 (file)
@@ -20,7 +20,7 @@
                        </div>
                </div>
                <div id="pageNav">
-                       <? if($loggedInAs) { ?><div><?=_Logged in as?>: <?=$loggedInAs?></div><? } ?>
+                       <? if($loggedInAs) { ?><div><?=_Logged in as?>: <?=$loggedInAs?> <?=_with?> <?=$loginMethod?></div><? } ?>
                        <?=$menu?>
                        <div>
                                <h3 class="pointer"><?=_Advertising?></h3>
index e766d9ea9e6e56b50fa87ec69c61924da05f4c7a..b858e7d9a35d662c5ecefc10375d9a798d33349b 100644 (file)
@@ -1,16 +1,21 @@
 package org.cacert.gigi;
 
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.Locale;
 
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public class GigiApiException extends Exception {
 
     private SQLException e;
 
-    private LinkedList<String> messages = new LinkedList<>();
+    private LinkedList<Outputable> messages = new LinkedList<>();
 
     public GigiApiException(SQLException e) {
         super(e);
@@ -19,13 +24,17 @@ public class GigiApiException extends Exception {
 
     public GigiApiException(String message) {
         super(message);
-        messages.add(message);
+        messages.add(new TranslateCommand(message));
     }
 
     public GigiApiException() {
 
     }
 
+    public GigiApiException(Outputable out) {
+        messages.add(out);
+    }
+
     public void mergeInto(GigiApiException e2) {
         messages.addAll(e2.messages);
         if (e == null) {
@@ -45,9 +54,12 @@ public class GigiApiException extends Exception {
             out.println(language.getTranslation("An internal error ouccured."));
             out.println("</div>");
         }
-        for (String message : messages) {
+        HashMap<String, Object> map = new HashMap<>();
+        for (Outputable message : messages) {
+            map.clear();
+
             out.print("<div>");
-            out.print(language.getTranslation(message));
+            message.output(out, language, map);
             out.println("</div>");
         }
         out.println("</div>");
@@ -61,11 +73,17 @@ public class GigiApiException extends Exception {
     @Override
     public String getMessage() {
         if (messages.size() != 0) {
-            StringBuffer res = new StringBuffer();
-            for (String string : messages) {
-                res.append(string + "\n");
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+
+            HashMap<String, Object> map = new HashMap<>();
+            for (Outputable message : messages) {
+                map.clear();
+                message.output(pw, Language.getInstance(Locale.ENGLISH), map);
             }
-            return res.toString();
+            pw.flush();
+
+            return sw.toString();
         }
         return "";
     }
index abeb78d0d765d7888af97e79a8bd1550e65a869e..661565d843a0a3f1b428a8f114d6c92cfc34129f 100644 (file)
@@ -34,7 +34,7 @@ public class DatabaseConnection {
     private void tryConnect() {
         try {
             c = DriverManager.getConnection(credentials.getProperty("sql.url") + "?zeroDateTimeBehavior=convertToNull", credentials.getProperty("sql.user"), credentials.getProperty("sql.password"));
-            PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?;");
+            PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?, time_zone='+0:00';");
             ps.setInt(1, CONNECTION_TIMEOUT);
             ps.execute();
             ps.close();
index 81e5f4e31aa27004efb9df0468b1a2b31784b516..55ed6ad3d53d003ae6639c575dc19147a36cdfd0 100644 (file)
@@ -23,9 +23,12 @@ public class GigiPreparedStatement {
         }
     }
 
-    public int executeUpdate() {
+    public void executeUpdate() {
         try {
-            return target.executeUpdate();
+            int updated = target.executeUpdate();
+            if (updated != 1) {
+                throw new Error("FATAL: multiple or no data updated: " + updated);
+            }
         } catch (SQLException e) {
             handleSQL(e);
             throw new Error(e);
index 9dc83bd774e007d5335f24815ea3234a3c7f502a..48157ffaaa15b2c389a5f04a9e5c250dbdd8c3d5 100644 (file)
@@ -3,7 +3,6 @@ package org.cacert.gigi.database;
 import java.sql.Date;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Time;
 import java.sql.Timestamp;
 
 public class GigiResultSet {
@@ -59,15 +58,6 @@ public class GigiResultSet {
         }
     }
 
-    public Time getTime(int columnIndex) {
-        try {
-            return target.getTime(columnIndex);
-        } catch (SQLException e) {
-            handleSQL(e);
-            throw new Error(e);
-        }
-    }
-
     public String getString(String columnLabel) {
         try {
             return target.getString(columnLabel);
@@ -113,15 +103,6 @@ public class GigiResultSet {
         }
     }
 
-    public Time getTime(String columnLabel) {
-        try {
-            return target.getTime(columnLabel);
-        } catch (SQLException e) {
-            handleSQL(e);
-            throw new Error(e);
-        }
-    }
-
     public boolean next() {
         try {
             return target.next();
index df940dbc06816cf33eaaf5151dbe343705e6af62..ced044cd8d34a102fa68875e0b9d6604d7fbfdea 100644 (file)
@@ -219,10 +219,10 @@ public class Certificate {
 
         crtName = rs.getString(1);
         serial = rs.getString(4);
-        if (rs.getTime(2) == null) {
+        if (rs.getTimestamp(2) == null) {
             return CertificateStatus.DRAFT;
         }
-        if (rs.getTime(2) != null && rs.getTime(3) == null) {
+        if (rs.getTimestamp(2) != null && rs.getTimestamp(3) == null) {
             return CertificateStatus.ISSUED;
         }
         return CertificateStatus.REVOKED;
index 1146cca0c5c8b0b451c1f75c334cff0f71e87a91..e27b696d829cbc432a782546c19c5918135ad116 100644 (file)
@@ -1,8 +1,17 @@
 package org.cacert.gigi.dbObjects;
 
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cacert.gigi.Gigi;
+import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.Scope;
+import org.cacert.gigi.output.template.SprintfCommand;
 
 public class DomainPingConfiguration implements IdCachable {
 
@@ -59,10 +68,34 @@ public class DomainPingConfiguration implements IdCachable {
         return res;
     }
 
-    public void requestReping() {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE pingconfig set reping='y' WHERE id=?");
+    public Date getLastExecution() {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `when` AS stamp from domainPinglog WHERE configId=? ORDER BY `when` DESC LIMIT 1");
+        ps.setInt(1, id);
+        GigiResultSet rs = ps.executeQuery();
+        if (rs.next()) {
+            return new Date(rs.getTimestamp("stamp").getTime());
+        }
+        return new Date(0);
+    }
+
+    public Date getLastSuccess() {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `when` AS stamp from domainPinglog WHERE configId=? AND state='success' ORDER BY `when` DESC LIMIT 1");
         ps.setInt(1, id);
-        ps.execute();
+        GigiResultSet rs = ps.executeQuery();
+        if (rs.next()) {
+            return new Date(rs.getTimestamp("stamp").getTime());
+        }
+        return new Date(0);
     }
 
+    public synchronized void requestReping() throws GigiApiException {
+        Date lastExecution = getLastExecution();
+        if (lastExecution.getTime() + 5 * 60 * 1000 < System.currentTimeMillis()) {
+            Gigi.notifyPinger(this);
+            return;
+        }
+        Map<String, Object> data = new HashMap<String, Object>();
+        data.put("data", new Date(lastExecution.getTime() + 5 * 60 * 1000));
+        throw new GigiApiException(new Scope(new SprintfCommand("Reping is only allowed after 5 minutes, yours end at %s.", Arrays.asList("$data")), data));
+    }
 }
index c453465b505c36c460626c3ff149b83202225463..6363757eaafa55ec51faf049d81f4c85700ae282 100644 (file)
@@ -141,9 +141,7 @@ public class User extends CertificateOwner {
         ps = DatabaseConnection.getInstance().prepare("UPDATE users SET `password`=? WHERE id=?");
         ps.setString(1, PasswordHash.hash(newPass));
         ps.setInt(2, getId());
-        if (ps.executeUpdate() != 1) {
-            throw new GigiApiException("Password update failed.");
-        }
+        ps.executeUpdate();
     }
 
     public void setName(Name name) {
@@ -469,7 +467,7 @@ public class User extends CertificateOwner {
             return getAssurancePoints() > 50 && isInGroup(Group.getByString("codesigning"));
         case 3:
         case 4:
-            return false; // has an orga
+            return getOrganisations().size() > 0;
         default:
             return false;
         }
diff --git a/src/org/cacert/gigi/output/template/Scope.java b/src/org/cacert/gigi/output/template/Scope.java
new file mode 100644 (file)
index 0000000..9a15b3a
--- /dev/null
@@ -0,0 +1,28 @@
+package org.cacert.gigi.output.template;
+
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cacert.gigi.localisation.Language;
+
+public class Scope implements Outputable {
+
+    private Map<String, Object> vars;
+
+    private Outputable out;
+
+    public Scope(Outputable out, Map<String, Object> vars) {
+        this.out = out;
+        this.vars = vars;
+    }
+
+    @Override
+    public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+        HashMap<String, Object> map = new HashMap<>();
+        map.putAll(vars);
+        map.putAll(this.vars);
+        this.out.output(out, l, map);
+    }
+
+}
index 128855fcf0dced4e2ed690cfda5c92fdc887ed88..ed01ceb6ccc90e9817cbe1fc64546f136ecaa08e 100644 (file)
@@ -107,6 +107,7 @@ public class LoginPage extends Page {
                     gps.executeUpdate();
                 }
                 loginSession(req, User.getById(rs.getInt(2)));
+                req.getSession().setAttribute(LOGIN_METHOD, "Password");
             }
         }
         rs.close();
@@ -125,6 +126,7 @@ public class LoginPage extends Page {
             loginSession(req, User.getById(rs.getInt(1)));
             req.getSession().setAttribute(CERT_SERIAL, serial);
             req.getSession().setAttribute(CERT_ISSUER, x509Certificate.getIssuerDN());
+            req.getSession().setAttribute(LOGIN_METHOD, "Certificate");
         }
         rs.close();
     }
index 1677029252fea60efe71a0209d48175287464a4f..906e2a16b88e266cc2c11c1e08b7fc04b2d057d3 100644 (file)
@@ -6,7 +6,6 @@ import java.util.HashMap;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Domain;
 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
@@ -71,8 +70,12 @@ public class DomainOverview extends Page {
             if (dpc.getTarget() != d) {
                 return;
             }
-            dpc.requestReping();
-            Gigi.notifyPinger();
+            try {
+                dpc.requestReping();
+            } catch (GigiApiException e) {
+                e.format(resp.getWriter(), getLanguage(req));
+                return;
+            }
             resp.sendRedirect(PATH + i);
         }
         if (req.getParameter("adddomain") != null) {
index 91ea7cc0f2bfbb4b185094eb8172f5feffcf83f1..5b5da852ca0356709b0e17aeacd0ab99e84651e0 100644 (file)
@@ -133,7 +133,7 @@ public class PingConfigForm extends Form {
 
             }
         }
-        Gigi.notifyPinger();
+        Gigi.notifyPinger(null);
         return false;
     }
 
index 2a3167438851969d613ea8575ebd4d5ae0850c72..ceb88e9a68b80447207749c4797a3599cd8049c6 100644 (file)
@@ -2,42 +2,56 @@ package org.cacert.gigi.ping;
 
 import java.security.KeyStore;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Queue;
 
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.dbObjects.Domain;
-import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.util.RandomToken;
 
 public class PingerDaemon extends Thread {
 
-    HashMap<String, DomainPinger> pingers = new HashMap<>();
+    HashMap<PingType, DomainPinger> pingers = new HashMap<>();
 
     private GigiPreparedStatement searchNeededPings;
 
     private GigiPreparedStatement enterPingResult;
 
-    private GigiPreparedStatement updatePingStatus;
-
     private KeyStore truststore;
 
+    private Queue<DomainPingConfiguration> toExecute = new LinkedList<>();
+
     public PingerDaemon(KeyStore truststore) {
         this.truststore = truststore;
     }
 
     @Override
     public void run() {
-        searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT pingconfig.*, domains.domain, domains.memid FROM pingconfig LEFT JOIN domainPinglog ON domainPinglog.configId=pingconfig.id INNER JOIN domains ON domains.id=pingconfig.domainid WHERE ( pingconfig.reping='y' OR domainPinglog.configId IS NULL) AND domains.deleted IS NULL GROUP BY pingconfig.id");
+        searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT pingconfig.id FROM pingconfig LEFT JOIN domainPinglog ON domainPinglog.configId=pingconfig.id INNER JOIN domains ON domains.id=pingconfig.domainid WHERE ( domainPinglog.configId IS NULL) AND domains.deleted IS NULL GROUP BY pingconfig.id");
         enterPingResult = DatabaseConnection.getInstance().prepare("INSERT INTO domainPinglog SET configId=?, state=?, result=?, challenge=?");
-        updatePingStatus = DatabaseConnection.getInstance().prepare("UPDATE pingconfig SET reping='n' WHERE id=?");
-        pingers.put("email", new EmailPinger());
-        pingers.put("ssl", new SSLPinger(truststore));
-        pingers.put("http", new HTTPFetch());
-        pingers.put("dns", new DNSPinger());
+        pingers.put(PingType.EMAIL, new EmailPinger());
+        pingers.put(PingType.SSL, new SSLPinger(truststore));
+        pingers.put(PingType.HTTP, new HTTPFetch());
+        pingers.put(PingType.DNS, new DNSPinger());
 
         while (true) {
-            execute();
+            synchronized (this) {
+                DomainPingConfiguration conf;
+                while ((conf = toExecute.peek()) != null) {
+                    handle(conf);
+                    toExecute.remove();
+                }
+                notifyAll();
+            }
+
+            GigiResultSet rs = searchNeededPings.executeQuery();
+            while (rs.next()) {
+                handle(DomainPingConfiguration.getById(rs.getInt("id")));
+            }
             try {
                 Thread.sleep(5000);
             } catch (InterruptedException e) {
@@ -45,29 +59,35 @@ public class PingerDaemon extends Thread {
         }
     }
 
-    private void execute() {
-
-        GigiResultSet rs = searchNeededPings.executeQuery();
-        while (rs.next()) {
-            String type = rs.getString("type");
-            String config = rs.getString("info");
-            DomainPinger dp = pingers.get(type);
-            if (dp != null) {
-                String token = null;
-                if (dp instanceof EmailPinger) {
-                    token = RandomToken.generateToken(16);
-                    config = config + ":" + token;
-                }
-                updatePingStatus.setInt(1, rs.getInt("id"));
-                updatePingStatus.execute();
-                enterPingResult.setInt(1, rs.getInt("id"));
-                String resp = dp.ping(Domain.getById(rs.getInt("domainid")), config, User.getById(rs.getInt("memid")));
-                enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == resp ? "open" : DomainPinger.PING_SUCCEDED.equals(resp) ? "success" : "failed");
-                enterPingResult.setString(3, resp);
-                enterPingResult.setString(4, token);
-                enterPingResult.execute();
+    private void handle(DomainPingConfiguration conf) {
+        PingType type = conf.getType();
+        String config = conf.getInfo();
+        DomainPinger dp = pingers.get(type);
+        if (dp != null) {
+            String token = null;
+            if (dp instanceof EmailPinger) {
+                token = RandomToken.generateToken(16);
+                config = config + ":" + token;
             }
+            enterPingResult.setInt(1, conf.getId());
+            Domain target = conf.getTarget();
+            String resp = dp.ping(target, config, target.getOwner());
+            enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == resp ? "open" : DomainPinger.PING_SUCCEDED.equals(resp) ? "success" : "failed");
+            enterPingResult.setString(3, resp);
+            enterPingResult.setString(4, token);
+            enterPingResult.execute();
         }
     }
 
+    public synchronized void queue(DomainPingConfiguration toReping) {
+        interrupt();
+        toExecute.add(toReping);
+        while (toExecute.size() > 0) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
 }
index e8a3a40d2edc179f3be6245badb51e9ad980f819..816b24731bc576635096e30ab691b1fb9e5e6b9b 100644 (file)
@@ -15,8 +15,6 @@ public class DNSUtil {
     static {
         Hashtable<String, String> env = new Hashtable<String, String>();
         env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
-        // env.put(Context.AUTHORITATIVE, "true");
-        // env.put(Context.PROVIDER_URL, "dns://ns.dyn.dogcraft.de");
         try {
             context = new InitialDirContext(env);
         } catch (NamingException e) {
index e1cc64fddffea0b3d7d19410b29a2c00bc251ddd..ba36830be206646de8b20f15b6492cc0c65d7f81 100644 (file)
@@ -31,11 +31,10 @@ import java.util.regex.Pattern;
 
 import org.cacert.gigi.crypto.SPKAC;
 import org.cacert.gigi.dbObjects.Digest;
-import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.certs.CertificateAdd;
 import org.cacert.gigi.pages.account.certs.CertificateIssueForm;
+import org.cacert.gigi.testUtils.ClientTest;
 import org.cacert.gigi.testUtils.IOUtils;
-import org.cacert.gigi.testUtils.ManagedTest;
 import org.cacert.gigi.util.PEM;
 import org.junit.Test;
 
@@ -53,18 +52,14 @@ import sun.security.x509.RFC822Name;
 import sun.security.x509.SubjectAlternativeNameExtension;
 import sun.security.x509.X509Key;
 
-public class TestCertificateAdd extends ManagedTest {
+public class TestCertificateAdd extends ClientTest {
 
     KeyPair kp = generateKeypair();
 
-    User u = User.getById(createVerifiedUser("testuser", "testname", uniq + "@testdom.com", TEST_PASSWORD));
-
-    String session = login(uniq + "@testdom.com", TEST_PASSWORD);
-
     String csrf;
 
     public TestCertificateAdd() throws GeneralSecurityException, IOException {
-        TestDomain.addDomain(session, uniq + ".tld");
+        TestDomain.addDomain(cookie, uniq + ".tld");
 
     }
 
@@ -86,13 +81,13 @@ public class TestCertificateAdd extends ManagedTest {
     public void testSimpleMail() throws IOException, GeneralSecurityException {
         PKCS10Attributes atts = buildAtts(new ObjectIdentifier[] {
             CertificateIssueForm.OID_KEY_USAGE_EMAIL_PROTECTION
-        }, new DNSName("a." + uniq + ".tld"), new DNSName("b." + uniq + ".tld"), new RFC822Name(uniq + "@testdom.com"));
+        }, new DNSName("a." + uniq + ".tld"), new DNSName("b." + uniq + ".tld"), new RFC822Name(email));
 
-        String pem = generatePEMCSR(kp, "CN=testuser testname", atts, "SHA384WithRSA");
+        String pem = generatePEMCSR(kp, "CN=a b", atts, "SHA384WithRSA");
 
         String[] res = fillOutForm("CSR=" + URLEncoder.encode(pem, "UTF-8"));
         assertArrayEquals(new String[] {
-                "mail", "testuser testname", "dns:a." + uniq + ".tld\ndns:b." + uniq + ".tld\nemail:" + uniq + "@testdom.com\n", Digest.SHA384.toString()
+                "mail", "a b", "dns:a." + uniq + ".tld\ndns:b." + uniq + ".tld\nemail:" + email + "\n", Digest.SHA384.toString()
         }, res);
     }
 
@@ -100,13 +95,13 @@ public class TestCertificateAdd extends ManagedTest {
     public void testSimpleClient() throws IOException, GeneralSecurityException {
         PKCS10Attributes atts = buildAtts(new ObjectIdentifier[] {
             CertificateIssueForm.OID_KEY_USAGE_SSL_CLIENT
-        }, new RFC822Name(uniq + "@testdom.com"));
+        }, new RFC822Name(email));
 
-        String pem = generatePEMCSR(kp, "CN=testuser testname,email=" + uniq + "@testdom.com", atts, "SHA512WithRSA");
+        String pem = generatePEMCSR(kp, "CN=a b,email=" + email, atts, "SHA512WithRSA");
 
         String[] res = fillOutForm("CSR=" + URLEncoder.encode(pem, "UTF-8"));
         assertArrayEquals(new String[] {
-                "client", "testuser testname", "email:" + uniq + "@testdom.com\n", Digest.SHA512.toString()
+                "client", "a b", "email:" + email + "\n", Digest.SHA512.toString()
         }, res);
     }
 
@@ -120,21 +115,21 @@ public class TestCertificateAdd extends ManagedTest {
     public void testIssue() throws IOException, GeneralSecurityException {
         PKCS10Attributes atts = buildAtts(new ObjectIdentifier[] {
             CertificateIssueForm.OID_KEY_USAGE_SSL_CLIENT
-        }, new RFC822Name(uniq + "@testdom.com"));
+        }, new RFC822Name(email));
 
-        String pem = generatePEMCSR(kp, "CN=testuser testname,email=" + uniq + "@testdom.com", atts, "SHA512WithRSA");
+        String pem = generatePEMCSR(kp, "CN=a b,email=" + email, atts, "SHA512WithRSA");
 
         String[] res = fillOutForm("CSR=" + URLEncoder.encode(pem, "UTF-8"));
         assertArrayEquals(new String[] {
-                "client", "testuser testname", "email:" + uniq + "@testdom.com\n", Digest.SHA512.toString()
+                "client", "a b", "email:" + email + "\n", Digest.SHA512.toString()
         }, res);
 
         HttpURLConnection huc = (HttpURLConnection) ncert.openConnection();
-        huc.setRequestProperty("Cookie", session);
+        huc.setRequestProperty("Cookie", cookie);
         huc.setDoOutput(true);
         OutputStream out = huc.getOutputStream();
         out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes());
-        out.write(("&profile=client&CN=testuser+testname&SANs=" + URLEncoder.encode("email:" + uniq + "@testdom.com\n", "UTF-8")).getBytes());
+        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes());
         out.write(("&hash_alg=SHA512&CCA=y").getBytes());
         URLConnection uc = authenticate(new URL(huc.getHeaderField("Location") + ".crt"));
         String crt = IOUtils.readURL(new InputStreamReader(uc.getInputStream(), "UTF-8"));
@@ -151,9 +146,9 @@ public class TestCertificateAdd extends ManagedTest {
         uc = authenticate(new URL(huc.getHeaderField("Location")));
         String gui = IOUtils.readURL(uc);
         assertThat(gui, containsString("clientAuth"));
-        assertThat(gui, containsString("CN=testuser testname"));
+        assertThat(gui, containsString("CN=a b"));
         assertThat(gui, containsString("SHA512withRSA"));
-        assertThat(gui, containsString("RFC822Name: " + uniq + "@testdom.com"));
+        assertThat(gui, containsString("RFC822Name: " + email));
 
     }
 
@@ -207,17 +202,17 @@ public class TestCertificateAdd extends ManagedTest {
     private X509Certificate createCertWithValidity(String validity) throws IOException, GeneralSecurityException, UnsupportedEncodingException, MalformedURLException, CertificateException {
         PKCS10Attributes atts = buildAtts(new ObjectIdentifier[] {
             CertificateIssueForm.OID_KEY_USAGE_SSL_CLIENT
-        }, new RFC822Name(uniq + "@testdom.com"));
+        }, new RFC822Name(email));
 
-        String pem = generatePEMCSR(kp, "CN=testuser testname", atts, "SHA512WithRSA");
+        String pem = generatePEMCSR(kp, "CN=a b", atts, "SHA512WithRSA");
         fillOutForm("CSR=" + URLEncoder.encode(pem, "UTF-8"));
 
         HttpURLConnection huc = (HttpURLConnection) ncert.openConnection();
-        huc.setRequestProperty("Cookie", session);
+        huc.setRequestProperty("Cookie", cookie);
         huc.setDoOutput(true);
         OutputStream out = huc.getOutputStream();
         out.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8")).getBytes());
-        out.write(("&profile=client&CN=testuser+testname&SANs=" + URLEncoder.encode("email:" + uniq + "@testdom.com\n", "UTF-8")).getBytes());
+        out.write(("&profile=client&CN=a+b&SANs=" + URLEncoder.encode("email:" + email + "\n", "UTF-8")).getBytes());
         out.write(("&hash_alg=SHA512&CCA=y&").getBytes());
         out.write(validity.getBytes());
 
@@ -235,13 +230,13 @@ public class TestCertificateAdd extends ManagedTest {
 
     private URLConnection authenticate(URL url) throws IOException {
         URLConnection uc = url.openConnection();
-        uc.setRequestProperty("Cookie", session);
+        uc.setRequestProperty("Cookie", cookie);
         return uc;
     }
 
     protected String testSPKAC(boolean correctChallange) throws GeneralSecurityException, IOException {
         HttpURLConnection uc = (HttpURLConnection) ncert.openConnection();
-        uc.setRequestProperty("Cookie", session);
+        uc.setRequestProperty("Cookie", cookie);
         String s = IOUtils.readURL(uc);
 
         csrf = extractPattern(s, Pattern.compile("<input [^>]*name='csrf' [^>]*value='([^']*)'>"));
@@ -285,7 +280,7 @@ public class TestCertificateAdd extends ManagedTest {
 
     private String[] fillOutForm(String pem) throws IOException {
         HttpURLConnection uc = (HttpURLConnection) ncert.openConnection();
-        uc.setRequestProperty("Cookie", session);
+        uc.setRequestProperty("Cookie", cookie);
         csrf = getCSRF(uc);
         return fillOutFormDirect(pem);
 
@@ -294,7 +289,7 @@ public class TestCertificateAdd extends ManagedTest {
     private String[] fillOutFormDirect(String pem) throws IOException {
 
         HttpURLConnection uc = (HttpURLConnection) ncert.openConnection();
-        uc.setRequestProperty("Cookie", session);
+        uc.setRequestProperty("Cookie", cookie);
         uc.setDoOutput(true);
         uc.getOutputStream().write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" + pem).getBytes());
         uc.getOutputStream().flush();
index 21be9c15113f343171ad17b457fc914b72d35ac9..89d318e6e54e06c89fd0b8105fb366d75e395759 100644 (file)
@@ -6,15 +6,10 @@ import java.io.IOException;
 import java.net.URLEncoder;
 
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.dbObjects.User;
-import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.ClientTest;
 import org.junit.Test;
 
-public class TestChangePassword extends ManagedTest {
-
-    User u = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
-
-    String cookie;
+public class TestChangePassword extends ClientTest {
 
     String path = ChangePasswordPage.PATH;
 
index 6360578b42da418202fd4273fafa6e50b66dcaf4..c63e36d2b3d76866e521fdd7ce305ef111555cd1 100644 (file)
@@ -7,17 +7,14 @@ import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.cacert.gigi.testUtils.ClientTest;
 import org.cacert.gigi.testUtils.IOUtils;
-import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Test;
 
-public class TestContactInformation extends ManagedTest {
+public class TestContactInformation extends ClientTest {
 
     @Test
     public void testDirectoryListingToggle() throws IOException {
-        String email = createUniqueName() + "@e.fg";
-        createVerifiedUser("Kurti", createUniqueName(), email, TEST_PASSWORD);
-        String cookie = login(email, TEST_PASSWORD);
         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=&processContact", 1));
         URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
         url.setRequestProperty("Cookie", cookie);
@@ -34,9 +31,6 @@ public class TestContactInformation extends ManagedTest {
 
     @Test
     public void testContactinfoSet() throws IOException {
-        String email = createUniqueName() + "@e.fg";
-        createVerifiedUser("Kurti", createUniqueName(), email, TEST_PASSWORD);
-        String cookie = login(email, TEST_PASSWORD);
         String text = createUniqueName();
         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=" + text + "&processContact", 1));
         URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
index faa9ac8b58e6a659e24dfd03e5dfba49cedde0d4..1a3a5a081f3cdbbeef92838061d739ec82073b3b 100644 (file)
@@ -5,23 +5,18 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 import java.net.URLEncoder;
 
-import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
-import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.ClientTest;
 import org.junit.Test;
 
-public class TestDomain extends ManagedTest {
-
-    User u = User.getById(createVerifiedUser("testuser", "testname", uniq + "@testdom.com", TEST_PASSWORD));
-
-    String session = login(uniq + "@testdom.com", TEST_PASSWORD);
+public class TestDomain extends ClientTest {
 
     public TestDomain() throws IOException {}
 
     @Test
     public void testAdd() throws IOException {
-        assertNull(addDomain(session, uniq + ".de"));
-        assertNotNull(addDomain(session, uniq + ".de"));
+        assertNull(addDomain(cookie, uniq + ".de"));
+        assertNotNull(addDomain(cookie, uniq + ".de"));
     }
 
     public static String addDomain(String session, String domain) throws IOException {
index 190dd5a0237e4ba98d1751ba7ff9e99f7747a456..6659a1e115cbacb5467aca7c3cbe8e75267ee8b0 100644 (file)
@@ -14,14 +14,10 @@ import org.cacert.gigi.dbObjects.ObjectCache;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.pages.account.mail.MailOverview;
-import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.ClientTest;
 import org.junit.Test;
 
-public class TestMailManagement extends ManagedTest {
-
-    private User u = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
-
-    private String cookie;
+public class TestMailManagement extends ClientTest {
 
     private String path = MailOverview.DEFAULT_PATH;
 
@@ -136,4 +132,10 @@ public class TestMailManagement extends ManagedTest {
         u2 = User.getById(u2.getId());
         assertNotEquals(u2.getEmails().length, 0);
     }
+
+    @Test
+    public void testMailDeleteWebPrimary() throws MalformedURLException, UnsupportedEncodingException, IOException {
+        assertNotNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + u.getEmails()[0].getId(), 0));
+        assertNotEquals(u.getEmails().length, 0);
+    }
 }
index 2623fa020ac85b3fa61f810087d8049a16c8489c..f0a07a801d39e24ff8c2d912834c36061385000e 100644 (file)
@@ -14,25 +14,21 @@ 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"));
         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=mail&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());
@@ -41,14 +37,14 @@ public class TestOrgaManagement extends ManagedTest {
         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") + "&do_affiliate=y&master=y", 1);
+        executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + orgs[0].getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1);
         List<Affiliation> 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") + "&do_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);
@@ -58,13 +54,13 @@ 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=&do_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=&do_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());
@@ -89,13 +85,13 @@ 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();
index 9f5aae30477202161d72d4769279c00bf6ee7e7e..7c8884ba8c22acb8a6952af95ac0fdabc5119301 100644 (file)
@@ -10,15 +10,11 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.ObjectCache;
 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 TestTTP extends ManagedTest {
-
-    User u = User.getById(createVerifiedUser("fn", "ln", "test-" + createUniqueName() + "@example.org", TEST_PASSWORD));
-
-    String cookie = login(u.getEmail(), TEST_PASSWORD);
+public class TestTTP extends ClientTest {
 
     URL ttpPage = new URL("https://" + getServerName() + RequestTTPPage.PATH);
 
index b1cbf9aba6625e1349eaf435bc2ed51fa58648fe..32c4268afc120846f613a5a72d07917b9953e824 100644 (file)
@@ -10,21 +10,14 @@ import java.net.URL;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.admin.TTPAdminPage;
-import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.ClientTest;
 import org.junit.Test;
 
-public class TestTTPAdmin extends ManagedTest {
-
-    User us;
-
-    String cookie;
+public class TestTTPAdmin extends ClientTest {
 
     User us2;
 
     public TestTTPAdmin() throws IOException {
-        String email = uniq + "@example.com";
-        us = User.getById(createVerifiedUser("fn", "ln", email, TEST_PASSWORD));
-        cookie = login(email, TEST_PASSWORD);
         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
     }
 
@@ -40,14 +33,14 @@ public class TestTTPAdmin extends ManagedTest {
 
     public void testTTPAdmin(boolean hasRight) throws IOException {
         if (hasRight) {
-            grant(us.getEmail(), Group.getByString("ttp-assurer"));
+            grant(email, Group.getByString("ttp-assurer"));
         }
-        grant(us.getEmail(), TTPAdminPage.TTP_APPLICANT);
-        cookie = login(us.getEmail(), TEST_PASSWORD);
+        grant(u.getEmail(), 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 + "/" + us.getId()));
+        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));
     }
index dffab08f2413a05bfbe8fdc4f44934cf2f124e5b..64c9cd650e3e618d7c51cd194f3b70158554e7b1 100644 (file)
@@ -1,5 +1,6 @@
 package org.cacert.gigi.ping;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
@@ -13,6 +14,10 @@ import java.util.regex.Pattern;
 
 import javax.naming.NamingException;
 
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Domain;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration;
+import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.PingTest;
@@ -34,21 +39,21 @@ public class TestHTTP extends PingTest {
     }
 
     @Test
-    public void httpAndMailSuccess() throws IOException, InterruptedException, SQLException {
+    public void httpAndMailSuccess() throws Exception {
         testEmailAndHTTP(0, 0, true, true);
     }
 
     @Test
-    public void httpFailKeyAndMailSuccess() throws IOException, InterruptedException, SQLException {
+    public void httpFailKeyAndMailSuccess() throws Exception {
         testEmailAndHTTP(1, 0, false, true);
     }
 
     @Test
-    public void httpFailValAndMailFail() throws IOException, InterruptedException, SQLException {
+    public void httpFailValAndMailFail() throws Exception {
         testEmailAndHTTP(2, 1, false, false);
     }
 
-    public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException {
+    public void testEmailAndHTTP(int httpVariant, int emailVariant, boolean successHTTP, boolean successMail) throws IOException, InterruptedException, SQLException, GigiApiException {
 
         String test = getTestProps().getProperty("domain.http");
         assumeNotNull(test);
@@ -78,6 +83,23 @@ public class TestHTTP extends PingTest {
         assertTrue(newcontent, !successHTTP ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
+
+        if (successHTTP) { // give it a second try
+            int id = Integer.parseInt(u2.toString().replaceFirst("^.*/([0-9]+)$", "$1"));
+            Domain d = Domain.getById(id);
+            DomainPingConfiguration dpc = null;
+            for (DomainPingConfiguration conf : d.getConfiguredPings()) {
+                if (conf.getType() == PingType.HTTP) {
+                    dpc = conf;
+                    break;
+                }
+            }
+            if (dpc == null) {
+                fail("Http config not found");
+            }
+            String res = executeBasicWebInteraction(cookie, u2.getPath(), "configId=" + dpc.getId());
+            assertThat(res, containsString("only allowed after"));
+        }
     }
 
     private String readHTTP(String token) throws IOException {
index 007d570b435b6ff32e15420f209610cb47d94c5b..610e11536700513835604187bdce687a96dd0c0d 100644 (file)
@@ -139,7 +139,7 @@ public class TestSSL extends PingTest {
     private void createCertificate(String test, CertificateProfile profile) throws GeneralSecurityException, IOException, SQLException, InterruptedException, GigiApiException {
         kp = generateKeypair();
         String csr = generatePEMCSR(kp, "CN=" + test);
-        c = new Certificate(User.getById(userid), Certificate.buildDN("CN", test), "sha256", csr, CSRType.CSR, profile);
+        c = new Certificate(User.getById(id), Certificate.buildDN("CN", test), "sha256", csr, CSRType.CSR, profile);
         c.issue(null, "2y").waitFor(60000);
     }
 
index ab88844f07c218f380179d05fae87f3d9a9d6003..fc22e6d086bc58399c3463e30aa237f8db32a94d 100644 (file)
@@ -2,15 +2,33 @@ package org.cacert.gigi.testUtils;
 
 import java.io.IOException;
 
+import org.cacert.gigi.dbObjects.User;
+
+/**
+ * Superclass for testsuites in a scenario where there is an registered member,
+ * who is already logged on.
+ */
 public abstract class ClientTest extends ManagedTest {
 
+    /**
+     * Email of the member.
+     */
     protected String email = createUniqueName() + "@example.org";
 
-    protected int userid = createVerifiedUser("a", "b", email, TEST_PASSWORD);
+    /**
+     * Id of the member
+     */
+    protected int id = createVerifiedUser("a", "b", email, TEST_PASSWORD);
 
-    protected String cookie;
+    /**
+     * {@link User} object of the member
+     */
+    protected User u = User.getById(id);
 
-    protected String csrf;
+    /**
+     * Session cookie of the member.
+     */
+    protected String cookie;
 
     public ClientTest() {
         try {
index a6bbed85be7c6684a6dfabeaaa3370f952aecd96..97b8823b7888c96add41158c13c9a612864eff43 100644 (file)
@@ -20,7 +20,11 @@ import sun.security.pkcs10.PKCS10;
 import sun.security.pkcs10.PKCS10Attributes;
 import sun.security.x509.X500Name;
 
-public class ConfiguredTest {
+/**
+ * Base class for a Testsuite that makes use of the config variables that define
+ * the environment.
+ */
+public abstract class ConfiguredTest {
 
     static Properties testProps = new Properties();
 
index c0c8ad49275843b94aa64ac1de90b78780c53bd7..ce96cf2894497caac41c31b93f710856e973dcb1 100644 (file)
@@ -55,6 +55,10 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
+/**
+ * Base class for test suites who require a launched Gigi instance. The instance
+ * is cleared once per test suite.
+ */
 public class ManagedTest extends ConfiguredTest {
 
     static {
@@ -62,7 +66,7 @@ public class ManagedTest extends ConfiguredTest {
     }
 
     /**
-     * Some password that fullfills the password criteria.
+     * Some password that fulfills the password criteria.
      */
     protected static final String TEST_PASSWORD = "xvXV12°§";
 
index 50d5d7fc14696a97692c39e8fb85b35ec8feb9ed..4fb49595c316e84a5e9452f14bd6ebb7e82fd991 100644 (file)
@@ -18,8 +18,14 @@ import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
 import org.junit.After;
 
+/**
+ * Base class for test suites that check extensively if the domain-ping
+ * functionality wroks as expected.
+ */
 public abstract class PingTest extends ClientTest {
 
+    protected String csrf;
+
     protected static void updateService(String token, String value, String action) throws IOException, MalformedURLException {
         String manage = getTestProps().getProperty("domain.manage");
         assumeNotNull(manage);