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

[tor-commits] [ooni-probe/master] Add requiresRoot attribute to test API



commit 435b3e3f4376fe661a32c836717d5a3f8e53125e
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Fri Oct 26 22:51:03 2012 +0000

    Add requiresRoot attribute to test API
    * Will trigger error if trying to run a test that requires root
---
 nettests/examples/example_scapyt.py |    2 ++
 ooni/__init__.py                    |    6 ++----
 ooni/nettest.py                     |    5 +++--
 ooni/runner.py                      |    5 ++++-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/nettests/examples/example_scapyt.py b/nettests/examples/example_scapyt.py
index 403ddc5..cda3a10 100644
--- a/nettests/examples/example_scapyt.py
+++ b/nettests/examples/example_scapyt.py
@@ -5,6 +5,7 @@
 
 from ooni.templates import scapyt
 from scapy.all import *
+
 class ExampleScapy(scapyt.ScapyTest):
     name = "Example Scapy Test"
     author = "Arturo Filastò"
@@ -13,6 +14,7 @@ class ExampleScapy(scapyt.ScapyTest):
     inputs = [IP(dst="8.8.8.8")/TCP(dport=31337),
               IP(dst="ooni.nu")/TCP(dport=31337)]
 
+    requiresRoot = True
 
     def test_sendReceive(self):
         log.msg("Running send receive")
diff --git a/ooni/__init__.py b/ooni/__init__.py
index 9a4e60f..1533244 100644
--- a/ooni/__init__.py
+++ b/ooni/__init__.py
@@ -1,5 +1,4 @@
 from . import config
-from . import input
 from . import inputunit
 from . import kit
 from . import lib
@@ -14,10 +13,9 @@ from . import utils
 from . import ooniprobe
 from . import plugoo
 from . import plugins
-from . import oonitests
 
-__all__ = ['config', 'input', 'inputunit', 'kit',
+__all__ = ['config', 'inputunit', 'kit',
            'lib', 'nettest', 'oonicli', 'reporter',
            'runner', 'templates', 'utils',
            # XXX below are legacy related modules
-           'ooniprobe', 'plugoo', 'plugins', 'oonitests']
+           'ooniprobe', 'plugoo', 'plugins']
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 1d46218..bb9a404 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -96,6 +96,8 @@ class TestCase(unittest.TestCase):
           ``The Name <email@xxxxxxxxxxx>``
 
     * version: is the version string of the test.
+
+    * requiresRoot: set to True if the test must be run as root.
     """
     name = "I Did Not Change The Name"
     author = "Jane Doe <foo@xxxxxxxxxxx>"
@@ -108,8 +110,7 @@ class TestCase(unittest.TestCase):
     report['errors'] = []
 
     optParameters = None
-    optFlags      = None
-    subCommands   = None
+    requiresRoot = False
 
     def deferSetUp(self, ignored, result):
         """
diff --git a/ooni/runner.py b/ooni/runner.py
index ff5dd33..371f310 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -9,7 +9,7 @@
 # :copyright: (c) 2012 Isis Lovecruft, Arturo Filasto, The Tor Project, Inc.
 # :version: 0.1.0-pre-alpha
 #
-
+import os
 import inspect
 
 from twisted.python import reflect, usage
@@ -50,6 +50,9 @@ def processTest(obj, config):
     """
 
     input_file = obj.inputFile
+    if obj.requiresRoot:
+        if os.getuid() != 0:
+            raise Exception("This test requires root to run")
 
     if obj.optParameters or input_file:
         if not obj.optParameters:



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