예제 #1
0
def test_fetch_incidents_is_already_fetched(mocker):
    """Unit test
    Given
    - fetch incidents command
    - command args
    - command raw response
    When
    - mock the already_fetched and time.
    - mock the Client's send_request.
    Then
    - run the fetch incidents command using the Client
    Validate The length of the results.
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client('tenant', 'server_url', 'username', 'password', 'verify',
                    'proxies')
    mocker.patch.object(client,
                        'list_incidents_request',
                        return_value=RESPONSE_FETCH_INCIDENTS)
    incidents = fetch_incidents(client,
                                fetch_time='1 hour',
                                incident_status='open',
                                max_fetch='50',
                                last_run={
                                    'already_fetched': ['100107'],
                                    'time': "2020-06-07T08:32:41.679579Z"
                                })
    assert len(incidents) == 0
예제 #2
0
def test_module(mocker):
    """
    Given
    - Securonix test module
    When
    - mock the demisto params.
    - mock the Client's generate_token
    - mock the Client's list_workflows_request
    - mock the Client's list_incidents_request
    Then
    - run the test_module command using the Client
    Validate The response is ok.
    """
    from Securonix import test_module as module
    mocker.patch.object(demisto, 'params', return_value={'isFetch': True})
    mocker.patch.object(Client, '_generate_token')
    client = Client('tenant', 'server_url', 'username', 'password', 'verify',
                    'proxies')
    mocker.patch.object(client,
                        'list_workflows_request',
                        return_value=RESPONSE_LIST_WORKFLOWS)
    mocker.patch.object(client,
                        'list_incidents_request',
                        return_value=RESPONSE_LIST_INCIDENT)
    result = module(client)
    assert result == 'ok'
예제 #3
0
def test_fetch_incidents(mocker):
    """Unit test
    Given
    - fetch incidents command
    - command args
    - command raw response
    When
    - mock the Client's send_request.
    Then
    - run the fetch incidents command using the Client
    Validate The length of the results.
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client('tenant', 'server_url', 'username', 'password', 'verify',
                    'proxies')
    mocker.patch.object(client,
                        'list_incidents_request',
                        return_value=RESPONSE_FETCH_INCIDENTS)
    incidents = fetch_incidents(client,
                                fetch_time='1 hour',
                                incident_status='open',
                                max_fetch='50',
                                last_run={})
    assert len(incidents) == 1
    assert incidents[0].get(
        'name') == 'Emails with large File attachments: 100107'
def test_fetch_incidents_with_default_severity(mocker):
    """Unit test
    Given
    - fetch incidents command
    - command args
    - command raw response
    When
    - mock the Client's send_request.
    Then
    - run the fetch incidents command using the Client
    Validate that the severity is high (3)
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client('tenant', 'server_url', 'username', 'password', 'verify',
                    'proxies')
    mocker.patch.object(client,
                        'list_incidents_request',
                        return_value=RESPONSE_FETCH_INCIDENTS)
    incidents = fetch_incidents(client,
                                fetch_time='1 hour',
                                incident_status='open',
                                default_severity='High',
                                max_fetch='50',
                                last_run={})
    assert len(incidents) == 1
    assert incidents[0].get('severity') == 3
예제 #5
0
def test_commands(command, args, response, expected_result, mocker):
    """Unit test for integration commands.
    Integration was build and tested with: SNYPR Version 6.3
    Args:
        command: func name in .py
        args: func args
        response: response as mocked from 'SNYPR 6.3 CU4 Administration Guide'
        expected_result: expected result in demisto
        mocker: mocker object
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client('tenant', 'server_url', 'username', 'password', 'verify', 'proxies')
    mocker.patch.object(client, 'http_request', return_value=response)
    result = command(client, args)
    assert expected_result == result[1]  # entry context is found in the 2nd place in the result of the command