1107
1107
self.assertEqual(value, 'value3-top')
1108
1108
value = tree_config.get_option('key3', 'SECTION')
1109
1109
self.assertEqual(value, 'value3-section')
1112
class TestAuthenticationConfig(TestCase):
1113
"""Test the authentication.conf file matching."""
1115
# XXX: test definitions without users.
1117
def _got_user_passwd(self, expected_user, expected_password,
1118
config, *args, **kwargs):
1119
credentials = config.get_credentials(*args, **kwargs)
1120
if credentials is None:
1124
user = credentials['user']
1125
password = credentials['password']
1126
self.assertEquals(expected_user, user)
1127
self.assertEquals(expected_password, password)
1129
def test_empty_config(self):
1130
conf = config.AuthenticationConfig(_file=StringIO())
1131
self.assertEquals({}, conf._get_config())
1132
self._got_user_passwd(None, None, conf, 'http', 'foo.net')
1134
def test_broken_config(self):
1135
conf = config.AuthenticationConfig(_file=StringIO('[DEF'))
1136
self.assertRaises(errors.ParseConfigError, conf._get_config)
1138
def test_credentials_for_scheme_host(self):
1139
conf = config.AuthenticationConfig(_file=StringIO(
1140
"""# Identity on foo.net
1145
password=secret-pass
1148
self._got_user_passwd('joe', 'secret-pass', conf, 'ftp', 'foo.net')
1150
self._got_user_passwd(None, None, conf, 'http', 'foo.net')
1152
self._got_user_passwd(None, None, conf, 'ftp', 'bar.net')
1154
def test_credentials_for_host_port(self):
1155
conf = config.AuthenticationConfig(_file=StringIO(
1156
"""# Identity on foo.net
1162
password=secret-pass
1165
self._got_user_passwd('joe', 'secret-pass',
1166
conf, 'ftp', 'foo.net', port=10021)
1168
self._got_user_passwd(None, None, conf, 'ftp', 'foo.net')
1170
def test_for_matching_host(self):
1171
conf = config.AuthenticationConfig(_file=StringIO(
1172
"""# Identity on foo.net
1178
[sourceforge domain]
1185
self._got_user_passwd('georges', 'bendover',
1186
conf, 'bzr', 'foo.bzr.sf.net')
1188
self._got_user_passwd(None, None,
1189
conf, 'bzr', 'bbzr.sf.net')
1191
def test_for_matching_host_None(self):
1192
conf = config.AuthenticationConfig(_file=StringIO(
1193
"""# Identity on foo.net
1203
self._got_user_passwd('joe', 'joepass',
1204
conf, 'bzr', 'quux.net')
1205
# no host but different scheme
1206
self._got_user_passwd('georges', 'bendover',
1207
conf, 'ftp', 'quux.net')
1209
def test_credentials_for_path(self):
1210
conf = config.AuthenticationConfig(_file=StringIO(
1226
self._got_user_passwd(None, None,
1227
conf, 'http', host='bar.org', path='/dir3')
1229
self._got_user_passwd('georges', 'bendover',
1230
conf, 'http', host='bar.org', path='/dir2')
1232
self._got_user_passwd('jim', 'jimpass',
1233
conf, 'http', host='bar.org',path='/dir1/subdir')
1235
def test_credentials_for_user(self):
1236
conf = config.AuthenticationConfig(_file=StringIO(
1245
self._got_user_passwd('jim', 'jimpass',
1246
conf, 'http', 'bar.org')
1248
self._got_user_passwd('jim', 'jimpass',
1249
conf, 'http', 'bar.org', user='jim')
1250
# Don't get a different user if one is specified
1251
self._got_user_passwd(None, None,
1252
conf, 'http', 'bar.org', user='georges')
1254
def test_verify_certificates(self):
1255
conf = config.AuthenticationConfig(_file=StringIO(
1262
verify_certificates=False
1269
credentials = conf.get_credentials('https', 'bar.org')
1270
self.assertEquals(False, credentials.get('verify_certificates'))
1271
credentials = conf.get_credentials('https', 'foo.net')
1272
self.assertEquals(True, credentials.get('verify_certificates'))