Esempio n. 1
0
 def test_drop_no_privileges(self):
     with contextlib.nested(mock.patch.object(os, 'setgroups'),
                            mock.patch.object(daemon, 'setgid'),
                            mock.patch.object(daemon, 'setuid')) as mocks:
         daemon.drop_privileges()
         for cursor in mocks:
             self.assertFalse(cursor.called)
Esempio n. 2
0
 def test_drop_no_privileges(self):
     with contextlib.nested(
             mock.patch.object(os, 'setgroups'),
             mock.patch.object(daemon, 'setgid'),
             mock.patch.object(daemon, 'setuid')) as mocks:
         daemon.drop_privileges()
         for cursor in mocks:
             self.assertFalse(cursor.called)
Esempio n. 3
0
 def _test_drop_privileges(self, setuid, setgid, setgroups, geteuid, user=None, group=None):
     daemon.drop_privileges(user=user, group=group)
     if user:
         setuid.assert_called_once_with(user)
     else:
         self.assertFalse(setuid.called)
     if group:
         setgroups.assert_called_once_with([])
         setgid.assert_called_once_with(group)
     else:
         self.assertFalse(setgroups.called)
         self.assertFalse(setgid.called)
Esempio n. 4
0
 def _test_drop_privileges(self, setuid, setgid, setgroups,
                           geteuid, user=None, group=None):
     daemon.drop_privileges(user=user, group=group)
     if user:
         setuid.assert_called_once_with(user)
     else:
         self.assertFalse(setuid.called)
     if group:
         setgroups.assert_called_once_with([])
         setgid.assert_called_once_with(group)
     else:
         self.assertFalse(setgroups.called)
         self.assertFalse(setgid.called)
Esempio n. 5
0
 def _test_drop_privileges(self, user=None, group=None):
     with contextlib.nested(
             mock.patch.object(os, 'geteuid', return_value=0),
             mock.patch.object(os, 'setgroups'),
             mock.patch.object(daemon, 'setgid'),
             mock.patch.object(daemon, 'setuid')) as (geteuid, setgroups,
                                                      setgid, setuid):
         daemon.drop_privileges(user=user, group=group)
         if user:
             setuid.assert_called_once_with(user)
         else:
             self.assertFalse(setuid.called)
         if group:
             setgroups.assert_called_once_with([])
             setgid.assert_called_once_with(group)
         else:
             self.assertFalse(setgroups.called)
             self.assertFalse(setgid.called)
Esempio n. 6
0
 def _test_drop_privileges(self, user=None, group=None):
     with contextlib.nested(
             mock.patch.object(os, 'geteuid', return_value=0),
             mock.patch.object(os, 'setgroups'),
             mock.patch.object(daemon, 'setgid'),
             mock.patch.object(daemon, 'setuid')) as (
                 geteuid, setgroups, setgid, setuid):
         daemon.drop_privileges(user=user, group=group)
         if user:
             setuid.assert_called_once_with(user)
         else:
             self.assertFalse(setuid.called)
         if group:
             setgroups.assert_called_once_with([])
             setgid.assert_called_once_with(group)
         else:
             self.assertFalse(setgroups.called)
             self.assertFalse(setgid.called)
Esempio n. 7
0
 def test_drop_no_privileges(self, mock_setuid, mock_setgid,
                             mock_setgroups):
     daemon.drop_privileges()
     for cursor in (mock_setuid, mock_setgid, mock_setgroups):
         self.assertFalse(cursor.called)
Esempio n. 8
0
 def test_drop_no_privileges(self, mock_setuid, mock_setgid,
                             mock_setgroups):
     daemon.drop_privileges()
     for cursor in (mock_setuid, mock_setgid, mock_setgroups):
         self.assertFalse(cursor.called)