]> WPIA git - gigi.git/commitdiff
Fix testcases.
authorFelix Dörre <felix@dogcraft.de>
Sat, 1 Nov 2014 19:31:31 +0000 (20:31 +0100)
committerJanis Streib <janis@dogcraft.de>
Wed, 31 Dec 2014 01:35:55 +0000 (02:35 +0100)
src/org/cacert/gigi/dbObjects/CertificateOwner.java
src/org/cacert/gigi/dbObjects/ObjectCache.java
src/org/cacert/gigi/dbObjects/Organisation.java
src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java
tests/org/cacert/gigi/pages/account/TestCertificateAdd.java
tests/org/cacert/gigi/pages/orga/TestOrgaManagement.java

index 3091de6c98c806eff28ffc2e5e10c786b16b359d..7c111beea4b1ecfb26b50acebe4e3b6f3cb2cf7c 100644 (file)
@@ -23,7 +23,7 @@ public abstract class CertificateOwner implements IdCachable {
     public static synchronized CertificateOwner getById(int id) {
         CertificateOwner u = myCache.get(id);
         if (u == null) {
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT *, users.id AS uid, organisations.id AS oid FROM certOwners LEFT JOIN users ON users.id=certOwners.id LEFT JOIN organisations ON organisations.id = certOwners.id WHERE certOwners.id=?");
+            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT *, users.id AS uid, organisations.id AS oid FROM certOwners LEFT JOIN users ON users.id=certOwners.id LEFT JOIN organisations ON organisations.id = certOwners.id WHERE certOwners.id=? AND deleted is null");
             ps.setInt(1, id);
             GigiResultSet rs = ps.executeQuery();
             if ( !rs.next()) {
@@ -129,4 +129,10 @@ public abstract class CertificateOwner implements IdCachable {
         return false;
     }
 
+    public void delete() {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE certowners set deleted=NOW() WHERE id=?");
+        ps.setInt(1, getId());
+        ps.execute();
+        myCache.remove(this);
+    }
 }
index 1d239757fd0cb47b63140752cde16623c8e695ba..d1e41f82e3baaa0b359e6d55b1283fb81e0b85c4 100644 (file)
@@ -31,4 +31,8 @@ public class ObjectCache<T extends IdCachable> {
             objectCache.hashmap.clear();
         }
     }
+
+    public void remove(T toRm) {
+        hashmap.remove(toRm);
+    }
 }
index 633412c440fff98732c4fdfc11a0e9bfe2505cfa..25a11b7a2fc897f36f75ffa9c53ce67a7c16bbff 100644 (file)
@@ -138,7 +138,7 @@ public class Organisation extends CertificateOwner {
     }
 
     public static Organisation[] getOrganisations(int offset, int count) {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id FROM organisations LIMIT ?,?");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT certOwners.id FROM organisations inner join certOwners on certOwners.id=organisations.id where certOwners.deleted is null LIMIT ?,?");
         ps.setInt(1, offset);
         ps.setInt(2, count);
         GigiResultSet res = ps.executeQuery();
index 87cf0e379e750d45f5031e7136b2be8162a4bf83..f6b35f9644d0c61a5c430db7bd87740034d133e6 100644 (file)
@@ -251,11 +251,14 @@ public class CertificateIssueForm extends Form {
                         selectedDigest = Digest.valueOf(hashAlg);
                     }
                     profile = CertificateProfile.getByName(req.getParameter("profile"));
-                    Organisation neworg = Organisation.getById(Integer.parseInt(req.getParameter("org")));
-                    if (neworg == null || u.getOrganisations().contains(neworg)) {
-                        org = neworg;
-                    } else {
-                        outputError(out, req, "Selected Organisation is not part of your account.");
+                    String newOrgStr = req.getParameter("org");
+                    if (newOrgStr != null) {
+                        Organisation neworg = Organisation.getById(Integer.parseInt(newOrgStr));
+                        if (neworg == null || u.getOrganisations().contains(neworg)) {
+                            org = neworg;
+                        } else {
+                            outputError(out, req, "Selected Organisation is not part of your account.");
+                        }
                     }
                     ou = req.getParameter("OU");
                     if ( !u.canIssue(profile)) {
index 6490c4aa6da1ad4f15e3f86b8f22f8a15191b2b0..e1cc64fddffea0b3d7d19410b29a2c00bc251ddd 100644 (file)
@@ -310,7 +310,7 @@ public class TestCertificateAdd extends ManagedTest {
         }
 
         String profileKey = extractPattern(result, Pattern.compile("<option value=\"([^\"]*)\" selected>"));
-        String resultingCN = extractPattern(result, Pattern.compile("<input [^>]*name='CN' [^>]*value='([^']*)'>"));
+        String resultingCN = extractPattern(result, Pattern.compile("<input [^>]*name='CN' [^>]*value='([^']*)'/>"));
         String txt = extractPattern(result, Pattern.compile("<textarea [^>]*name='SANs' [^>]*>([^<]*)</textarea>"));
         String md = extractPattern(result, Pattern.compile("<input type=\"radio\" [^>]*name=\"hash_alg\" value=\"([^\"]*)\" checked='checked'/>"));
         return new String[] {
index 45e25e698ff8ef6ced00695273622f55e576db0c..bd0b8f4b5cb46241b55b80c587ffb1ad93f76b83 100644 (file)
@@ -96,5 +96,7 @@ public class TestOrgaManagement extends ManagedTest {
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
         uc = cookie(new URL("https://" + getServerName() + ViewOrgPage.DEFAULT_PATH + "/" + o2.getId()).openConnection(), session);
         assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
+        o1.delete();
+        o2.delete();
     }
 }