]> WPIA git - gigi.git/commitdiff
Merge "fix: only run fetch-locales in postinst configure"
authorFelix Dörre <felix@dogcraft.de>
Mon, 29 Aug 2016 11:32:35 +0000 (13:32 +0200)
committerGerrit Code Review <gigi-system@dogcraft.de>
Mon, 29 Aug 2016 11:32:35 +0000 (13:32 +0200)
src/org/cacert/gigi/dbObjects/SupportedUser.java
src/org/cacert/gigi/pages/account/certs/CertificateRequest.java
src/org/cacert/gigi/util/CAA.java
src/org/cacert/gigi/util/ServerConstants.java
tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java
tests/org/cacert/gigi/util/TestCAAValidation.java

index 18bfbee21fe345dbce3c3be8c640bbec0d05e72a..940e67fc89b689c7bfa8e8e2ecdda5100fbab81d 100644 (file)
@@ -120,6 +120,11 @@ public class SupportedUser {
         // send notification to user
         message = SprintfCommand.createSimple("The group permission '{0}' was granted to your account.", toMod.getName());
         sendSupportUserNotification(subject, message);
+        if (toMod == Group.SUPPORTER) {
+            subject = "Support role granted";
+            message = SprintfCommand.createSimple("The group permission '{0}' was granted for '{1}'.", toMod.getName(), target.getPreferredName().toString());
+            sendBoardNotification(subject, message);
+        }
     }
 
     public void revoke(Group toMod) {
@@ -131,6 +136,11 @@ public class SupportedUser {
         // send notification to user
         message = SprintfCommand.createSimple("The group permission '{0}' was revoked from your account.", toMod.getName());
         sendSupportUserNotification(subject, message);
+        if (toMod == Group.SUPPORTER) {
+            subject = "Support role revoked";
+            message = SprintfCommand.createSimple("The group permission '{0}' was revoked for '{1}'.", toMod.getName(), target.getPreferredName().toString());
+            sendBoardNotification(subject, message);
+        }
     }
 
     private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
@@ -173,4 +183,19 @@ public class SupportedUser {
         Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
         sendSupportNotification(subject, message);
     }
+
+    private void sendBoardNotification(String subject, Outputable message) {
+        try {
+            HashMap<String, Object> vars = new HashMap<>();
+            vars.put("supporter", supporter.getPreferredName().toString());
+            vars.put("action", message);
+            vars.put("ticket", this.getTicket());
+            vars.put("subject", subject);
+
+            String boardemailaddress = ServerConstants.getBoardMailAddress();
+            supportNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, boardemailaddress);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
index 43e4fbd8205591ef31639689995cc7786f67a8e3..e1bf47cc9bde9de5d1b56252f07bbca96f6b675f 100644 (file)
@@ -336,18 +336,19 @@ public class CertificateRequest {
                     try {
                         DomainAssessment.checkCertifiableDomain(san.getName(), user.isInGroup(Group.CODESIGNING), false);
                         valid = true;
+                        if ( !valid || !CAA.verifyDomainAccess(owner, p, san.getName()) || (pDNS != null && !domainTemp.isMultiple())) {
+                            // remove
+                        } else {
+                            if (pDNS == null) {
+                                pDNS = san.getName();
+                            }
+                            filteredSANs.add(san);
+                            continue;
+                        }
                     } catch (GigiApiException e) {
+                        error.mergeInto(e);
                         valid = false;
                     }
-                    if ( !valid || !CAA.verifyDomainAccess(owner, p, san.getName()) || (pDNS != null && !domainTemp.isMultiple())) {
-                        // remove
-                    } else {
-                        if (pDNS == null) {
-                            pDNS = san.getName();
-                        }
-                        filteredSANs.add(san);
-                        continue;
-                    }
                 }
             } else if (san.getType() == SANType.EMAIL) {
                 if (emailTemp != null && owner.isValidEmail(san.getName())) {
index a95977e77c65b62a520b2617f75ac8732c08c595..33e78e89627f74df25da8b9ac0cb80a8c9d7900c 100644 (file)
@@ -2,8 +2,10 @@ package org.cacert.gigi.util;
 
 import javax.naming.NamingException;
 
+import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.CertificateOwner;
 import org.cacert.gigi.dbObjects.CertificateProfile;
+import org.cacert.gigi.output.template.SprintfCommand;
 
 public class CAA {
 
@@ -44,14 +46,14 @@ public class CAA {
         }
     }
 
-    public static boolean verifyDomainAccess(CertificateOwner owner, CertificateProfile p, String name) {
+    public static boolean verifyDomainAccess(CertificateOwner owner, CertificateProfile p, String name) throws GigiApiException {
         try {
             if (name.startsWith("*.")) {
                 return verifyDomainAccess(owner, p, name.substring(2), true);
             }
             return verifyDomainAccess(owner, p, name, false);
         } catch (NamingException e) {
-            return false;
+            throw new GigiApiException(SprintfCommand.createSimple("Internal Name Server/Resolution Error: {0}", e.getMessage()));
         }
     }
 
@@ -84,10 +86,14 @@ public class CAA {
 
     private static CAARecord[] getEffectiveCAARecords(String name) throws NamingException {
         CAARecord[] caa = DNSUtil.getCAAEntries(name);
+        String publicSuffix = PublicSuffixes.getInstance().getRegistrablePart(name);
         // TODO missing alias processing
         while (caa.length == 0 && name.contains(".")) {
             name = name.split("\\.", 2)[1];
             caa = DNSUtil.getCAAEntries(name);
+            if (name.equals(publicSuffix)) {
+                return caa;
+            }
         }
         return caa;
     }
index 09317c3ec643f8c53dfc16b3b27309b4b7ac2883..21bbce98f63e9f439f04e96d5415a79e04e874c9 100644 (file)
@@ -94,4 +94,8 @@ public class ServerConstants {
         return "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
     }
 
+    public static String getBoardMailAddress() {
+        return "board@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+    }
+
 }
index dac9053e0eb1dd01da52eb3cddd502c053e77924..e0ca82897d553271bc967d3fbfc8ea27e0b1163d 100644 (file)
@@ -64,11 +64,44 @@ public class TestSEAdminNotificationMail extends ClientTest {
 
     @Test
     public void testGrantUserGroup() throws MalformedURLException, IOException {
+        executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDatabaseName(), "UTF-8"), 0);
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+
+        // mail to support
+        String message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
+    }
+
+    @Test
+    public void testRemoveUserGroup() throws MalformedURLException, IOException {
+        executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDatabaseName(), "UTF-8"), 0);
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+
+        // mail to support
+        String message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
+    }
+
+    @Test
+    public void testGrantSupporterGroup() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDatabaseName(), "UTF-8"), 0);
 
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+        User target = User.getById(targetID);
 
         // mail to support
         String message = getMailReceiver().receive().getMessage();
