159
class FakeControlFiles(object):
160
class FakeControlFilesAndTransport(object):
161
162
def __init__(self, user_id=None):
165
self.files['email'] = user_id
164
166
self._transport = self
166
168
def get_utf8(self, filename):
167
if filename != 'email':
168
raise NotImplementedError
169
if self.email is not None:
170
return StringIO(self.email)
171
raise errors.NoSuchFile(filename)
170
raise AssertionError("get_utf8 should no longer be used")
173
172
def get(self, filename):
175
175
return StringIO(self.files[filename])
177
177
raise errors.NoSuchFile(filename)
179
def get_bytes(self, filename):
182
return self.files[filename]
184
raise errors.NoSuchFile(filename)
179
186
def put(self, filename, fileobj):
180
187
self.files[filename] = fileobj.read()
995
1002
my_config = config.BranchConfig(branch)
996
1003
self.assertEqual("Robert Collins <robertc@example.net>",
997
1004
my_config.username())
998
branch.control_files.email = "John"
1005
my_config.branch.control_files.files['email'] = "John"
999
1006
my_config.set_user_option('email',
1000
1007
"Robert Collins <robertc@example.org>")
1001
1008
self.assertEqual("John", my_config.username())
1002
branch.control_files.email = None
1009
del my_config.branch.control_files.files['email']
1003
1010
self.assertEqual("Robert Collins <robertc@example.org>",
1004
1011
my_config.username())
1006
1013
def test_not_set_in_branch(self):
1007
1014
my_config = self.get_branch_config(sample_config_text)
1008
my_config.branch.control_files.email = None
1009
1015
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
1010
1016
my_config._get_user_id())
1011
my_config.branch.control_files.email = "John"
1017
my_config.branch.control_files.files['email'] = "John"
1012
1018
self.assertEqual("John", my_config._get_user_id())
1014
1020
def test_BZR_EMAIL_OVERRIDES(self):
1220
1226
self.assertEquals({}, conf._get_config())
1221
1227
self._got_user_passwd(None, None, conf, 'http', 'foo.net')
1223
def test_broken_config(self):
1229
def test_missing_auth_section_header(self):
1230
conf = config.AuthenticationConfig(_file=StringIO('foo = bar'))
1231
self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
1233
def test_auth_section_header_not_closed(self):
1224
1234
conf = config.AuthenticationConfig(_file=StringIO('[DEF'))
1225
1235
self.assertRaises(errors.ParseConfigError, conf._get_config)
1237
def test_auth_value_not_boolean(self):
1227
1238
conf = config.AuthenticationConfig(_file=StringIO(
1231
1242
verify_certificates=askme # Error: Not a boolean
1233
1244
self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
1246
def test_auth_value_not_int(self):
1234
1247
conf = config.AuthenticationConfig(_file=StringIO(
1355
1368
self._got_user_passwd(None, None,
1356
1369
conf, 'http', 'bar.org', user='georges')
1371
def test_credentials_for_user_without_password(self):
1372
conf = config.AuthenticationConfig(_file=StringIO(
1379
# Get user but no password
1380
self._got_user_passwd('jim', None,
1381
conf, 'http', 'bar.org')
1358
1383
def test_verify_certificates(self):
1359
1384
conf = config.AuthenticationConfig(_file=StringIO(
1418
1443
'SMTP %(user)s@%(host)s:%(port)d password: ',
1419
1444
'smtp', port=10025)
1446
def test_ssh_password_emits_warning(self):
1447
conf = config.AuthenticationConfig(_file=StringIO(
1455
entered_password = 'typed-by-hand'
1456
stdout = tests.StringIOWrapper()
1457
ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1460
# Since the password defined in the authentication config is ignored,
1461
# the user is prompted
1462
self.assertEquals(entered_password,
1463
conf.get_password('ssh', 'bar.org', user='jim'))
1464
self.assertContainsRe(
1465
self._get_log(keep_log_file=True),
1466
'password ignored in section \[ssh with password\]')
1468
def test_ssh_without_password_doesnt_emit_warning(self):
1469
conf = config.AuthenticationConfig(_file=StringIO(
1476
entered_password = 'typed-by-hand'
1477
stdout = tests.StringIOWrapper()
1478
ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1481
# Since the password defined in the authentication config is ignored,
1482
# the user is prompted
1483
self.assertEquals(entered_password,
1484
conf.get_password('ssh', 'bar.org', user='jim'))
1485
# No warning shoud be emitted since there is no password. We are only
1487
self.assertNotContainsRe(
1488
self._get_log(keep_log_file=True),
1489
'password ignored in section \[ssh with password\]')
1422
1492
# FIXME: Once we have a way to declare authentication to all test servers, we
1423
1493
# can implement generic tests.