def test_scan_worldwritable_directories_with_no_sticky_bit_set(self, mock_os): # Prepare data and mocks test_subject = WorldWritable(None) mock_os.walk.return_value = [ ('/world/writable/not/sticky', (), ()), ('/not/world/writable/not/sticky', (), ()), ('/world/writable/sticky', (), ()), ] test_subject.is_world_writable = MagicMock(side_effect=[True, False, True]) test_subject.is_sticky_bit_set = MagicMock(side_effect=[False, True]) # Run test scenario result = test_subject.scan_worldwritable_directories_with_no_sticky_bit_set() # Assertions self.assertEqual(result, ['/world/writable/not/sticky']) mock_os.walk.assert_called_once_with('/') test_subject.is_world_writable.assert_has_calls( [ call('/world/writable/not/sticky'), call('/not/world/writable/not/sticky'), call('/world/writable/sticky'), ] ) test_subject.is_sticky_bit_set.assert_has_calls( [ call('/world/writable/not/sticky'), call('/world/writable/sticky'), ] )
def test_scan_worldwritable_directories_with_no_sticky_bit_set( self, mock_os): # Prepare data and mocks test_subject = WorldWritable(None) mock_os.walk.return_value = [ ('/world/writable/not/sticky', (), ()), ('/not/world/writable/not/sticky', (), ()), ('/world/writable/sticky', (), ()), ] test_subject.is_world_writable = MagicMock( side_effect=[True, False, True]) test_subject.is_sticky_bit_set = MagicMock(side_effect=[False, True]) # Run test scenario result = test_subject.scan_worldwritable_directories_with_no_sticky_bit_set( ) # Assertions self.assertEqual(result, ['/world/writable/not/sticky']) mock_os.walk.assert_called_once_with('/') test_subject.is_world_writable.assert_has_calls([ call('/world/writable/not/sticky'), call('/not/world/writable/not/sticky'), call('/world/writable/sticky'), ]) test_subject.is_sticky_bit_set.assert_has_calls([ call('/world/writable/not/sticky'), call('/world/writable/sticky'), ])
def test_is_sticky_bit_set_when_file_does_not_exist(self, mock_os): # Prepare data and mocks test_subject = WorldWritable(None) mock_os.stat.side_effect = raise_file_not_found_error path = '/does/not/actually/exist' # Run test scenario result = test_subject.is_sticky_bit_set(path) # Assertions self.assertFalse(result) mock_os.stat.assert_called_once_with(path)
def test_is_sticky_bit_set_when_is_set(self, mock_os): # Prepare data and mocks test_subject = WorldWritable(None) mock_os.stat.return_value = os.stat_result((0o01000, 0, 0, 0, 0, 0, 0, 0, 0, 0)) path = '/does/not/actually/exist' # Run test scenario result = test_subject.is_sticky_bit_set(path) # Assertions self.assertTrue(result) mock_os.stat.assert_called_once_with(path)
def test_is_sticky_bit_set_when_is_set(self, mock_os): # Prepare data and mocks test_subject = WorldWritable(None) mock_os.stat.return_value = os.stat_result( (0o01000, 0, 0, 0, 0, 0, 0, 0, 0, 0)) path = '/does/not/actually/exist' # Run test scenario result = test_subject.is_sticky_bit_set(path) # Assertions self.assertTrue(result) mock_os.stat.assert_called_once_with(path)