def test_domain(requests_mock): from HelloWorld import Client, domain_reputation_command mock_response = util_load_json('test_data/domain_reputation.json') requests_mock.get('http://test.com/api/v1/domain?domain=google.com', json=mock_response) client = Client( base_url='http://test.com/api/v1', verify=False, headers={ 'Authorization': 'Bearer some_api_key' } ) args = { 'domain': "google.com", 'threshold': 65, } _, outputs, _ = domain_reputation_command(client, args, 65) assert outputs['HelloWorld.Domain(val.domain == obj.domain)'] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][0] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][0] == mock_response
def test_domain(requests_mock): """Tests the domain reputation command function. Configures requests_mock instance to generate the appropriate domain reputation API response, loaded from a local JSON file. Checks the output of the command function with the expected output. """ from HelloWorld import Client, domain_reputation_command mock_response = util_load_json('test_data/domain_reputation.json') requests_mock.get('http://test.com/api/v1/domain?domain=google.com', json=mock_response) client = Client(base_url='http://test.com/api/v1', verify=False, headers={'Authorization': 'Bearer some_api_key'}) args = { 'domain': "google.com", 'threshold': 65, } _, outputs, _ = domain_reputation_command(client, args, 65) assert outputs['HelloWorld.Domain(val.domain == obj.domain)'] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][0] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][ 0] == mock_response
def test_domain(requests_mock): """Tests the domain reputation command function. Configures requests_mock instance to generate the appropriate domain reputation API response, loaded from a local JSON file. Checks the output of the command function with the expected output. """ from CommonServerPython import Common from HelloWorld import Client, domain_reputation_command domain_to_check = 'google.com' mock_response = util_load_json('test_data/domain_reputation.json') requests_mock.get(f'http://test.com/api/v1/domain?domain={domain_to_check}', json=mock_response) client = Client( base_url='http://test.com/api/v1', verify=False, headers={ 'Authorization': 'Bearer some_api_key' } ) args = { 'domain': domain_to_check, 'threshold': 65, } response = domain_reputation_command(client, args, 65) # We modify the timestamps from the raw mock_response of the API, because the # integration changes the format from timestamp to ISO8601. mock_response['expiration_date'] = '2028-09-14T04:00:00.000Z' mock_response['creation_date'] = '1997-09-15T04:00:00.000Z' mock_response['updated_date'] = '2019-09-09T15:39:04.000Z' assert response.outputs[0] == mock_response assert response.outputs_prefix == 'HelloWorld.Domain' assert response.outputs_key_field == 'domain' # This command also returns Common.Domain data assert isinstance(response.indicators, list) assert len(response.indicators) == 1 assert isinstance(response.indicators[0], Common.Domain) assert response.indicators[0].domain == domain_to_check
def test_domain(requests_mock): """Tests the domain reputation command function. Configures requests_mock instance to generate the appropriate domain reputation API response, loaded from a local JSON file. Checks the output of the command function with the expected output. """ from HelloWorld import Client, domain_reputation_command mock_response = util_load_json('test_data/domain_reputation.json') requests_mock.get('http://test.com/api/v1/domain?domain=google.com', json=mock_response) client = Client( base_url='http://test.com/api/v1', verify=False, headers={ 'Authorization': 'Bearer some_api_key' } ) args = { 'domain': 'google.com', 'threshold': 65, } _, outputs, _ = domain_reputation_command(client, args, 65) # We modify the timestamps from the raw mock_response of the API, because the # integration changes the format from timestamp to ISO8601. mock_response['expiration_date'] = '2028-09-14T04:00:00.000Z' mock_response['creation_date'] = '1997-09-15T04:00:00.000Z' mock_response['updated_date'] = '2019-09-09T15:39:04.000Z' assert outputs['HelloWorld.Domain(val.domain == obj.domain)'] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][0] assert outputs['HelloWorld.Domain(val.domain == obj.domain)'][0] == mock_response