[tor-commits] [ooni-probe/master] Add some scaffolding for Squid Proxy detection test

art at torproject.org art at torproject.org
Tue Mar 13 20:48:58 UTC 2012


commit da50bb53f05e487a00b3db2feb97ce37cf449afd
Author: Arturo Filastò <hellais at gmail.com>
Date:   Tue Mar 13 13:49:30 2012 -0700

    Add some scaffolding for Squid Proxy detection test
---
 tests/squid.py |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/tests/squid.py b/tests/squid.py
new file mode 100644
index 0000000..847135e
--- /dev/null
+++ b/tests/squid.py
@@ -0,0 +1,113 @@
+"""
+    Squid Proxy Detector
+    ********************
+
+"""
+import os
+import httplib
+import urllib2
+from urlparse import urlparse
+
+from plugoo import gen_headers
+from plugoo.assets import Asset
+from plugoo.tests import Test
+
+__plugoo__ = "SquidProxy"
+__desc__ = "This Test aims at detecting the squid transparent proxy"
+
+class SquidAsset(Asset):
+    """
+    This is the asset that should be used by the Test. It will
+    contain all the code responsible for parsing the asset file
+    and should be passed on instantiation to the test.
+    """
+    def __init__(self, file=None):
+        self = Asset.__init__(self, file)
+
+
+class Squid(Test):
+    """
+    Squid Proxy testing class.
+    """
+    def _http_request(self, method, url,
+                      path=None, headers=None):
+        """
+        Perform an HTTP Request.
+        XXX move this function to the core OONI
+        code.
+        """
+        url = urlparse(url)
+        host = url.netloc
+
+        conn = httplib.HTTPConnection(host, 80)
+        conn.connect()
+
+        if path is None:
+            path = purl.path
+
+        conn.putrequest(method, path)
+
+        for h in gen_headers():
+            conn.putheaders(h[0], h[1])
+        conn.endheaders()
+
+        send_browser_headers(self, None, conn)
+
+        response = conn.getresponse()
+
+        headers = dict(response.getheaders())
+
+        self.headers = headers
+        self.data = response.read()
+        return True
+
+    def invalid_request(self):
+        """
+        This will trigger squids "Invalid Request" error.
+        """
+        pass
+
+    def cache_object(self):
+        """
+        This attempts to do a GET cache_object://localhost/info on
+        any destination and checks to see if the response contains
+        is that of Squid.
+        """
+
+        pass
+
+    def experiment(self, *a, **kw):
+        """
+        Fill this up with the tasks that should be performed
+        on the "dirty" network and should be compared with the
+        control.
+        """
+
+
+    def control(self):
+        """
+        Fill this up with the control related code.
+        """
+        return True
+
+def run(ooni):
+    """
+    This is the function that will be called by OONI
+    and it is responsible for instantiating and passing
+    the arguments to the Test class.
+    """
+    config = ooni.config
+
+    # This the assets array to be passed to the run function of
+    # the test
+    assets = [TestTemplateAsset(os.path.join(config.main.assetdir, \
+                                            "someasset.txt"))]
+
+    # Instantiate the Test
+    thetest = TestTemplate(ooni)
+    ooni.logger.info("starting SquidProxyTest...")
+    # Run the test with argument assets
+    thetest.run(assets)
+    ooni.logger.info("finished.")
+
+



More information about the tor-commits mailing list