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'),
934
930
self.no_proxy_host = 'localhost'
936
932
def test_HTTP_PROXY(self):
937
# pycurl do not check HTTP_PROXY for security reasons
933
# pycurl does not check HTTP_PROXY for security reasons
938
934
# (for use in a CGI context that we do not care
939
935
# about. Should we ?)
936
raise TestSkipped('pycurl does not check HTTP_PROXY '
937
'for security reasons')
942
939
def test_HTTP_PROXY_with_NO_PROXY(self):
940
raise TestSkipped('pycurl does not check HTTP_PROXY '
941
'for security reasons')
945
943
def test_http_proxy_without_scheme(self):
946
944
# pycurl *ignores* invalid proxy env variables. If that
1220
1220
self.build_tree_contents([('a', 'contents of a\n'),
1221
1221
('b', 'contents of b\n'),])
1222
self.old_factory = ui.ui_factory
1223
# The following has the unfortunate side-effect of hiding any ouput
1224
# during the tests (including pdb prompts). Feel free to comment them
1225
# for debugging purposes but leave them in place, there are needed to
1226
# run the tests without any console
1227
self.old_stdout = sys.stdout
1228
sys.stdout = StringIOWrapper()
1229
self.addCleanup(self.restoreUIFactory)
1231
def restoreUIFactory(self):
1232
ui.ui_factory = self.old_factory
1233
sys.stdout = self.old_stdout
1235
1223
def get_user_url(self, user=None, password=None):
1236
1224
"""Build an url embedding user and password"""
1284
1272
def test_prompt_for_password(self):
1285
1273
self.server.add_user('joe', 'foo')
1286
1274
t = self.get_user_transport('joe', None)
1287
ui.ui_factory = TestUIFactory(stdin='foo\n')
1275
stdout = StringIOWrapper()
1276
ui.ui_factory = TestUIFactory(stdin='foo\n', stdout=stdout)
1288
1277
self.assertEqual('contents of a\n',t.get('a').read())
1289
1278
# stdin should be empty
1290
1279
self.assertEqual('', ui.ui_factory.stdin.readline())
1280
self._check_password_prompt(t._unqualified_scheme, 'joe',
1291
1282
# And we shouldn't prompt again for a different request
1292
1283
# against the same transport.
1293
1284
self.assertEqual('contents of b\n',t.get('b').read())
1297
1288
# Only one 'Authentication Required' error should occur
1298
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)
1301
1322
class TestHTTPAuth(TestAuth):
1302
1323
"""Test HTTP authentication schemes.