Rev 5958: Tweak the http Authorization tests to make some parts easier to reuse (parametrization mostly). in file:///home/vila/src/bzr/bugs/723074-http-debug-mask-credentials/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jun 7 08:12:32 UTC 2011
At file:///home/vila/src/bzr/bugs/723074-http-debug-mask-credentials/
------------------------------------------------------------
revno: 5958
revision-id: v.ladeuil+lp at free.fr-20110607081232-yvtbewkbc6no8wsq
parent: pqm at pqm.ubuntu.com-20110606125209-j8r8jiltfjypii3i
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 723074-http-debug-mask-credentials
timestamp: Tue 2011-06-07 10:12:32 +0200
message:
Tweak the http Authorization tests to make some parts easier to reuse (parametrization mostly).
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2011-05-26 08:05:45 +0000
+++ b/bzrlib/tests/test_http.py 2011-06-07 08:12:32 +0000
@@ -91,22 +91,32 @@
]
+def vary_by_http_auth_scheme():
+ scenarios = [
+ ('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
+ ('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
+ ('basicdigest',
+ dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
+ ]
+ # Add some attributes common to all scenarios
+ for scenario_id, scenario_dict in scenarios:
+ scenario_dict.update(_username_prompt_prefix='',
+ _password_prompt_prefix='')
+ return scenarios
+
+
def vary_by_http_proxy_auth_scheme():
- return [
+ scenarios = [
('basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
('digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
('basicdigest',
dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
]
-
-
-def vary_by_http_auth_scheme():
- return [
- ('basic', dict(_auth_server=http_utils.HTTPBasicAuthServer)),
- ('digest', dict(_auth_server=http_utils.HTTPDigestAuthServer)),
- ('basicdigest',
- dict(_auth_server=http_utils.HTTPBasicAndDigestAuthServer)),
- ]
+ # Add some attributes common to all scenarios
+ for scenario_id, scenario_dict in scenarios:
+ scenario_dict.update(_username_prompt_prefix='Proxy ',
+ _password_prompt_prefix='Proxy ')
+ return scenarios
def vary_by_http_activity():
@@ -1489,6 +1499,35 @@
self.get_a, self.old_transport, redirected)
+def _setup_authentication_config(**kwargs):
+ conf = config.AuthenticationConfig()
+ conf._get_config().update({'httptest': kwargs})
+ conf._save()
+
+
+class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
+ """Unit tests for glue by which urllib2 asks us for authentication"""
+
+ def test_get_user_password_without_port(self):
+ """We cope if urllib2 doesn't tell us the port.
+
+ See https://bugs.launchpad.net/bzr/+bug/654684
+ """
+ user = 'joe'
+ password = 'foo'
+ _setup_authentication_config(scheme='http', host='localhost',
+ user=user, password=password)
+ handler = _urllib2_wrappers.HTTPAuthHandler()
+ got_pass = handler.get_user_password(dict(
+ user='joe',
+ protocol='http',
+ host='localhost',
+ path='/',
+ realm='Realm',
+ ))
+ self.assertEquals((user, password), got_pass)
+
+
class TestAuth(http_utils.TestCaseWithWebserver):
"""Test authentication scheme"""
@@ -1498,12 +1537,6 @@
vary_by_http_auth_scheme(),
)
- _auth_header = 'Authorization'
- _password_prompt_prefix = ''
- _username_prompt_prefix = ''
- # Set by load_tests
- _auth_server = None
-
def setUp(self):
super(TestAuth, self).setUp()
self.server = self.get_readonly_server()
@@ -1650,11 +1683,8 @@
ui.ui_factory = tests.TestUIFactory(stdin=stdin_content,
stderr=tests.StringIOWrapper())
# Create a minimal config file with the right password
- _setup_authentication_config(
- scheme='http',
- port=self.server.port,
- user=user,
- password=password)
+ _setup_authentication_config(scheme='http', port=self.server.port,
+ user=user, password=password)
# Issue a request to the server to connect
self.assertEqual('contents of a\n',t.get('a').read())
# stdin should have been left untouched
@@ -1690,11 +1720,8 @@
user = 'joe'
password = 'foo'
self.server.add_user(user, password)
- _setup_authentication_config(
- scheme='http',
- port=self.server.port,
- user=user,
- password=password)
+ _setup_authentication_config(scheme='http', port=self.server.port,
+ user=user, password=password)
t = self.get_user_transport(None, None)
# Issue a request to the server to connect
self.assertEqual('contents of a\n', t.get('a').read())
@@ -1702,41 +1729,12 @@
self.assertEqual(1, self.server.auth_required_errors)
-def _setup_authentication_config(**kwargs):
- conf = config.AuthenticationConfig()
- conf._get_config().update({'httptest': kwargs})
- conf._save()
-
-
-
-class TestUrllib2AuthHandler(tests.TestCaseWithTransport):
- """Unit tests for glue by which urllib2 asks us for authentication"""
-
- def test_get_user_password_without_port(self):
- """We cope if urllib2 doesn't tell us the port.
-
- See https://bugs.launchpad.net/bzr/+bug/654684
- """
- user = 'joe'
- password = 'foo'
- _setup_authentication_config(
- scheme='http',
- host='localhost',
- user=user,
- password=password)
- handler = _urllib2_wrappers.HTTPAuthHandler()
- got_pass = handler.get_user_password(dict(
- user='joe',
- protocol='http',
- host='localhost',
- path='/',
- realm='Realm',
- ))
- self.assertEquals((user, password), got_pass)
-
-
class TestProxyAuth(TestAuth):
- """Test proxy authentication schemes."""
+ """Test proxy authentication schemes.
+
+ This inherits from TestAuth to tweak the setUp and filter some failing
+ tests.
+ """
scenarios = multiply_scenarios(
vary_by_http_client_implementation(),
@@ -1744,10 +1742,6 @@
vary_by_http_proxy_auth_scheme(),
)
- _auth_header = 'Proxy-authorization'
- _password_prompt_prefix = 'Proxy '
- _username_prompt_prefix = 'Proxy '
-
def setUp(self):
super(TestProxyAuth, self).setUp()
# Override the contents to avoid false positives
More information about the bazaar-commits
mailing list