[tor-commits] [ooni-probe/master] Add requiresRoot attribute to test API
art at torproject.org
art at torproject.org
Fri Oct 26 22:50:58 UTC 2012
commit 3612a17d27af6564be3bfc10cdbea7880723db3c
Author: Arturo Filastò <arturo at filasto.net>
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 | 3 +++
ooni/runner.py | 5 ++++-
4 files changed, 11 insertions(+), 5 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 5302d2f..b28ecf4 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -96,6 +96,8 @@ class TestCase(unittest.TestCase):
``The Name <email at example.com>``
* 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 at example.com>"
@@ -108,6 +110,7 @@ class TestCase(unittest.TestCase):
report['errors'] = []
optParameters = None
+ requiresRoot = False
def deferSetUp(self, ignored, result):
"""
diff --git a/ooni/runner.py b/ooni/runner.py
index 8068b5b..3e26d58 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:
More information about the tor-commits
mailing list