def test_get_decoder_file_exceptions(): """Test exceptions on get method.""" # File does not exist result = decoder.get_decoder_file(filename='non_existing_file.xml') assert not result.affected_items assert result.render()['data']['failed_items'][0]['error']['code'] == 1503 # Invalid XML result = decoder.get_decoder_file(filename='wrong_decoders.xml') assert not result.affected_items assert result.render()['data']['failed_items'][0]['error']['code'] == 1501 # File permissions filename = 'test2_decoders.xml' old_permissions = stat.S_IMODE( os.lstat(os.path.join(test_data_path, 'tests/data/decoders', filename)).st_mode) try: os.chmod(os.path.join(test_data_path, 'tests/data/decoders', filename), 000) # UUT 3rd call forcing a permissions error opening decoder file result = decoder.get_decoder_file(filename=filename) assert not result.affected_items assert result.render( )['data']['failed_items'][0]['error']['code'] == 1502 finally: os.chmod(os.path.join(test_data_path, 'tests/data/decoders', filename), old_permissions)
def test_get_decoder_file(filename): """Test get file function. Parameters ---------- filename : str Decoder filename """ result = decoder.get_decoder_file(filename=filename) # Assert the result is an AffectedItemsWazuhResult assert isinstance(result, AffectedItemsWazuhResult) assert result.affected_items assert not result.failed_items result = decoder.get_decoder_file(filename=filename, raw=True) # Assert the result is a plain text str assert isinstance(result, str)