def test_url_command(mocker, raw_response, expected_ec, expected_relationships): """ Given - A URL. When - Running url_command with the url. Then - Validate that the URL and DBotScore entry context have the proper values. - Validate that the proper relations were created """ mocker.patch.object(client, 'query', side_effect=[raw_response]) command_results = url_command( client, 'http://www.fotoidea.com/sport/4x4_san_ponso/slides/IMG_0068.html/url_list' ) # results is CommandResults list all_context = command_results[0].to_context() context = all_context['EntryContext'] assert sorted(expected_ec) == sorted(context) relations = all_context['Relationships'] assert sorted(expected_relationships) == sorted(relations)
def test_url_command(mocker): """ Given - A url with status code 404. When - Running url_command with the url. Then - Return no matches for the url. """ url = 'http://url2447.staywell.com/asm/unsubscribe/?user_id=275860%5C%5Cu0026data=LeFzS0ZTdINxJN2UMVFvyPotO31n'\ 'Q1cIqvNrOcRqvlAgWpdtwnHcouXXGS0c64jBnTCVM9X4Cd5n0ZizgP78tXM5VB2w0m0DiwLI_J2sI1s09Mb5WlOYhWuCjJ8-lUjUdQ9'\ 'TyxcDuXhHIapoSlpgOzqCddxTLM3cSCW9zRcHfK5b3yO7P0XOFOqG-kZyFOs9LA75fX-yJ-d-2jHzBzeXrFbc9GxWEw1W9yyTUzvCY8'\ 'cirtcm1_CG8NVhvfc5wnattncML1PF6zctl5JVX3kUHZZJoc2uUHbADiLAJ6K3mEHmH4EbS9oEFs10MF8BvT7n' expected_result = 'No matches for URL http://url2447.staywell.com/asm/unsubscribe/?user_id=275860%5C%5Cu0026dat' \ 'a=LeFzS0ZTdINxJN2UMVFvyPotO31nQ1cIqvNrOcRqvlAgWpdtwnHcouXXGS0c64jBnTCVM9X4Cd5n0ZizgP78tXM5VB' \ '2w0m0DiwLI_J2sI1s09Mb5WlOYhWuCjJ8-lUjUdQ9TyxcDuXhHIapoSlpgOzqCddxTLM3cSCW9zRcHfK5b3yO7P0XOFO' \ 'qG-kZyFOs9LA75fX-yJ-d-2jHzBzeXrFbc9GxWEw1W9yyTUzvCY8cirtcm1_CG8NVhvfc5wnattncML1PF6zctl5JVX3' \ 'kUHZZJoc2uUHbADiLAJ6K3mEHmH4EbS9oEFs10MF8BvT7n' mocker.patch.object(client, 'query', return_value=404) command_results = url_command(client, url) assert command_results[0] == expected_result
def test_url_command_uppercase_protocol(requests_mock): """ Given: - URL with uppercase protocol (HTTPS) When: - Running the url command Then: - Ensure the protocol is lowercased """ requests_mock.get('base_url/indicators/url/https://www.google.com/general', json={ 'alexa': 'http://www.alexa.com/siteinfo/google.com', }) res = url_command(client, 'HTTPS://www.google.com') assert res[0].indicator.to_context( )['URL(val.Data && val.Data == obj.Data)'][ 'Data'] == 'https://www.google.com'