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.assertEquals('redirected once',
2206
transport.do_catching_redirections(
2207
self.get_a, self.old_transport, redirected).read())
2208
self.assertEquals(1, self.redirections)
2209
# stdin should be empty
2210
self.assertEqual('', ui.ui_factory.stdin.readline())
2211
self.assertEquals('', stdout.getvalue())
2213
def test_auth_on_redirected_via_following_redirections(self):
2214
self.new_server.add_user('joe', 'foo')
2215
stdout = tests.StringIOWrapper()
2216
stderr = tests.StringIOWrapper()
2217
ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n',
2218
stdout=stdout, stderr=stderr)
2219
t = self.old_transport
2220
req = RedirectedRequest('GET', t.abspath('a'))
2221
new_prefix = 'http://%s:%s' % (self.new_server.host,
2222
self.new_server.port)
2223
self.old_server.redirections = [
2224
('(.*)', r'%s/1\1' % (new_prefix), 301),]
2225
self.assertEquals('redirected once',t._perform(req).read())
2226
# stdin should be empty
2227
self.assertEqual('', ui.ui_factory.stdin.readline())
2228
self.assertEquals('', stdout.getvalue())