]> WPIA git - gigi.git/commitdiff
Test more error cases for DNS ping.
authorFelix Dörre <felix@dogcraft.de>
Wed, 27 Aug 2014 17:26:25 +0000 (19:26 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 28 Aug 2014 11:36:28 +0000 (13:36 +0200)
tests/org/cacert/gigi/ping/TestDNS.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index e6c53f161ef4af5dddaad95fa1c17b6c8c81bd6e..4ee94743c8a48f66e969f373dcfa26f64b3e2863 100644 (file)
@@ -23,6 +23,7 @@ import org.cacert.gigi.testUtils.ManagedTest;
 import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
 import org.cacert.gigi.util.DNSUtil;
 import org.cacert.gigi.util.RandomToken;
 import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
 import org.cacert.gigi.util.DNSUtil;
 import org.cacert.gigi.util.RandomToken;
+import org.junit.After;
 import org.junit.Test;
 
 public class TestDNS extends ManagedTest {
 import org.junit.Test;
 
 public class TestDNS extends ManagedTest {
@@ -39,9 +40,25 @@ public class TestDNS extends ManagedTest {
     }
 
     @Test
     }
 
     @Test
-    public void testEmailAndDNS() throws IOException, InterruptedException, SQLException, NamingException {
+    public void testEmailAndDNSSuccess() throws IOException, InterruptedException, SQLException, NamingException {
+        testEmailAndDNS(0, 0, true, true);
+    }
+
+    @After
+    public void test() throws SQLException, IOException {
+        purgeDatabase();
+    }
+
+    @Test
+    public void testEmailAndDNSFail() throws IOException, InterruptedException, SQLException, NamingException {
+        testEmailAndDNS(1, 0, false, true);
+        purgeDatabase();
+        testEmailAndDNS(2, 0, false, true);
+    }
+
+    public void testEmailAndDNS(int dnsVariant, int emailVariant, boolean successDNS, boolean successMail) throws IOException, InterruptedException, SQLException, NamingException {
         String email = createUniqueName() + "@example.org";
         String email = createUniqueName() + "@example.org";
-        int uid = createVerifiedUser("a", "b", email, TEST_PASSWORD);
+        createVerifiedUser("a", "b", email, TEST_PASSWORD);
         String cookie = login(email, TEST_PASSWORD);
 
         String test = getTestProps().getProperty("domain.dnstest");
         String cookie = login(email, TEST_PASSWORD);
 
         String test = getTestProps().getProperty("domain.dnstest");
@@ -54,7 +71,7 @@ public class TestDNS extends ManagedTest {
         Pattern p = Pattern.compile("cacert-([A-Za-z0-9]+) IN TXT ([A-Za-z0-9]+)");
         Matcher m = p.matcher(content1);
         m.find();
         Pattern p = Pattern.compile("cacert-([A-Za-z0-9]+) IN TXT ([A-Za-z0-9]+)");
         Matcher m = p.matcher(content1);
         m.find();
-        updateDNS(m.group(1), m.group(2));
+        updateDNS(m.group(1) + (dnsVariant == 1 ? "a" : ""), m.group(2) + (dnsVariant == 2 ? "a" : ""));
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
                 "&emailType=y&email=2&DNSType=y" + //
 
         String content = "newdomain=" + URLEncoder.encode(test, "UTF-8") + //
                 "&emailType=y&email=2&DNSType=y" + //
@@ -91,9 +108,9 @@ public class TestDNS extends ManagedTest {
 
         newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
         Pattern pat = Pattern.compile("<td>dns</td>\\s*<td>success</td>");
 
         newcontent = IOUtils.readURL(cookie(u2.openConnection(), cookie));
         Pattern pat = Pattern.compile("<td>dns</td>\\s*<td>success</td>");
-        assertTrue(newcontent, pat.matcher(newcontent).find());
+        assertTrue(newcontent, !successDNS ^ pat.matcher(newcontent).find());
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
         pat = Pattern.compile("<td>email</td>\\s*<td>success</td>");
-        assertTrue(newcontent, pat.matcher(newcontent).find());
+        assertTrue(newcontent, !successMail ^ pat.matcher(newcontent).find());
     }
 
     private String updateDNS(String token, String value) throws IOException, MalformedURLException, NamingException {
     }
 
     private String updateDNS(String token, String value) throws IOException, MalformedURLException, NamingException {
index f20ed763f7d4cca84b65296e129ff70147e2bc1b..77822f52380101b47ff7d7c4ca17db1687255d6e 100644 (file)
@@ -95,10 +95,7 @@ public class ManagedTest {
             if ( !DatabaseConnection.isInited()) {
                 DatabaseConnection.init(testProps);
             }
             if ( !DatabaseConnection.isInited()) {
                 DatabaseConnection.init(testProps);
             }
-            System.out.println("... purging Database");
-            DatabaseManager.run(new String[] {
-                    testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
-            });
+            purgeDatabase();
             String type = testProps.getProperty("type");
             Properties mainProps = generateMainProps();
             ServerConstants.init(mainProps);
             String type = testProps.getProperty("type");
             Properties mainProps = generateMainProps();
             ServerConstants.init(mainProps);
@@ -144,8 +141,6 @@ public class ManagedTest {
             SimpleSigner.runSigner();
         } catch (IOException e) {
             throw new Error(e);
             SimpleSigner.runSigner();
         } catch (IOException e) {
             throw new Error(e);
-        } catch (ClassNotFoundException e1) {
-            e1.printStackTrace();
         } catch (SQLException e1) {
             e1.printStackTrace();
         } catch (InterruptedException e) {
         } catch (SQLException e1) {
             e1.printStackTrace();
         } catch (InterruptedException e) {
@@ -154,6 +149,17 @@ public class ManagedTest {
 
     }
 
 
     }
 
+    public static void purgeDatabase() throws SQLException, IOException {
+        System.out.println("... purging Database");
+        try {
+            DatabaseManager.run(new String[] {
+                    testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
+            });
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+        }
+    }
+
     private static Properties generateMainProps() {
         Properties mainProps = new Properties();
         mainProps.setProperty("host", "127.0.0.1");
     private static Properties generateMainProps() {
         Properties mainProps = new Properties();
         mainProps.setProperty("host", "127.0.0.1");