[Inteproxy-commits] r210 - in trunk: . inteproxy test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 11 22:13:55 CEST 2009


Author: bh
Date: 2009-09-11 22:13:54 +0200 (Fri, 11 Sep 2009)
New Revision: 210

Modified:
   trunk/ChangeLog
   trunk/inteproxy/transcoder.py
   trunk/test/test_transcoder_map.py
Log:
* inteproxy/transcoder.py (TranscoderMap.add_rule): Add the port
number to the hostname pattern if the rule has a port number.
(TranscoderMap.lookup): Rename host->netloc because it also may
contain the port number

* test/test_transcoder_map.py (TestTranscoderMapWithPorts): New.
Class for rules with port numbers


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-09-11 20:06:53 UTC (rev 209)
+++ trunk/ChangeLog	2009-09-11 20:13:54 UTC (rev 210)
@@ -1,5 +1,15 @@
 2009-09-11  Bernhard Herzog  <bh at intevation.de>
 
+	* inteproxy/transcoder.py (TranscoderMap.add_rule): Add the port
+	number to the hostname pattern if the rule has a port number.
+	(TranscoderMap.lookup): Rename host->netloc because it also may
+	contain the port number
+
+	* test/test_transcoder_map.py (TestTranscoderMapWithPorts): New.
+	Class for rules with port numbers
+
+2009-09-11  Bernhard Herzog  <bh at intevation.de>
+
 	* test/test_transcoder_map.py
 	(TestTranscoderMapNoWildcards.config_contents)
 	(TestTranscoderMapWithPathWildcards.config_contents)

Modified: trunk/inteproxy/transcoder.py
===================================================================
--- trunk/inteproxy/transcoder.py	2009-09-11 20:06:53 UTC (rev 209)
+++ trunk/inteproxy/transcoder.py	2009-09-11 20:13:54 UTC (rev 210)
@@ -10,7 +10,7 @@
 import re
 import base64
 import urlparse
-from urllib import quote_plus
+from urllib import quote_plus, splitport
 from StringIO import StringIO
 
 from lxml import etree
@@ -200,7 +200,10 @@
     def add_rule(self, rule):
         """Adds a transcoder rule (typically an instance of InteProxyRule)
         """
-        self.rules.append((re.compile(pattern_to_regex(rule.host,
+        netloc = rule.host
+        if rule.port is not None:
+            netloc += ":%d" % rule.port
+        self.rules.append((re.compile(pattern_to_regex(netloc,
                                                        character_set="[^/]")),
                            re.compile(pattern_to_regex(rule.path)),
                            rule))
@@ -210,13 +213,13 @@
         for rule in rules:
             self.add_rule(rule)
 
-    def lookup(self, host, path):
+    def lookup(self, netloc, path):
         """Returns the rule matching host and path.
         If no rule matches, the method returns None
         """
-        for host_regex, path_regex, rule in self.rules:
-            host_match = host_regex.match(host)
-            if host_match and host_match.group(0) == host:
+        for netloc_regex, path_regex, rule in self.rules:
+            netloc_match = netloc_regex.match(netloc)
+            if netloc_match and netloc_match.group(0) == netloc:
                 path_match = path_regex.match(path)
                 if path_match and path_match.group(0) == path:
                     return rule

Modified: trunk/test/test_transcoder_map.py
===================================================================
--- trunk/test/test_transcoder_map.py	2009-09-11 20:06:53 UTC (rev 209)
+++ trunk/test/test_transcoder_map.py	2009-09-11 20:13:54 UTC (rev 210)
@@ -184,3 +184,57 @@
             msg=("Wrong class for %(method)s %(url)s:"
                  " got %(cls)s expected %(expectedcls)s" % locals())
             self.assertEquals(cls, expectedcls, msg)
+
+
+class TestTranscoderMapWithPorts(TranscoderMapTest):
+
+    config_contents = """\
+[inteproxy-rules]
+urls=owsproxy://*intevation.*:8080/wms/
+     basicauth://*.example.com:9000/*
+     owsproxy://*.example.com/*
+"""
+    #
+
+    def test_get_transcoder_http_proxy(self):
+        """Test the get_transcoder method in http-proxy mode with wildcards"""
+        test_cases = [
+            # matched by the first rule
+            ("GET", "http://intevation.de:8080/wms/", OWSProxyGETTranscoder),
+            ("POST", "http://intevation.org:8080/wms/", OWSProxyPOSTTranscoder),
+            ("GET", "http://gis.intevation.org:8080/wms/",
+             OWSProxyGETTranscoder),
+            ("POST", "http://data.intevation.de:8080/wms/",
+             OWSProxyPOSTTranscoder),
+
+            # not matched by the first rule
+            ("GET", "http://intevation.de:9000/wms/", IdentityTranscoder),
+            ("POST", "http://intevation.de//wms/", IdentityTranscoder),
+
+            # matched by the second rule
+            ("GET", "http://geodata.example.com:9000/prefix/frida/wms",
+             BasicAuthTranscoder),
+            ("POST", "http://geodata.example.com:9000/prefix/wms",
+             BasicAuthTranscoder),
+            ("GET", "http://frida.example.com:9000/", BasicAuthTranscoder),
+            ("POST", "http://gis.data.example.com:9000/", BasicAuthTranscoder),
+
+            # not matched by the second rule
+            ("GET", "http://geodata.example.org:9001/frida/wms",
+             IdentityTranscoder),
+            ("POST", "http://geodata.example.net:8080/prefix/wms",
+             IdentityTranscoder),
+
+            # matched by the third rule
+            ("GET", "http://geodata.example.com/prefix/frida/wms",
+             OWSProxyGETTranscoder),
+            ("POST", "http://geodata.example.com/prefix/wms",
+             OWSProxyPOSTTranscoder),
+            ]
+
+        for method, url, expectedcls in test_cases:
+            transcoder = self.transcoder_map.get_transcoder(method, url)
+            cls = transcoder.__class__
+            msg=("Wrong class for %(method)s %(url)s:"
+                 " got %(cls)s expected %(expectedcls)s" % locals())
+            self.assertEquals(cls, expectedcls, msg)



More information about the Inteproxy-commits mailing list