204
204
def test_invalid_http_urls(self):
205
205
"""Trap invalid construction of urls"""
206
206
t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
207
self.assertRaises((errors.InvalidURL, errors.ConnectionError),
207
self.assertRaises(errors.InvalidURL,
209
209
'http://http://bazaar-vcs.org/bzr/bzr.dev/')
797
797
osutils.set_or_unset_env(name, value)
799
799
def _proxied_request(self):
800
handler = ProxyHandler(PasswordManager())
800
handler = ProxyHandler()
801
801
request = Request('GET','http://baz/buzzle')
802
802
handler.set_proxy(request, 'http')
832
832
# FIXME: We don't have an https server available, so we don't
833
833
# test https connections.
835
# FIXME: Once the test suite is better fitted to test
836
# authorization schemes, test proxy authorizations too (see
840
836
TestCaseWithTwoWebservers.setUp(self)
841
837
self.build_tree_contents([('foo', 'contents of foo\n'),
1222
1220
self.build_tree_contents([('a', 'contents of a\n'),
1223
1221
('b', 'contents of b\n'),])
1224
self.old_factory = ui.ui_factory
1225
# The following has the unfortunate side-effect of hiding any ouput
1226
# during the tests (including pdb prompts). Feel free to comment them
1227
# for debugging purposes but leave them in place, there are needed to
1228
# run the tests without any console
1229
self.old_stdout = sys.stdout
1230
sys.stdout = StringIOWrapper()
1231
self.addCleanup(self.restoreUIFactory)
1233
def restoreUIFactory(self):
1234
ui.ui_factory = self.old_factory
1235
sys.stdout = self.old_stdout
1237
1223
def get_user_url(self, user=None, password=None):
1238
1224
"""Build an url embedding user and password"""
1286
1272
def test_prompt_for_password(self):
1287
1273
self.server.add_user('joe', 'foo')
1288
1274
t = self.get_user_transport('joe', None)
1289
ui.ui_factory = TestUIFactory(stdin='foo\n')
1275
stdout = StringIOWrapper()
1276
ui.ui_factory = TestUIFactory(stdin='foo\n', stdout=stdout)
1290
1277
self.assertEqual('contents of a\n',t.get('a').read())
1291
1278
# stdin should be empty
1292
1279
self.assertEqual('', ui.ui_factory.stdin.readline())
1280
self._check_password_prompt(t._unqualified_scheme, 'joe',
1293
1282
# And we shouldn't prompt again for a different request
1294
1283
# against the same transport.
1295
1284
self.assertEqual('contents of b\n',t.get('b').read())
1299
1288
# Only one 'Authentication Required' error should occur
1300
1289
self.assertEqual(1, self.server.auth_required_errors)
1291
def _check_password_prompt(self, scheme, user, actual_prompt):
1292
expected_prompt = (self._password_prompt_prefix
1293
+ ("%s %s@%s:%d, Realm: '%s' password: "
1295
user, self.server.host, self.server.port,
1296
self.server.auth_realm)))
1297
self.assertEquals(expected_prompt, actual_prompt)
1299
def test_no_prompt_for_password_when_using_auth_config(self):
1302
stdin_content = 'bar\n' # Not the right password
1303
self.server.add_user(user, password)
1304
t = self.get_user_transport(user, None)
1305
ui.ui_factory = TestUIFactory(stdin=stdin_content,
1306
stdout=StringIOWrapper())
1307
# Create a minimal config file with the right password
1308
conf = config.AuthenticationConfig()
1309
conf._get_config().update(
1310
{'httptest': {'scheme': 'http', 'port': self.server.port,
1311
'user': user, 'password': password}})
1313
# Issue a request to the server to connect
1314
self.assertEqual('contents of a\n',t.get('a').read())
1315
# stdin should have been left untouched
1316
self.assertEqual(stdin_content, ui.ui_factory.stdin.readline())
1317
# Only one 'Authentication Required' error should occur
1318
self.assertEqual(1, self.server.auth_required_errors)
1303
1322
class TestHTTPAuth(TestAuth):
1304
1323
"""Test HTTP authentication schemes.