/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

(vila) Don't leak credentials with -Dhttp (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    bzrdir,
35
35
    cethread,
36
36
    config,
 
37
    debug,
37
38
    errors,
38
39
    osutils,
39
40
    remote as _mod_remote,
40
41
    tests,
 
42
    trace,
41
43
    transport,
42
44
    ui,
43
45
    )
100
102
        ]
101
103
    # Add some attributes common to all scenarios
102
104
    for scenario_id, scenario_dict in scenarios:
103
 
        scenario_dict.update(_username_prompt_prefix='',
 
105
        scenario_dict.update(_auth_header='Authorization',
 
106
                             _username_prompt_prefix='',
104
107
                             _password_prompt_prefix='')
105
108
    return scenarios
106
109
 
107
110
 
108
111
def vary_by_http_proxy_auth_scheme():
109
112
    scenarios = [
110
 
        ('basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
111
 
        ('digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
112
 
        ('basicdigest',
 
113
        ('proxy-basic', dict(_auth_server=http_utils.ProxyBasicAuthServer)),
 
114
        ('proxy-digest', dict(_auth_server=http_utils.ProxyDigestAuthServer)),
 
115
        ('proxy-basicdigest',
113
116
            dict(_auth_server=http_utils.ProxyBasicAndDigestAuthServer)),
114
117
        ]
115
118
    # Add some attributes common to all scenarios
116
119
    for scenario_id, scenario_dict in scenarios:
117
 
        scenario_dict.update(_username_prompt_prefix='Proxy ',
 
120
        scenario_dict.update(_auth_header='Proxy-Authorization',
 
121
                             _username_prompt_prefix='Proxy ',
118
122
                             _password_prompt_prefix='Proxy ')
119
123
    return scenarios
120
124
 
1728
1732
        # Only one 'Authentication Required' error should occur
1729
1733
        self.assertEqual(1, self.server.auth_required_errors)
1730
1734
 
 
1735
    def test_no_credential_leaks_in_log(self):
 
1736
        self.overrideAttr(debug, 'debug_flags', set(['http']))
 
1737
        user = 'joe'
 
1738
        password = 'very-sensitive-password'
 
1739
        self.server.add_user(user, password)
 
1740
        t = self.get_user_transport(user, password)
 
1741
        # Capture the debug calls to mutter
 
1742
        self.mutters = []
 
1743
        def mutter(*args):
 
1744
            lines = args[0] % args[1:]
 
1745
            # Some calls output multiple lines, just split them now since we
 
1746
            # care about a single one later.
 
1747
            self.mutters.extend(lines.splitlines())
 
1748
        self.overrideAttr(trace, 'mutter', mutter)
 
1749
        # Issue a request to the server to connect
 
1750
        self.assertEqual(True, t.has('a'))
 
1751
        # Only one 'Authentication Required' error should occur
 
1752
        self.assertEqual(1, self.server.auth_required_errors)
 
1753
        # Since the authentification succeeded, there should be a corresponding
 
1754
        # debug line
 
1755
        sent_auth_headers = [line for line in self.mutters
 
1756
                             if line.startswith('> %s' % (self._auth_header,))]
 
1757
        self.assertLength(1, sent_auth_headers)
 
1758
        self.assertStartsWith(sent_auth_headers[0],
 
1759
                              '> %s: <masked>' % (self._auth_header,))
 
1760
 
1731
1761
 
1732
1762
class TestProxyAuth(TestAuth):
1733
1763
    """Test proxy authentication schemes.
2243
2273
        # stdout should be empty, stderr will contains the prompts
2244
2274
        self.assertEqual('', stdout.getvalue())
2245
2275
 
2246