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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 26 17:16:14 CET 2008


Author: bh
Date: 2008-11-26 17:16:13 +0100 (Wed, 26 Nov 2008)
New Revision: 177

Modified:
   trunk/ChangeLog
   trunk/inteproxy/proxycore.py
   trunk/test/test_inteproxy.py
Log:
* inteproxy/proxycore.py
(InteProxyHTTPRequestHandler.open_http_connection): Handle case
where an upstream proxy returns a 407 response (Proxy
Authentication Required) by converting it to 502 (Bad Gateway).

* test/test_inteproxy.py
(TestInteProxyWithExtraProxyWithAuthentication.test): Test whether
InteProxy handles 407 responses from upstream proxies by returning
502 itself.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-11-26 15:59:07 UTC (rev 176)
+++ trunk/ChangeLog	2008-11-26 16:16:13 UTC (rev 177)
@@ -1,6 +1,18 @@
 2008-11-26  Bernhard Herzog  <bh at intevation.de>
 
 	* inteproxy/proxycore.py
+	(InteProxyHTTPRequestHandler.open_http_connection): Handle case
+	where an upstream proxy returns a 407 response (Proxy
+	Authentication Required) by converting it to 502 (Bad Gateway).
+
+	* test/test_inteproxy.py
+	(TestInteProxyWithExtraProxyWithAuthentication.test): Test whether
+	InteProxy handles 407 responses from upstream proxies by returning
+	502 itself.
+
+2008-11-26  Bernhard Herzog  <bh at intevation.de>
+
+	* inteproxy/proxycore.py
 	(InteProxyHTTPRequestHandler.handle_proxy_request)
 	(InteProxyHTTPRequestHandler.open_http_connection): Move debug
 	print of the response into open_http_connection.

Modified: trunk/inteproxy/proxycore.py
===================================================================
--- trunk/inteproxy/proxycore.py	2008-11-26 15:59:07 UTC (rev 176)
+++ trunk/inteproxy/proxycore.py	2008-11-26 16:16:13 UTC (rev 177)
@@ -184,6 +184,12 @@
                                                response.reason,
                                                response.msg, response)
         response_message.debug_log_message(self.log_debug)
+
+        if response_message.status == 407:
+            self.log_debug("upstream sent %d: %r; converting to 502",
+                           response_message.status, response_message.reason)
+            response_message.status = 502
+            response_message.reason = "Upstream proxy requires authentication"
         return response_message
 
 

Modified: trunk/test/test_inteproxy.py
===================================================================
--- trunk/test/test_inteproxy.py	2008-11-26 15:59:07 UTC (rev 176)
+++ trunk/test/test_inteproxy.py	2008-11-26 16:16:13 UTC (rev 177)
@@ -259,3 +259,29 @@
         self.assertEquals(response.status, 200)
         data = response.read()
         self.assertEquals(data, "wms data")
+
+
+class TestInteProxyWithExtraProxyWithIncorrectAuthentication(ServerTest):
+
+    remote_contents = [
+        ("/wms", [("Content-Type", "text/plain")], "wms data"),
+        ]
+
+    def create_http_proxy(self):
+        server = MasterWorkerServer(("127.0.0.1", 0),
+                                    AuthenticatingProxyRequestHandler, 5,
+                                    None, None,
+                                    transcoder_map=create_transcoder_map())
+        return server, "testuser", "wrong"
+
+    def test(self):
+        http = httplib.HTTPConnection("localhost", self.server.server_port)
+        http.request("GET", self.remote_server_base_url + "wms")
+        response = http.getresponse()
+        # the remote proxy returns a 407 (Proxy Authentication
+        # Required), but it must not be returned to the inteproxy client
+        # as such, otherwise inteproxy's client would believe that
+        # inteproxy itself required authentication.  Inteproxy should
+        # send a 502 (Bad Gateway) instead to indicate a server
+        # configuration problem
+        self.assertEquals(response.status, 502)



More information about the Inteproxy-commits mailing list