예제 #1
0
def test_gra_fetch_users(requests_mock):
    """Unit test
        Given
        - fetch gra users
        - command args page , max
        - command raw response
        When
        - mock the Client's send_request.
        Then
        - run the gra fetch users command using the Client
        Validate the output with mock response
        Validate the output prefix
        Validate key field
    """
    from GuruculGRA import Client, fetch_record_command
    mock_response = util_load_json('test_data/gra-fetch-users.json')
    requests_mock.get('https://test.com/api/users',
                      json=mock_response)
    api_url = '/users'
    params = {'page': 1, 'max': 10}
    client = Client(
        base_url='https://test.com/api',
        verify=False,
        headers={
            'Authentication': 'Bearer some_api_key'
        }
    )
    response = fetch_record_command(client, api_url, 'Gra.Users', 'employeeId', params)
    assert response.outputs == mock_response
    assert response.outputs_prefix == 'Gra.Users'
    assert response.outputs_key_field == 'employeeId'
예제 #2
0
def test_gra_fetch_resource_orphan_accounts(requests_mock):
    """Unit test
        Given
        - fetch orphan accounts for resource
        - command args page, max, resource
        - command raw response
        When
        - mock the Client's send_request.
        Then
        - run the gra fetch users command using the Client
        Validate the output with mock response
        Validate the output prefix
        Validate key field
    """
    from GuruculGRA import Client, fetch_record_command
    mock_response = util_load_json('test_data/gra-fetch-resource-orphan-accounts.json')
    requests_mock.get('https://test.com/api/resources/Linux/accounts/orphan',
                      json=mock_response)
    api_url = '/resources/Linux/accounts/orphan'
    params = {'page': 1, 'max': 10}
    client = Client(
        base_url='https://test.com/api',
        verify=False,
        headers={
            'Authentication': 'Bearer some_api_key'
        }
    )
    response = fetch_record_command(client, api_url, 'Gra.Resource.Orphan.Accounts', 'id', params)
    assert response.outputs == mock_response
    assert response.outputs_prefix == 'Gra.Resource.Orphan.Accounts'
    assert response.outputs_key_field == 'id'
예제 #3
0
def test_gra_investigate_anomaly_summary(requests_mock):
    """Unit test
        Given
        - gra investigate anomaly summary
        - command args page, max
        - command raw response
        When
        - mock the Client's send_request.
        Then
        - run the gra investigate anomaly summary command using the Client
        Validate the output with mock response
        Validate the output prefix
        Validate key field
    """
    from GuruculGRA import Client, fetch_record_command
    mock_response = util_load_json(
        'test_data/gra-investigate-anomaly-summary.json')
    requests_mock.get(
        'https://test.com/api/investigateAnomaly/anomalySummary/ModelName',
        json=mock_response)
    investigateAnomaly_url = '/investigateAnomaly/anomalySummary/ModelName'
    client = Client(base_url='https://test.com/api',
                    verify=False,
                    headers={'Authentication': 'Bearer some_api_key'})
    response = fetch_record_command(client, investigateAnomaly_url,
                                    'Gra.Investigate.Anomaly.Summary',
                                    'modelId', None)
    mock_response_array = []
    mock_response_array.append(mock_response)
    assert response.outputs == mock_response_array
    assert response.outputs_prefix == 'Gra.Investigate.Anomaly.Summary'
    assert response.outputs_key_field == 'modelId'
예제 #4
0
def test_gra_analytical_features_entity_value(requests_mock):
    """Unit test
        Given
        - gra analytical features entity value
        - command args page, max
        - command raw response
        When
        - mock the Client's send_request.
        Then
        - run the gra investigate anomaly summary command using the Client
        Validate the output with mock response
        Validate the output prefix
        Validate key field
    """
    from GuruculGRA import Client, fetch_record_command
    mock_response = util_load_json(
        'test_data/gra-analytical-features-entity-value.json')
    requests_mock.get(
        'https://test.com/api/profile/analyticalFeatures/entityValue',
        json=mock_response)
    investigateAnomaly_url = '/profile/analyticalFeatures/entityValue'
    client = Client(base_url='https://test.com/api',
                    verify=False,
                    headers={'Authentication': 'Bearer some_api_key'})
    response = fetch_record_command(client, investigateAnomaly_url,
                                    'Gra.Analytical.Features.Entity.Value',
                                    'entityID', None)
    mock_response_array = []
    mock_response_array.append(mock_response)
    assert response.outputs == mock_response_array
    assert response.outputs_prefix == 'Gra.Analytical.Features.Entity.Value'
    assert response.outputs_key_field == 'entityID'
예제 #5
0
def test_gra_case_action_anomaly(requests_mock):
    """Unit test
        Given
        - gra case action
        - command args page, max
        - command raw response
        When
        - mock the Client's send_request.
        Then
        - run the gra case action anomaly command using the Client
        Validate the output with mock response
        Validate the output prefix
        Validate key field
    """
    from GuruculGRA import Client, fetch_record_command
    mock_response = util_load_json('test_data/gra-case-action-anomaly.json')
    requests_mock.get('https://test.com/api/cases/closeCaseAnomaly',
                      json=mock_response)
    cases_url = '/cases/closeCaseAnomaly'
    params = {'page': 1, 'max': 10}
    client = Client(base_url='https://test.com/api',
                    verify=False,
                    headers={'Authentication': 'Bearer some_api_key'})
    response = fetch_record_command(client, cases_url,
                                    'Gra.Cases.Action.Anomaly', 'caseId',
                                    params)
    assert response.outputs == mock_response
    assert response.outputs_prefix == 'Gra.Cases.Action.Anomaly'
    assert response.outputs_key_field == 'caseId'