[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [collector/master] Implements task-19894.



commit f514a1380db2962fcfbc3444b7643f93159ba3e5
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Sat Aug 13 15:16:07 2016 +0200

    Implements task-19894.
    
    Throws a RuntimeException and informs the user that nothing was activated;
    and then exits.
    
    Added a new test and made necessary adaptions to affected tests.
---
 .../java/org/torproject/collector/conf/Configuration.java   | 12 ++++++++++++
 src/test/java/org/torproject/collector/MainTest.java        | 13 +++++++++++++
 .../org/torproject/collector/conf/ConfigurationTest.java    |  6 +++++-
 src/test/resources/junittest.policy                         |  1 +
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/torproject/collector/conf/Configuration.java b/src/main/java/org/torproject/collector/conf/Configuration.java
index ee6552c..e55393c 100644
--- a/src/main/java/org/torproject/collector/conf/Configuration.java
+++ b/src/main/java/org/torproject/collector/conf/Configuration.java
@@ -50,6 +50,7 @@ public class Configuration extends Observable implements Cloneable {
     try {
       ft = Files.getLastModifiedTime(confPath);
       reload();
+      anythingActivated();
     } catch (IOException e) {
       throw new ConfigurationException("Cannot watch configuration file. "
           + "Reason: " + e.getMessage(), e);
@@ -81,6 +82,17 @@ public class Configuration extends Observable implements Cloneable {
     }
   }
 
+  private void anythingActivated() throws ConfigurationException {
+    if (!(this.getBool(Key.RelaydescsActivated)
+        || this.getBool(Key.BridgedescsActivated)
+        || this.getBool(Key.ExitlistsActivated)
+        || this.getBool(Key.UpdateindexActivated)
+        || this.getBool(Key.TorperfActivated))) {
+      throw new ConfigurationException("Nothing is activated!\n"
+          + "Please edit collector.properties. Exiting.");
+    }
+  }
+
   /** Return a copy of all properties. */
   public Properties getPropertiesCopy() {
     return (Properties) props.clone();
diff --git a/src/test/java/org/torproject/collector/MainTest.java b/src/test/java/org/torproject/collector/MainTest.java
index 05c16c5..5453dd4 100644
--- a/src/test/java/org/torproject/collector/MainTest.java
+++ b/src/test/java/org/torproject/collector/MainTest.java
@@ -171,5 +171,18 @@ public class MainTest {
     }
   }
 
+  @Test(expected = ConfigurationException.class)
+  public void testNoModuleActivated() throws Exception {
+    File conf = tmpf.newFile("test.conf");
+    try {
+      assertEquals(0L, conf.length());
+      // create default configuration
+      Main.main(new String[]{conf.toString()});
+    } catch (ConfigurationException ce) {
+      fail("This should not cause a ConfigurationException: " + ce);
+    }
+    // no module activated; the following should throw a ConfigurationException
+    Main.main(new String[]{conf.toString()});
+  }
 }
 
diff --git a/src/test/java/org/torproject/collector/conf/ConfigurationTest.java b/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
index 45ab5ed..89a7750 100644
--- a/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
+++ b/src/test/java/org/torproject/collector/conf/ConfigurationTest.java
@@ -18,6 +18,7 @@ import org.junit.rules.TemporaryFolder;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.lang.reflect.Field;
+import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Observable;
@@ -182,6 +183,8 @@ public class ConfigurationTest {
         }
       });
     File confFile = tmpf.newFile("empty");
+    Files.write(confFile.toPath(), (Key.RelaydescsActivated.name() + "=true")
+        .getBytes());
     conf.setWatchableSourceAndLoad(confFile.toPath());
     MainTest.waitSec(1);
     confFile.setLastModified(System.currentTimeMillis());
@@ -202,10 +205,11 @@ public class ConfigurationTest {
         }
       });
     File confFile = tmpf.newFile("empty");
+    Files.write(confFile.toPath(), (Key.RelaydescsActivated.name() + "=true")
+        .getBytes());
     conf.setWatchableSourceAndLoad(confFile.toPath());
     MainTest.waitSec(1);
     confFile.delete();
-    conf.setProperty(Key.CompressRelayDescriptorDownloads.name(), "false");
     conf.setProperty(Key.ImportDirectoryArchives.name(), "false");
     Dummy dummy = new Dummy(conf);
     tmpf.newFolder("empty");
diff --git a/src/test/resources/junittest.policy b/src/test/resources/junittest.policy
index 0c7ccac..e2f4a26 100644
--- a/src/test/resources/junittest.policy
+++ b/src/test/resources/junittest.policy
@@ -7,6 +7,7 @@ grant {
   permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.fs";
   permission java.lang.RuntimePermission "accessDeclaredMembers";
   permission java.lang.RuntimePermission "getFileStoreAttributes";
+  permission java.lang.RuntimePermission "getStackTrace";
   permission java.lang.RuntimePermission "modifyThread";
   permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
   permission java.lang.RuntimePermission "shutdownHooks";



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits