From 9927758e06f1a81e6dff663b9fdfab841ad7d481 Mon Sep 17 00:00:00 2001 From: Anar Azadaliyev Date: Sun, 18 Feb 2024 17:55:24 +0200 Subject: [PATCH] fix IdentifyAttachedEmail handle None (#32966) * fix IdentifyAttachedEmail handle None * fix docker * add coverage * Bump pack from version CommonScripts to 1.14.0. --------- Co-authored-by: Content Bot --- Packs/CommonScripts/ReleaseNotes/1_14_0.md | 7 ++ .../IdentifyAttachedEmail.py | 3 + .../IdentifyAttachedEmail.yml | 2 +- .../IdentifyAttachedEmail_test.py | 82 +++++++++++++++++++ Packs/CommonScripts/pack_metadata.json | 2 +- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Packs/CommonScripts/ReleaseNotes/1_14_0.md diff --git a/Packs/CommonScripts/ReleaseNotes/1_14_0.md b/Packs/CommonScripts/ReleaseNotes/1_14_0.md new file mode 100644 index 000000000000..ccc3ebcf8813 --- /dev/null +++ b/Packs/CommonScripts/ReleaseNotes/1_14_0.md @@ -0,0 +1,7 @@ + +#### Scripts + +##### IdentifyAttachedEmail + +- Fixed an issue where the script was erroring when there were no File entries in the warroom. +- Updated the Docker image to: *demisto/python3:3.10.13.87159*. diff --git a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.py b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.py index a47585fae16e..307c6de93ab0 100644 --- a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.py +++ b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.py @@ -66,6 +66,9 @@ def identify_attached_mail(args): else: entries = demisto.executeCommand('getEntries', {"filter": {"categories": ["attachments"]}}) + if not entries: + return 'no', None + for e in entries: id = is_entry_email(e) if id: diff --git a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.yml b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.yml index dbb7afd937ce..8f1db8a80336 100644 --- a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.yml +++ b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail.yml @@ -28,4 +28,4 @@ tests: - Process Email - Generic - Test - Incident Starter - Phishing v2 - Test - Incident Starter fromversion: 5.0.0 -dockerimage: demisto/python3:3.10.13.86272 +dockerimage: demisto/python3:3.10.13.87159 diff --git a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail_test.py b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail_test.py index df84b466f8db..ece17fa892c4 100644 --- a/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail_test.py +++ b/Packs/CommonScripts/Scripts/IdentifyAttachedEmail/IdentifyAttachedEmail_test.py @@ -166,3 +166,85 @@ def execute_command(command, args): results = identify_attached_mail({}) assert results == ('yes', {'reportedemailentryid': '23@2'}) + + +def test_identify_attached_mail_no_email_found(mocker): + """ + Given + - no email entries in the warroom + - the platform is xsoar saas + + When + - running the script to get the entries + + Then + - no entries to be found + + """ + import CommonServerPython + mocker.patch.object(CommonServerPython, 'get_demisto_version', return_value={ + 'version': '8.2.0', + 'buildNumber': '12345' + }) + + def execute_command(command, args): + if command == 'getEntries' and args == {"filter": {"categories": ["attachments"]}}: + return + else: + pytest.fail() + + mocker.patch.object(demisto, 'executeCommand', side_effect=execute_command) + + results = identify_attached_mail({}) + assert results == ('no', None) + + +def test_list_of_entries_passed_in_xsoar_saas_but_no_file_entries(mocker): + """ + Given + - two entries with ids 23@2 24@2 which are not file entries + - the platform is xsoar saas + + When + - running the script to get the entries + + Then + - expect the getEntriesByIDs to be called + - expect no email entries to be found + + """ + entry_ids = """[\"23@2\",\"24@2\"]""" + import CommonServerPython + mocker.patch.object(CommonServerPython, 'get_demisto_version', return_value={ + 'version': '8.2.0', + 'buildNumber': '12345' + }) + + def execute_command(command, args): + if command == 'getEntriesByIDs' and args.get('entryIDs') == '23@2,24@2': + return [ + { + 'File': 'msg.txt', + 'FileMetadata': { + 'info': 'ASCII text, with CRLF line terminators' + }, + 'ID': '23@2' + }, + { + 'File': 'foo.txt', + 'FileMetadata': { + 'info': 'ASCII text, with CRLF line terminators' + }, + 'ID': '24@2' + } + ] + else: + pytest.fail() + + mocker.patch.object(demisto, 'executeCommand', side_effect=execute_command) + + args = { + 'entryid': entry_ids + } + results = identify_attached_mail(args) + assert results == ('no', None) diff --git a/Packs/CommonScripts/pack_metadata.json b/Packs/CommonScripts/pack_metadata.json index ef668157d2b1..293d37cc7cee 100644 --- a/Packs/CommonScripts/pack_metadata.json +++ b/Packs/CommonScripts/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Common Scripts", "description": "Frequently used scripts pack.", "support": "xsoar", - "currentVersion": "1.13.40", + "currentVersion": "1.14.0", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",