Exemple #1
0
def test_fetch_incidents_with_specific_score(mocker):
    """Unit test
        Given
        - demisto params
        - raw response of the http request
        When
        - mock the http request result while the result is 15 incidents and we only wish to see 5
        Then
        - validate the incidents values, make sure make sure that there are only 5 incidents and that there
         are the oldest
        """
    mocker.patch.object(Client, '_generate_token')
    client = Client(server_url="https://api.cyberark.com/",
                    username="******",
                    password="******",
                    use_ssl=False,
                    proxy=False,
                    max_fetch=10)

    mocker.patch.object(
        Client,
        '_http_request',
        return_value=GET_SECURITY_EVENTS_WITH_15_INCIDENT_RAW_RESPONSE)
    _, incidents = fetch_incidents(client, {},
                                   "3 days",
                                   score="50",
                                   max_fetch="10")
    assert len(incidents) == 3
    assert incidents == INCIDENTS_FILTERED_BY_SCORE
Exemple #2
0
def test_cyberark_pas_commands(command, args, http_response, context, mocker):
    """Unit test
    Given
    - demisto args
    - raw response of the http request
    When
    - mock the http request result
    Then
    - create the context
    - validate the expected_result and the created context
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client(server_url="https://api.cyberark.com/",
                    username="******",
                    password="******",
                    use_ssl=False,
                    proxy=False,
                    max_fetch=50)

    mocker.patch.object(Client, '_http_request', return_value=http_response)

    outputs = command(client, **args)
    results = outputs.to_context()

    assert results.get("EntryContext") == context
Exemple #3
0
def test_fetch_incidents_with_an_incident_that_was_shown_before(mocker):
    """Unit test
        Given
        - demisto params
        - raw response of the http request
        When
        - mock the http request result while one of the incidents was shown in the previous run
        Then
        - validate the incidents values, make sure the event that was shown before is not in
        the incidents again
        """
    mocker.patch.object(Client, '_generate_token')
    client = Client(server_url="https://api.cyberark.com/",
                    username="******",
                    password="******",
                    use_ssl=False,
                    proxy=False,
                    max_fetch=50)

    mocker.patch.object(
        Client,
        '_http_request',
        return_value=GET_SECURITY_EVENTS_WITH_UNNECESSARY_INCIDENT_RAW_RESPONSE
    )
    # the last run dict is the same we would have got if we run the prev test before
    last_run = {
        'time':
        1594573600000,
        'last_event_ids':
        '["5f0b3064e4b0ba4baf5c1113", "5f0b4320e4b0ba4baf5c2b05"]'
    }
    _, incidents = fetch_incidents(client, last_run, "3 days", "0", "1")
    assert incidents == INCIDENTS_AFTER_FETCH
Exemple #4
0
def test_add_safe_member_permissions_validate(mocker, permission_exist):
    """
    Given
    - Permissions.
    When
    - calling *add_safe_member* method.
    Then
    - Validate ManageSafeMembers was set in http body permission list.
    """
    args = ADD_SAFE_MEMBER_ARGS
    mocker.patch.object(Client, '_generate_token')
    client = Client(server_url="https://api.cyberark.com/",
                    username="******",
                    password="******",
                    use_ssl=False,
                    proxy=False,
                    max_fetch=50)
    mock = mocker.patch.object(Client, '_http_request')
    if not permission_exist:
        args.get('permissions').remove('ManageSafeMembers')
    add_safe_member_command(client, **args)
    permissions = mock.call_args[1].get('json_data').get('member').get(
        'Permissions')
    for permission in permissions:
        if 'ManageSafeMembers' in permission.get('Key'):
            assert permission.get('Value') == permission_exist
Exemple #5
0
def test_fetch_incidents(mocker):
    """Unit test
    Given
    - raw response of the http request
    When
    - mock the http request result as 5 results that are sorted from the newest to the oldest
    Then
    - as defined in the demisto params - show only 2, those should be the oldest 2 available
    - validate the incidents values
    """
    mocker.patch.object(Client, '_generate_token')
    client = Client(server_url="https://api.cyberark.com/", username="******", password="******", use_ssl=False,
                    proxy=False, max_fetch=50)

    mocker.patch.object(Client, '_http_request', return_value=GET_SECURITY_EVENTS_RAW_RESPONSE)

    _, incidents = fetch_incidents(client, {}, "3 days", "0", "2")
    assert incidents == INCIDENTS