コード例 #1
0
 def test_check_root_privilege(self):
     with ExitStack() as resources:
         mock_geteuid = resources.enter_context(
             patch('os.geteuid', return_value=0))
         resources.enter_context(
             patch('pwd.getpwuid', return_value=['test']))
         check_root_privilege()
         mock_geteuid.assert_called_with()
コード例 #2
0
 def test_check_root_privilege(self):
     with ExitStack() as resources:
         mock_geteuid = resources.enter_context(
             patch('os.geteuid', return_value=0))
         resources.enter_context(
             patch('pwd.getpwuid', return_value=['test']))
         check_root_privilege()
         mock_geteuid.assert_called_with()
コード例 #3
0
 def test_check_root_privilege_non_root(self):
     with ExitStack() as resources:
         mock_geteuid = resources.enter_context(
             patch('os.geteuid', return_value=1))
         resources.enter_context(
             patch('pwd.getpwuid', return_value=['test']))
         with self.assertRaises(PrivilegeError) as cm:
             check_root_privilege()
         mock_geteuid.assert_called_with()
         self.assertEqual(cm.exception.user_name, 'test')
コード例 #4
0
 def test_check_root_privilege_non_root(self):
     with ExitStack() as resources:
         mock_geteuid = resources.enter_context(
             patch('os.geteuid', return_value=1))
         resources.enter_context(
             patch('pwd.getpwuid', return_value=['test']))
         with self.assertRaises(PrivilegeError) as cm:
             check_root_privilege()
         mock_geteuid.assert_called_with()
         self.assertEqual(
             cm.exception.user_name, 'test')
コード例 #5
0
 def __init__(self, args):
     super().__init__(args)
     self.gadget_tree = args.gadget_tree
     # It's required to run ubuntu-image as root to build classic image.
     check_root_privilege()
コード例 #6
0
 def __init__(self, args):
     super().__init__(args)
     self.gadget_tree = args.gadget_tree
     # It's required to run ubuntu-image as root to build classic image.
     check_root_privilege()