Skip to content

Commit

Permalink
fix IdentifyAttachedEmail handle None (#32966)
Browse files Browse the repository at this point in the history
* fix IdentifyAttachedEmail handle None

* fix docker

* add coverage

* Bump pack from version CommonScripts to 1.14.0.

---------

Co-authored-by: Content Bot <bot@demisto.com>
  • Loading branch information
2 people authored and maimorag committed Feb 22, 2024
1 parent 9100872 commit 9927758
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
7 changes: 7 additions & 0 deletions 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*.
Expand Up @@ -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:
Expand Down
Expand Up @@ -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
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Expand Up @@ -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": "",
Expand Down

0 comments on commit 9927758

Please sign in to comment.