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

[tor-commits] [ooni-probe/master] Port UK Mobile Network test to new API



commit e115d4d0e6c063422fc35cbe1a63dcf0f5917a77
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Mon Nov 12 23:05:21 2012 +0100

    Port UK Mobile Network test to new API
---
 nettests/core/http_uk_mobile_networks.py |   85 +++++++++++++++++++++++++++
 to-be-ported/old-api/httpt.py            |   94 ------------------------------
 2 files changed, 85 insertions(+), 94 deletions(-)

diff --git a/nettests/core/http_uk_mobile_networks.py b/nettests/core/http_uk_mobile_networks.py
new file mode 100644
index 0000000..784a9e9
--- /dev/null
+++ b/nettests/core/http_uk_mobile_networks.py
@@ -0,0 +1,85 @@
+# -*- encoding: utf-8 -*-
+import yaml
+
+from twisted.python import usage
+from twisted.plugin import IPlugin
+
+from ooni.templates import httpt
+from ooni.utils import log
+
+class UsageOptions(usage.Options):
+    """
+    See https://github.com/hellais/ooni-inputs/processed/uk_mobile_networks_redirects.yaml 
+    to see how the rules file should look like.
+    """
+    optParameters = [
+                     ['rules', 'y', None, 
+                    'Specify the redirect rules file ']
+                    ]
+
+class HTTPUKMobileNetworksTest(httpt.HTTPTest):
+    """
+    This test was thought of by Open Rights Group and implemented with the
+    purpose of detecting censorship in the UK.
+    For more details on this test see:
+    https://trac.torproject.org/projects/tor/ticket/6437
+    XXX port the knowledge from the trac ticket into this test docstring
+    """
+    name = "HTTP UK mobile network redirect test"
+
+    usageOptions = UsageOptions
+
+    followRedirects = True
+
+    inputFile = ['urls', 'f', None, 'List of urls one per line to test for censorship']
+    requiredOptions = ['urls']
+
+    def testPattern(self, value, pattern, type):
+        if type == 'eq':
+            return value == pattern
+        elif type == 're':
+            import re
+            if re.match(pattern, value):
+                return True
+            else:
+                return False
+        else:
+            return None
+
+    def testPatterns(self, patterns, location):
+        test_result = False
+
+        if type(patterns) == list:
+            for pattern in patterns:
+                test_result |= self.testPattern(location, pattern['value'], pattern['type'])
+        rules_file = self.localOptions['rules']
+
+        return test_result
+
+    def testRules(self, rules, location):
+        result = {}
+        blocked = False
+        for rule, value in rules.items():
+            current_rule = {}
+            current_rule['name'] = value['name']
+            current_rule['patterns'] = value['patterns']
+            current_rule['test'] = self.testPatterns(value['patterns'], location)
+            blocked |= current_rule['test']
+            result[rule] = current_rule
+        result['blocked'] = blocked
+        return result
+
+    def processRedirect(self, location):
+        self.report['redirect'] = None
+        rules_file = self.localOptions['rules']
+
+        fp = open(rules_file)
+        rules = yaml.safe_load(fp)
+        fp.close()
+
+        log.msg("Testing rules %s" % rules)
+        redirect = self.testRules(rules, location)
+        self.report['redirect'] = redirect
+
+
+
diff --git a/to-be-ported/old-api/httpt.py b/to-be-ported/old-api/httpt.py
deleted file mode 100644
index 358f1ea..0000000
--- a/to-be-ported/old-api/httpt.py
+++ /dev/null
@@ -1,94 +0,0 @@
-"""
-This is a self genrated test created by scaffolding.py.
-you will need to fill it up with all your necessities.
-Safe hacking :).
-"""
-from zope.interface import implements
-from twisted.python import usage
-from twisted.plugin import IPlugin
-from ooni.plugoo.tests import ITest, OONITest
-from ooni.plugoo.assets import Asset
-from ooni.protocols import http
-from ooni.utils import log
-
-class httptArgs(usage.Options):
-    optParameters = [['urls', 'f', None, 'Urls file'],
-                     ['url', 'u', 'http://torproject.org/', 'Test single site'],
-                     ['resume', 'r', 0, 'Resume at this index'],
-                     ['rules', 'y', None, 'Specify the redirect rules file']]
-
-class httptTest(http.HTTPTest):
-    implements(IPlugin, ITest)
-
-    shortName = "httpt"
-    description = "httpt"
-    requirements = None
-    options = httptArgs
-    blocking = False
-
-
-    def testPattern(self, value, pattern, type):
-        if type == 'eq':
-            return value == pattern
-        elif type == 're':
-            import re
-            if re.match(pattern, value):
-                return True
-            else:
-                return False
-        else:
-            return None
-
-    def testPatterns(self, patterns, location):
-        test_result = False
-
-        if type(patterns) == list:
-            for pattern in patterns:
-                test_result |= self.testPattern(location, pattern['value'], pattern['type'])
-        else:
-            test_result |= self.testPattern(location, patterns['value'], patterns['type'])
-
-        return test_result
-
-    def testRules(self, rules, location):
-        result = {}
-        blocked = False
-        for rule, value in rules.items():
-            current_rule = {}
-            current_rule['name'] = value['name']
-            current_rule['patterns'] = value['patterns']
-            current_rule['test'] = self.testPatterns(value['patterns'], location)
-            blocked |= current_rule['test']
-            result[rule] = current_rule
-        result['blocked'] = blocked
-        return result
-
-    def processRedirect(self, location):
-        self.result['redirect'] = None
-        try:
-            rules_file = self.local_options['rules']
-            import yaml
-            rules = yaml.load(open(rules_file))
-            log.msg("Testing rules %s" % rules)
-            redirect = self.testRules(rules, location)
-            self.result['redirect'] = redirect
-        except TypeError:
-            log.msg("No rules file. Got a redirect, but nothing to do.")
-
-
-    def control(self, experiment_result, args):
-        print self.response
-        print self.request
-        # What you return here ends up inside of the report.
-        log.msg("Running control")
-        return {}
-
-    def load_assets(self):
-        if self.local_options and self.local_options['urls']:
-            return {'url': Asset(self.local_options['urls'])}
-        else:
-            return {}
-
-# We need to instantiate it otherwise getPlugins does not detect it
-# XXX Find a way to load plugins without instantiating them.
-#httpt = httptTest(None, None, None)



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