Ejemplo n.º 1
0
    def test_handle_general_result_doesnt_exist(self, mocker):
        """
        Given
            - response in json format and
            - a path to be returned from the object
        When
            - the json object is well formed
            - the path doesn't exist
        Then
            - raise DemistoException Exception
        """
        with pytest.raises(ValueError):
            json_obj = {
                'IP_LIST_OUTPUT': {
                    'RESPONSE': {
                        'DATETIME': 'sometime',
                        'IP_SET': {
                            'IP': ['1.1.1.1']
                        }
                    }
                }
            }
            path = {'qualys-ip-list': {'json_path': ['IP_SET', 'WHAT']}}
            mocker.patch.object(Qualysv2,
                                'format_and_validate_response',
                                return_value=json_obj)
            mocker.patch.object(Qualysv2, 'COMMANDS_PARSE_AND_OUTPUT_DATA',
                                path)
            dummy_response = requests.Response()

            handle_general_result(dummy_response, 'qualys-ip-list')
Ejemplo n.º 2
0
    def test_handle_general_result_empty_path(self, mocker):
        """
        Given
            - response in json format
            - a path to be returned from the object
        When
            - the json object is formed correctly
            - the path is empty
        Then
            - return the json object without any changes
        """
        json_obj = {
            'IP_LIST_OUTPUT': {
                'RESPONSE': {
                    'DATETIME': 'sometime',
                    'IP_SET': {
                        'IP': ['1.1.1.1']
                    }
                }
            }
        }
        path = {'qualys-ip-list': {'json_path': []}}
        mocker.patch.object(Qualysv2,
                            'format_and_validate_response',
                            return_value=json_obj)
        mocker.patch.object(Qualysv2, 'COMMANDS_PARSE_AND_OUTPUT_DATA', path)
        dummy_response = requests.Response()

        result = handle_general_result(dummy_response, 'qualys-ip-list')
        assert result == json_obj
Ejemplo n.º 3
0
    def test_handle_general_result_path_exists(self, mocker):
        """
        Given
            - response in json format
            - path to a specific field
        When
            - the json object is well formed
            - the path is correct
        Then
            - return the path requested
        """
        json_obj = {
            'IP_LIST_OUTPUT': {
                'RESPONSE': {
                    'DATETIME': 'sometime',
                    'IP_SET': {
                        'IP': ['1.1.1.1']
                    }
                }
            }
        }
        mocker.patch.object(Qualysv2,
                            'format_and_validate_response',
                            return_value=json_obj)
        dummy_response = requests.Response()

        assert handle_general_result(dummy_response, 'qualys-ip-list') == {
            'DATETIME': 'sometime',
            'IP_SET': {
                'IP': ['1.1.1.1']
            }
        }
Ejemplo n.º 4
0
    def test_handle_general_result_none_value(self, mocker):
        """
        Given
            - response in json format
            - a path to be returned from the object
        When
            - the json object is none formed
            - the path doesn't exist
        Then
            - raise DemistoException Exception
        """
        with pytest.raises(ValueError):
            json_obj = None
            path = {'qualys-ip-list': {'json_path': ['IP_SET', 'WHAT']}}
            mocker.patch.object(Qualysv2, 'format_and_validate_response', return_value=json_obj)
            mocker.patch.object(Qualysv2, 'COMMANDS_PARSE_AND_OUTPUT_DATA', path)
            dummy_response = requests.Response()

            handle_general_result(dummy_response, 'qualys-ip-list')
Ejemplo n.º 5
0
def test_handle_general_result_missing_output_builder():
    """
    Given
        - raw xml result
        - command name
        - output builder function
    When
        - output builder is None
    Then
        - raise a TypeError exception, None is not callable, must be provided
    """
    with pytest.raises(TypeError):
        raw_xml_response = '<?xml version="1.0" encoding="UTF-8" ?>'\
                           '<!DOCTYPE SIMPLE_RETURN SYSTEM' \
                           ' "https://qualysapi.qg2.apps.qualys.com/api/2.0/simple_return.dtd">' \
                           '<SIMPLE_RETURN><RESPONSE>' \
                           '<DATETIME>2021-03-24T15:40:23Z</DATETIME>' \
                           '<TEXT>IPs successfully added to Vulnerability Management</TEXT>' \
                           '</RESPONSE></SIMPLE_RETURN>'
        command_name = 'qualys-ip-add'
        handle_general_result(result=raw_xml_response, command_name=command_name, output_builder=None)