@@ -76,15 +109,19 @@ public class TestSEAdminNotificationMail extends ClientTest {
         // mail to user
         message = getMailReceiver().receive().getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
+        // mail to board
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted for '" + target.getPreferredName().toString() + "'."));
     }
 
     @Test
-    public void testRemoveUserGroup() throws MalformedURLException, IOException {
+    public void testRemoveSupporterGroup() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDatabaseName(), "UTF-8"), 0);
 
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+        User target = User.getById(targetID);
 
         // mail to support
         String message = getMailReceiver().receive().getMessage();
@@ -92,6 +129,9 @@ public class TestSEAdminNotificationMail extends ClientTest {
         // mail to user
         message = getMailReceiver().receive().getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
+        // mail to board
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + target.getPreferredName().toString() + "'."));
     }
 
     @Test
index 1b4c3953dc46ea74f34ba71a517521bee7c9e2ed..b483a68f66ea4a583afd51ddf67777372bd7bfa2 100644 (file)
@@ -53,7 +53,7 @@ public class TestCAAValidation extends ClientTest {
     public Boolean success;
 
     @Test
-    public void testCAA() {
+    public void testCAA() throws GigiApiException {
         assertEquals(success, CAA.verifyDomainAccess(u, CertificateProfile.getByName("server"), domain));
     }