Skip to content

Commit

Permalink
Add URL scan test
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloperezj committed May 9, 2024
1 parent 7494820 commit 929e187
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1997,15 +1997,15 @@ def scan_url_command(client: Client, args: dict) -> CommandResults:
f'{INTEGRATION_ENTRY_CONTEXT}.Submission(val.id && val.id === obj.id)': data,
'vtScanID': data.get('id') # BC preservation
}
except DemistoException as ex:
error = ex.res.json().get('error')
except DemistoException as e:
error = e.res.json().get('error')

# Invalid url, probably due to an unknown TLD
if error['code'] == 'InvalidArgumentError':
data = {'url': url, 'id': '', 'error': error['message']}
headers.append('error')
else:
raise
raise e

return CommandResults(
readable_output=tableToMarkdown(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,3 +1053,43 @@ def test_gti_private_analysis_get(mocker, requests_mock):

assert results.execution_metrics is None
assert results.outputs == expected_response


def test_url_scan_command(mocker, requests_mock):
"""
Given:
- A valid URL
When:
- Running the !url-scan command
Then:
- Validate the command results are valid
"""
from GoogleThreatIntelligence import scan_url_command, Client
import CommonServerPython

mocker.patch.object(demisto, 'params', return_value=DEFAULT_PARAMS)
mocker.patch.object(CommonServerPython, 'is_demisto_version_ge', return_value=True)
params = demisto.params()
client = Client(params=params)

url = 'https://www.example.com'
mock_response = {
'data': {
'id': 'random_id',
'url': url,
}
}

mocker.patch.object(demisto, 'args', return_value={'url': url})
requests_mock.post('https://www.virustotal.com/api/v3/urls',
json=mock_response)

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

assert results.execution_metrics is None
assert results.outputs == {
'GoogleThreatIntelligence.Submission(val.id && val.id === obj.id)': mock_response['data'],
'vtScanID': 'random_id',
}

0 comments on commit 929e187

Please sign in to comment.