def test_prompt_for_password(self):
     t = self.get_transport()
     ui.ui_factory = ui.CannedInputUIFactory([self.password])
     # Issue a request to the server to connect
     t.has('whatever/not/existing')
     # stdin should be empty (the provided password have been consumed)
     ui.ui_factory.assert_all_input_consumed()
Example #2
0
 def test_canned_input_get_input(self):
     uif = _mod_ui.CannedInputUIFactory([True, 'mbp', 'password', 42])
     self.assertEqual(True, uif.get_boolean(u'Extra cheese?'))
     self.assertEqual('mbp', uif.get_username(u'Enter your user name'))
     self.assertEqual('password',
                      uif.get_password(u'Password for %(host)s',
                                       host='example.com'))
     self.assertEqual(42, uif.get_integer(u'And all that jazz ?'))
 def test_locked(self):
     # break_lock when locked should unlock the branch and repo
     self.branch.lock_write()
     ui.ui_factory = ui.CannedInputUIFactory([True, True])
     try:
         self.unused_branch.break_lock()
     except NotImplementedError:
         # branch does not support break_lock
         self.branch.unlock()
         return
     self.assertRaises(errors.LockBroken, self.branch.unlock)
    def test_smtp_password_from_user(self):
        user = '******'
        password = '******'
        factory = WideOpenSMTPFactory()
        conn = self.get_connection('[DEFAULT]\nsmtp_username=%s\n' % user,
                                   smtp_factory=factory)
        self.assertIs(None, conn._smtp_password)

        ui.ui_factory = ui.CannedInputUIFactory([password])
        conn._connect()
        self.assertEqual(password, conn._smtp_password)
 def test_no_prompt_for_username(self):
     """ensure getpass.getuser() is used if there's no username in the 
     configuration.""",
     self.get_server().add_user(getpass.getuser(), self.password)
     t = self.get_transport()
     ui.ui_factory = ui.CannedInputUIFactory([self.password])
     # Issue a request to the server to connect
     t.put_bytes('foo', 'test bytes\n')
     self.assertEqual('test bytes\n', t.get_bytes('foo'))
     # Only the password should've been read
     ui.ui_factory.assert_all_input_consumed()
 def test_empty_password(self):
     # Override the default user/password from setUp
     self.user = '******'
     self.password = ''
     self.get_server().add_user(self.user, self.password)
     t = self.get_transport()
     ui.ui_factory = ui.CannedInputUIFactory([self.password])
     # Issue a request to the server to connect
     t.has('whatever/not/existing')
     # stdin should be empty (the provided password have been consumed),
     # even if the password is empty, it's followed by a newline.
     ui.ui_factory.assert_all_input_consumed()
 def test_no_prompt_for_password_when_using_auth_config(self):
     t = self.get_transport()
     ui.ui_factory = ui.CannedInputUIFactory([])
     # Create a config file with the right password
     conf = config.AuthenticationConfig()
     conf._get_config().update({'ftptest': {'scheme': 'ftp',
                                            'user': self.user,
                                            'password': self.password}})
     conf._save()
     # Issue a request to the server to connect
     t.put_bytes('foo', 'test bytes\n')
     self.assertEqual('test bytes\n', t.get_bytes('foo'))
Example #8
0
 def test_locked(self):
     # break_lock when locked should
     self.workingtree.lock_write()
     ui.ui_factory = ui.CannedInputUIFactory([True, True, True])
     try:
         self.unused_workingtree.break_lock()
     except (NotImplementedError, errors.LockActive):
         # workingtree does not support break_lock,
         # or does not support breaking a lock held by an alive
         # object/process.
         self.workingtree.unlock()
         return
     self.assertRaises(errors.LockBroken, self.workingtree.unlock)
Example #9
0
 def test_unlocked_repo_locked(self):
     # break lock on the workingtree should try on the branch even
     # if the workingtree isn't locked - and the easiest way
     # to see if that happened is to lock the repo.
     self.workingtree.branch.repository.lock_write()
     ui.ui_factory = ui.CannedInputUIFactory([True])
     try:
         self.unused_workingtree.break_lock()
     except NotImplementedError:
         # workingtree does not support break_lock
         self.workingtree.branch.repository.unlock()
         return
     if ui.ui_factory.responses == [True]:
         raise TestNotApplicable("repository does not physically lock.")
     self.assertRaises(errors.LockBroken,
                       self.workingtree.branch.repository.unlock)
 def test_break_lock(self):
     base = self.make_repository('base')
     repo = self.make_referring('referring', base)
     unused_repo = repo.bzrdir.open_repository()
     base.lock_write()
     self.addCleanup(base.unlock)
     # break_lock when locked should
     repo.lock_write()
     self.assertEqual(repo.get_physical_lock_status(),
                      unused_repo.get_physical_lock_status())
     if not unused_repo.get_physical_lock_status():
         # 'lock_write' has not taken a physical mutex out.
         repo.unlock()
         return
     ui.ui_factory = ui.CannedInputUIFactory([True])
     unused_repo.break_lock()
     self.assertRaises(errors.LockBroken, repo.unlock)
 def test_unlocks_master_branch(self):
     # break_lock when the master branch is locked should offer to
     # unlock it.
     master = self.make_branch('master')
     try:
         self.branch.bind(master)
     except errors.UpgradeRequired:
         # this branch does not support binding.
         return
     master.lock_write()
     ui.ui_factory = ui.CannedInputUIFactory([True, True])
     try:
         fresh = _mod_branch.Branch.open(self.unused_branch.base)
         fresh.break_lock()
     except NotImplementedError:
         # branch does not support break_lock
         master.unlock()
         return
     self.assertRaises(errors.LockBroken, master.unlock)
     # can we lock it now ?
     master.lock_write()
     master.unlock()
 def test_unlocked_repo_locked(self):
     # break lock on the branch should try on the repository even
     # if the branch isn't locked
     token = self.branch.repository.lock_write().repository_token
     if token is None:
         self.branch.repository.unlock()
         raise tests.TestNotApplicable(
             'Repository does not use physical locks.')
     self.branch.repository.leave_lock_in_place()
     self.branch.repository.unlock()
     other_instance = self.branch.repository.bzrdir.open_repository()
     if not other_instance.get_physical_lock_status():
         raise tests.TestNotApplicable(
             'Repository does not lock persistently.')
     ui.ui_factory = ui.CannedInputUIFactory([True])
     try:
         self.unused_branch.break_lock()
     except NotImplementedError:
         # branch does not support break_lock
         self.branch.repository.unlock()
         return
     self.assertRaises(errors.LockBroken, self.branch.repository.unlock)
Example #13
0
 def setUp(self):
     super(TestCannedInputUIFactory, self).setUp()
     self.factory = ui.CannedInputUIFactory([])
 def setUp(self):
     super(TestBreakLock, self).setUp()
     self.unused_repo = self.make_repository('.')
     self.repo = self.unused_repo.bzrdir.open_repository()
     ui.ui_factory = ui.CannedInputUIFactory([True])