[apt-proxy-devel] r620 - trunk/apt_proxy/test
Chris Halls
halls at costa.debian.org
Mon Aug 14 12:44:24 UTC 2006
Author: halls
Date: Mon Aug 14 12:44:24 2006
New Revision: 620
Modified:
trunk/apt_proxy/test/test_config.py
trunk/apt_proxy/test/test_fetchers.py
Log:
Add tests for http proxy
Modified: trunk/apt_proxy/test/test_config.py
==============================================================================
--- trunk/apt_proxy/test/test_config.py (original)
+++ trunk/apt_proxy/test/test_config.py Mon Aug 14 12:44:24 2006
@@ -36,11 +36,13 @@
address=1.2.3.4 5.6.7.8
timeout = 888
bandwidth_limit = 2323
+http_proxy = somehost:9876
[backend1]
backends = ftp://a.b.c
timeout = 999
bandwidth_limit = 3434
+http_proxy = user:secret at otherhost:webcache
[backend2]
backends =
@@ -85,6 +87,16 @@
self.assertEquals(self.c.bandwidth_limit, 2323)
self.assertEquals(self.c.backends['backend1'].bandwidth_limit,3434)
self.assertEquals(self.c.backends['backend2'].bandwidth_limit,2323)
+ def testHttpProxy(self):
+ self.assertEquals(self.c.http_proxy.host, 'somehost')
+ self.assertEquals(self.c.http_proxy.port, 9876)
+ self.assertEquals(self.c.http_proxy.user, None)
+ self.assertEquals(self.c.http_proxy.password, None)
+ def testHttpProxyUserPass(self):
+ self.assertEquals(self.c.backends['backend1'].http_proxy.host, 'otherhost')
+ self.assertEquals(self.c.backends['backend1'].http_proxy.port, 'webcache')
+ self.assertEquals(self.c.backends['backend1'].http_proxy.user, 'user')
+ self.assertEquals(self.c.backends['backend1'].http_proxy.password, 'secret')
class BrokenTimeoutTest(unittest.TestCase):
def testBrokenTimeout(self):
@@ -95,3 +107,5 @@
self.c = apConfig(StringIO(""))
def testDefaultReadLimit(self):
self.assertEquals(self.c.bandwidth_limit, None)
+ def testDefaultHttpProxy(self):
+ self.assertEquals(self.c.http_proxy, None)
Modified: trunk/apt_proxy/test/test_fetchers.py
==============================================================================
--- trunk/apt_proxy/test/test_fetchers.py (original)
+++ trunk/apt_proxy/test/test_fetchers.py Mon Aug 14 12:44:24 2006
@@ -16,7 +16,8 @@
"""This module tests the Fetcher classes"""
-import time, os, socket, signal, string
+import time, os, socket, signal, string, re, base64
+from StringIO import StringIO
from twisted.internet import reactor, protocol, defer, error
from twisted.protocols import ftp
@@ -43,6 +44,10 @@
[backend1]
backends = http://localhost/nothing-really
+[backend2]
+backends = http://localhost/nothing-really
+http_proxy = user1:password at test:1234
+
[ftp]
backends = ftp://localhost/nothing-really
"""
@@ -53,15 +58,22 @@
Set up a factory using the additional config given
"""
FactoryTestHelper.setUp(self, config1)
-
- def testInit(self):
- "Brief init test"
backend = self.factory.getBackend('backend1')
backendServer = backend.uris[0]
httpFetcher = HttpFetcher(backendServer)
httpFetcher.proxy = None # Would otherwise have been set by httpFetcher.connect
- connection = FetcherHttpClient(httpFetcher)
+ self.connection = FetcherHttpClient(httpFetcher)
+ self.connection.transport = StringIO()
+ def endHeaders():
+ pass
+ self.connection.endHeaders = endHeaders
+ def testProxyHeader(self):
+ self.connection.proxy = self.factory.getBackend('backend2').config.http_proxy
+ self.connection.download(None, '/a/b/c', None)
+ fetcherHeaders = self.connection.transport.getvalue()
+ authheader = "Proxy-Authorization: Basic " + base64.encodestring('user1:password')[:-1]
+ self.assertNotEquals(re.search(r'(?:\n|^)'+authheader+r'\r\n', fetcherHeaders), None)
class FetcherFtpInitTest(FactoryTestHelper):
def setUp(self):
More information about the apt-proxy-devel
mailing list