Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloperezj committed Feb 2, 2024
1 parent 11072a8 commit a1e7ac8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Packs/VirusTotal/Integrations/VirusTotalV3/VirusTotalV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,12 @@ def _get_error_result(client: Client, ioc_id: str, ioc_type: str, message: str)
Common.DBotScore.NONE,
desc,
client.reliability)
return CommandResults(indicator=getattr(Common, common_type)(ioc_id, dbot),
readable_output=desc)
options: dict[str, Common.DBotScore | str] = {'dbot_score': dbot}
if dbot_type == 'FILE':
options[get_hash_type(ioc_id)] = ioc_id
else:
options[dbot_type.lower()] = ioc_id
return CommandResults(indicator=getattr(Common, common_type)(**options), readable_output=desc)


def build_unknown_output(client: Client, ioc_id: str, ioc_type: str) -> CommandResults:
Expand Down
47 changes: 47 additions & 0 deletions Packs/VirusTotal/Integrations/VirusTotalV3/VirusTotalV3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ def test_domain_command(mocker, requests_mock):
assert results[0].execution_metrics is None
assert results[0].outputs == expected_results

mock_response = {'error': {'code': 'NotFoundError'}}
requests_mock.get(f'https://www.virustotal.com/api/v3/domains/testing.com?relationships={domain_relationships}',
json=mock_response)

results = domain_command(
client=client, score_calculator=mocked_score_calculator,
args=demisto.args(), relationships=domain_relationships)

assert results[0].execution_metrics is None
assert results[0].readable_output == 'Domain "testing.com" was not found in VirusTotal'
assert results[0].indicator.dbot_score.score == 0


def test_ip_command(mocker, requests_mock):
"""
Expand Down Expand Up @@ -342,6 +354,19 @@ def test_ip_command(mocker, requests_mock):
assert results[0].execution_metrics is None
assert results[0].outputs == expected_results

mock_response = {'error': {'code': 'NotFoundError'}}
requests_mock.get(f'https://www.virustotal.com/api/v3/ip_addresses/192.168.0.1?relationships={ip_relationships}',
json=mock_response)

results = ip_command(
client=client, score_calculator=mocked_score_calculator,
args=demisto.args(), relationships=ip_relationships,
disable_private_ip_lookup=True)

assert results[0].execution_metrics is None
assert results[0].readable_output == 'IP "192.168.0.1" was not found in VirusTotal'
assert results[0].indicator.dbot_score.score == 0


def test_url_command_success(mocker, requests_mock):
"""
Expand Down Expand Up @@ -383,6 +408,18 @@ def test_url_command_success(mocker, requests_mock):
assert results[0].execution_metrics is None
assert results[0].outputs == expected_results

mock_response = {'error': {'code': 'NotFoundError'}}
requests_mock.get(f'https://www.virustotal.com/api/v3/urls/{encode_url_to_base64(testing_url)}'
f'?relationships={url_relationships}', json=mock_response)

results = url_command(
client=client, score_calculator=mocked_score_calculator,
args=demisto.args(), relationships=url_relationships)

assert results[0].execution_metrics is None
assert results[0].readable_output == f'URL "{testing_url}" was not found in VirusTotal'
assert results[0].indicator.dbot_score.score == 0


def test_private_file_command(mocker, requests_mock):
"""
Expand Down Expand Up @@ -419,3 +456,13 @@ def test_private_file_command(mocker, requests_mock):
assert results[1].execution_metrics == [{'APICallsCount': 1, 'Type': 'Successful'}]
assert results[0].execution_metrics is None
assert results[0].outputs == expected_results

mock_response = {'error': {'code': 'NotFoundError'}}
requests_mock.get(f'https://www.virustotal.com/api/v3/private/files/{sha256}',
json=mock_response)

results = private_file_command(client=client, args=demisto.args())

assert results[0].execution_metrics is None
assert results[0].readable_output == f'File "{sha256}" was not found in VirusTotal'
assert results[0].indicator.dbot_score.score == 0

0 comments on commit a1e7ac8

Please sign in to comment.