270
270
def test_empty_header(self):
271
271
scheme, remainder = self.parse_header('')
272
self.assertEquals('', scheme)
272
self.assertEqual('', scheme)
273
273
self.assertIs(None, remainder)
275
275
def test_negotiate_header(self):
276
276
scheme, remainder = self.parse_header('Negotiate')
277
self.assertEquals('negotiate', scheme)
277
self.assertEqual('negotiate', scheme)
278
278
self.assertIs(None, remainder)
280
280
def test_basic_header(self):
281
281
scheme, remainder = self.parse_header(
282
282
'Basic realm="Thou should not pass"')
283
self.assertEquals('basic', scheme)
284
self.assertEquals('realm="Thou should not pass"', remainder)
283
self.assertEqual('basic', scheme)
284
self.assertEqual('realm="Thou should not pass"', remainder)
286
286
def test_basic_extract_realm(self):
287
287
scheme, remainder = self.parse_header(
289
289
_urllib2_wrappers.BasicAuthHandler)
290
290
match, realm = self.auth_handler.extract_realm(remainder)
291
291
self.assertTrue(match is not None)
292
self.assertEquals('Thou should not pass', realm)
292
self.assertEqual('Thou should not pass', realm)
294
294
def test_digest_header(self):
295
295
scheme, remainder = self.parse_header(
296
296
'Digest realm="Thou should not pass"')
297
self.assertEquals('digest', scheme)
298
self.assertEquals('realm="Thou should not pass"', remainder)
297
self.assertEqual('digest', scheme)
298
self.assertEqual('realm="Thou should not pass"', remainder)
301
301
class TestHTTPServer(tests.TestCase):
393
393
def test_url_parsing(self):
394
394
f = FakeManager()
395
395
url = http.extract_auth('http://example.com', f)
396
self.assertEquals('http://example.com', url)
397
self.assertEquals(0, len(f.credentials))
396
self.assertEqual('http://example.com', url)
397
self.assertEqual(0, len(f.credentials))
398
398
url = http.extract_auth(
399
399
'http://user:pass@www.bazaar-vcs.org/bzr/bzr.dev', f)
400
self.assertEquals('http://www.bazaar-vcs.org/bzr/bzr.dev', url)
401
self.assertEquals(1, len(f.credentials))
402
self.assertEquals([None, 'www.bazaar-vcs.org', 'user', 'pass'],
400
self.assertEqual('http://www.bazaar-vcs.org/bzr/bzr.dev', url)
401
self.assertEqual(1, len(f.credentials))
402
self.assertEqual([None, 'www.bazaar-vcs.org', 'user', 'pass'],
406
406
class TestHttpTransportUrls(tests.TestCase):
1418
1418
t = self.old_transport
1420
1420
req = RedirectedRequest('GET', t.abspath('a'))
1421
req.follow_redirections = True
1422
1421
new_prefix = 'http://%s:%s' % (self.new_server.host,
1423
1422
self.new_server.port)
1424
1423
self.old_server.redirections = \
1425
1424
[('(.*)', r'%s/1\1' % (new_prefix), 301),]
1426
self.assertEquals('redirected once',t._perform(req).read())
1425
self.assertEqual('redirected once',t._perform(req).read())
1428
1427
def test_five_redirections(self):
1429
1428
t = self.old_transport
1431
1430
req = RedirectedRequest('GET', t.abspath('a'))
1432
req.follow_redirections = True
1433
1431
old_prefix = 'http://%s:%s' % (self.old_server.host,
1434
1432
self.old_server.port)
1435
1433
new_prefix = 'http://%s:%s' % (self.new_server.host,
1472
1470
dir, file = urlutils.split(exception.target)
1473
1471
return self._transport(dir)
1475
self.assertEquals('0123456789',
1476
transport.do_catching_redirections(
1473
self.assertEqual('0123456789',
1474
transport.do_catching_redirections(
1477
1475
self.get_a, self.old_transport, redirected).read())
1478
self.assertEquals(1, self.redirections)
1476
self.assertEqual(1, self.redirections)
1480
1478
def test_redirection_loop(self):
2154
2152
def assertActivitiesMatch(self):
2155
2153
# Nothing to check here
2157
class TestAuthOnRedirected(http_utils.TestCaseWithRedirectedWebserver):
2158
"""Test authentication on the redirected http server."""
2160
_auth_header = 'Authorization'
2161
_password_prompt_prefix = ''
2162
_username_prompt_prefix = ''
2163
_auth_server = http_utils.HTTPBasicAuthServer
2164
_transport = _urllib.HttpTransport_urllib
2166
def create_transport_readonly_server(self):
2167
return self._auth_server()
2169
def create_transport_secondary_server(self):
2170
"""Create the secondary server redirecting to the primary server"""
2171
new = self.get_readonly_server()
2173
redirecting = http_utils.HTTPServerRedirecting()
2174
redirecting.redirect_to(new.host, new.port)
2178
super(TestAuthOnRedirected, self).setUp()
2179
self.build_tree_contents([('a','a'),
2181
('1/a', 'redirected once'),
2183
new_prefix = 'http://%s:%s' % (self.new_server.host,
2184
self.new_server.port)
2185
self.old_server.redirections = [
2186
('(.*)', r'%s/1\1' % (new_prefix), 301),]
2187
self.old_transport = self._transport(self.old_server.get_url())
2188
self.new_server.add_user('joe', 'foo')
2190
def get_a(self, transport):
2191
return transport.get('a')
2193
def test_auth_on_redirected_via_do_catching_redirections(self):
2194
self.redirections = 0
2196
def redirected(transport, exception, redirection_notice):
2197
self.redirections += 1
2198
dir, file = urlutils.split(exception.target)
2199
return self._transport(dir)
2201
stdout = tests.StringIOWrapper()
2202
stderr = tests.StringIOWrapper()
2203
ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n',
2204
stdout=stdout, stderr=stderr)
2205
self.assertEqual('redirected once',
2206
transport.do_catching_redirections(
2207
self.get_a, self.old_transport, redirected).read())
2208
self.assertEqual(1, self.redirections)
2209
# stdin should be empty
2210
self.assertEqual('', ui.ui_factory.stdin.readline())
2211
# stdout should be empty, stderr will contains the prompts
2212
self.assertEqual('', stdout.getvalue())
2214
def test_auth_on_redirected_via_following_redirections(self):
2215
self.new_server.add_user('joe', 'foo')
2216
stdout = tests.StringIOWrapper()
2217
stderr = tests.StringIOWrapper()
2218
ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n',
2219
stdout=stdout, stderr=stderr)
2220
t = self.old_transport
2221
req = RedirectedRequest('GET', t.abspath('a'))
2222
new_prefix = 'http://%s:%s' % (self.new_server.host,
2223
self.new_server.port)
2224
self.old_server.redirections = [
2225
('(.*)', r'%s/1\1' % (new_prefix), 301),]
2226
self.assertEqual('redirected once',t._perform(req).read())
2227
# stdin should be empty
2228
self.assertEqual('', ui.ui_factory.stdin.readline())
2229
# stdout should be empty, stderr will contains the prompts
2230
self.assertEqual('', stdout.getvalue())