Пример #1
0
 def test_unix_su_user_password(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock(return_value=1)
     uobject.prompt = '$ '
     uobject.set_prompt = MagicMock
     uobject.shell.return_value.response.return_value = "root"
     self.assertTrue(UnixHost.su(uobject, password='******'))
Пример #2
0
 def test_unix_su_exception2(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock()
     uobject.execute.side_effect = (1, -1)
     uobject.prompt = '$ '
     uobject.get_su_credentials = MagicMock(return_value=('root',
                                                          'Embe1mpls'))
     self.assertRaises(Exception, lambda: UnixHost.su(uobject))
Пример #3
0
    def test_unix_su_exception4(self):
        uobject = MagicMock(spec=UnixHost)
        uobject.execute = MagicMock(side_effect=(1, 1))
        uobject.prompt = '$ '
        uobject.set_prompt = MagicMock()
        uobject.name = 'foo'
        uobject.channels = []  # needed to raise TobyException
        # Exception
        uobject.shell.return_value.response.return_value.find.return_value = -1
        try:
            UnixHost.su(uobject, password='******')
        except Exception as exp:
            self.assertEqual(exp.args[0], "Not able to switch to root user")

        # return True
        uobject.execute = MagicMock(side_effect=(1, 1))
        uobject.shell.return_value.response.return_value.find.return_value = 1
        uobject.get_su_credentials.return_value = ('root', 'Embe1mpls')
        uobject.shell.return_value.response.return_value = "root"
        self.assertTrue(UnixHost.su(uobject))

        # Exception
        uobject.execute = MagicMock(side_effect=(-1, 1))
        try:
            UnixHost.su(uobject)
        except Exception as exp:
            self.assertEqual(exp.args[0], "Not able to switch to root user")

        # Exception
        uobject.execute = MagicMock(side_effect=(-1, -1))
        try:
            UnixHost.su(uobject)
        except Exception as exp:
            self.assertEqual(exp.args[0], "Not able to switch to root user")
Пример #4
0
 def test_unix_su_exception(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock(side_effect=[1, 1])
     uobject.prompt = '$ '
     uobject.set_prompt = MagicMock
     uobject.shell = MagicMock(return_value=-1)
     print('toto')
     self.assertRaises(Exception,
                       lambda: UnixHost.su(uobject, password='******'))
Пример #5
0
 def test_unix_su(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock(return_value=1)
     uobject.get_su_credentials = MagicMock(return_value=('root',
                                                          'Embe1mpls'))
     uobject.prompt = '$ '
     uobject.set_prompt = MagicMock
     uobject.shell.return_value.response.return_value = "root"
     self.assertTrue(UnixHost.su(uobject))
Пример #6
0
 def test_unix_su_exception3(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock()
     uobject.prompt = '$ '
     uobject.execute.side_effect = Exception
     self.assertRaises(Exception, lambda: UnixHost.su(uobject))
Пример #7
0
 def test_unix_su_exception(self):
     uobject = MagicMock(spec=UnixHost)
     uobject.execute = MagicMock(return_value=-1)
     uobject.prompt = '$ '
     self.assertRaises(Exception, lambda: UnixHost.su(uobject))