[Inteproxy-commits] r173 - in trunk: . inteproxy test
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 25 21:42:14 CET 2008
Author: bh
Date: 2008-11-25 21:42:14 +0100 (Tue, 25 Nov 2008)
New Revision: 173
Modified:
trunk/ChangeLog
trunk/inteproxy/proxycore.py
trunk/test/test_inteproxy.py
Log:
* inteproxy/proxycore.py
(InteProxyHTTPRequestHandler.open_http_connection): Add a
Proxy-Authorization header if the proxy descripion has a username
and password.
* test/test_inteproxy.py
(TestInteProxyWithExtraProxyWithAuthentication.test): New. Test
authorizatin at a remote proxy
(AuthenticatingProxyRequestHandler): Helper class that implements
a proxy that requires authentication
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-11-25 20:37:23 UTC (rev 172)
+++ trunk/ChangeLog 2008-11-25 20:42:14 UTC (rev 173)
@@ -1,5 +1,18 @@
2008-11-25 Bernhard Herzog <bh at intevation.de>
+ * inteproxy/proxycore.py
+ (InteProxyHTTPRequestHandler.open_http_connection): Add a
+ Proxy-Authorization header if the proxy descripion has a username
+ and password.
+
+ * test/test_inteproxy.py
+ (TestInteProxyWithExtraProxyWithAuthentication.test): New. Test
+ authorizatin at a remote proxy
+ (AuthenticatingProxyRequestHandler): Helper class that implements
+ a proxy that requires authentication
+
+2008-11-25 Bernhard Herzog <bh at intevation.de>
+
* test/test_inteproxy.py (ServerTest.setUp)
(ServerTest.create_http_proxy)
(TestInteProxyWithExtraProxy.create_http_proxy): Prepare for tests
Modified: trunk/inteproxy/proxycore.py
===================================================================
--- trunk/inteproxy/proxycore.py 2008-11-25 20:37:23 UTC (rev 172)
+++ trunk/inteproxy/proxycore.py 2008-11-25 20:42:14 UTC (rev 173)
@@ -15,6 +15,7 @@
import urlparse
import BaseHTTPServer
import socket
+import base64
from inteproxy.threadpool import ThreadPool
from inteproxy.feesdialog import handle_fees_and_access_constraints
@@ -116,7 +117,10 @@
# the URI used in the request. Usually, it's like remote_url
# but with schem and netloc removed.
request_uri = urlparse.urlunsplit(("", "", path, query, fragment))
+
proxy = None
+ extra_headers = []
+
if scheme == "http":
connection_class = httplib.HTTPConnection
proxy = self.server.http_proxy
@@ -129,6 +133,11 @@
if proxy is not None:
netloc = "%s:%d" % (proxy.host, proxy.port)
request_uri = remote_url
+ if proxy.username and proxy.password:
+ userpass = base64.b64encode("%s:%s" % (proxy.username,
+ proxy.password))
+ extra_headers.append(("Proxy-Authorization",
+ "Basic %s" % userpass))
connection = connection_class(netloc)
if self.request_version == "HTTP/1.0":
@@ -147,6 +156,8 @@
continue
else:
connection.putheader(header, value)
+ for header, value in extra_headers:
+ connection.putheader(header, value)
connection.endheaders()
if client_request.body is not None:
Modified: trunk/test/test_inteproxy.py
===================================================================
--- trunk/test/test_inteproxy.py 2008-11-25 20:37:23 UTC (rev 172)
+++ trunk/test/test_inteproxy.py 2008-11-25 20:42:14 UTC (rev 173)
@@ -11,6 +11,7 @@
import os
import httplib
import unittest
+import base64
import serversupport
@@ -206,3 +207,55 @@
self.assertEquals(response.status, 200)
data = response.read()
self.assertEquals(data, "wms data")
+
+
+class AuthenticatingProxyRequestHandler(InteProxyHTTPRequestHandler):
+
+ """Special request handler for remote proxy authorization tests
+
+ This request handler only accepts requests that send a
+ Proxy-Authorization header with Basic authentication scheme,
+ username 'testuser' and password 'secret'
+ """
+
+ def handle_proxy_request(self):
+ authenticated = False
+ auth = self.headers.get("Proxy-Authorization")
+ if auth:
+ parts = auth.split()
+ if len(parts) == 2:
+ auth_scheme, encoded = parts
+ if auth_scheme.lower() == "basic":
+ decoded = base64.b64decode(encoded)
+ if decoded == "testuser:secret":
+ authenticated = True
+
+ if not authenticated:
+ # we should send a Proxy-Authenticate too, but it doesn't
+ # matter for this test because InteProxy doesn't look at the
+ # header yet.
+ self.send_error(407)
+ else:
+ InteProxyHTTPRequestHandler.handle_proxy_request(self)
+
+
+class TestInteProxyWithExtraProxyWithAuthentication(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", "secret"
+
+ def test(self):
+ http = httplib.HTTPConnection("localhost", self.server.server_port)
+ http.request("GET", self.remote_server_base_url + "wms")
+ response = http.getresponse()
+ self.assertEquals(response.status, 200)
+ data = response.read()
+ self.assertEquals(data, "wms data")
More information about the Inteproxy-commits
mailing list