Skip to content

Commit

Permalink
Fix RTIR issue (#27360)
Browse files Browse the repository at this point in the history
* fix type

* Add UTs for changed add_reply function

* add credential defaults, improve UT

---------

Co-authored-by: samuelFain <65926551+samuelFain@users.noreply.github.com>
  • Loading branch information
dorschw and samuelFain authored Jun 12, 2023
1 parent b92ff70 commit 40fe9a4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
15 changes: 7 additions & 8 deletions Packs/RTIR/Integrations/RTIR/RTIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import re
import urllib3
import urllib

urllib3.disable_warnings()

Expand Down Expand Up @@ -855,12 +856,10 @@ def add_reply_request(ticket_id, encoded):
def add_reply():
ticket_id = demisto.args().get('ticket-id')
content = 'Action: comment\n'
text = demisto.args().get('text')
if text:
content += '\nText: ' + text.encode('utf-8')
cc = demisto.args().get('cc')
if cc:
content += '\nCc: ' + cc
if (text := demisto.args().get('text')):
content += f'\nText: {text}'
if (cc := demisto.args().get('cc')):
content += f'\nCc: {cc}'
try:
encoded = "content=" + urllib.parse.quote_plus(content)
added_reply = add_reply_request(ticket_id, encoded)
Expand Down Expand Up @@ -918,8 +917,8 @@ def main():
global SERVER, USERNAME, PASSWORD, BASE_URL, USE_SSL, FETCH_PRIORITY, FETCH_STATUS, FETCH_QUEUE, HEADERS, REFERER
SERVER = params.get('server', '')[:-1] if params.get('server', '').endswith(
'/') else params.get('server', '')
USERNAME = params.get('credentials').get('identifier', '')
PASSWORD = params.get('credentials').get('password', '')
USERNAME = params.get('credentials', {}).get('identifier', '')
PASSWORD = params.get('credentials', {}).get('password', '')
BASE_URL = urljoin(SERVER, '/REST/1.0/')
USE_SSL = not params.get('unsecure', False)
FETCH_PRIORITY = int(params.get('fetch_priority', "0")) - 1
Expand Down
2 changes: 1 addition & 1 deletion Packs/RTIR/Integrations/RTIR/RTIR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ script:
script: '-'
type: python
subtype: python3
dockerimage: demisto/python3:3.10.11.54132
dockerimage: demisto/python3:3.10.12.62631
tests:
- RTIR Test
fromversion: 5.0.0
51 changes: 50 additions & 1 deletion Packs/RTIR/Integrations/RTIR/RTIR_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_query_formatting(mocker):

from RTIR import build_search_query
query = build_search_query()
assert not (query.endswith('+OR+') or query.endswith('+AND+'))
assert not query.endswith(('+OR+', '+AND+'))


RAW_HISTORY = """
Expand Down Expand Up @@ -183,3 +183,52 @@ def test_parse_attachment_content():
response = parse_attachment_content('1234', RAW_ATTACHMENT_CONTENT)
expected = 'some multiline\nattachment content'
assert response == expected


def test_add_reply(mocker):
"""
Test sending a reply from an existing ticket to the user.
Given:
- Valid ticket id and text
- Valid response
When:
- Sending a reply to the user
Then:
- Ensure the reply is sent successfully
"""
from RTIR import add_reply
mocker.patch.object(demisto, 'args', return_value={'ticket-id': '1234', 'text': 'some text'})
mocked_response = requests.Response()
mocked_response._content = b'200'
mocked_response.status_code = 200
mocker.patch('RTIR.add_reply_request', return_value=mocked_response)
mocked_demisto_results = mocker.patch.object(demisto, 'results')
add_reply()
mocked_demisto_results.assert_called_with('Replied successfully to ticket 1234.')


def test_add_reply_fail(mocker):
"""
Test failure in sending a reply from an existing ticket to the user.
Given:
- Invalid response
When:
- Sending a reply to the user
Then:
- Ensure the reply fails with an error message.
"""
from RTIR import add_reply
mocker.patch.object(demisto, 'args', return_value={'ticket-id': '1234', 'text': 'some text'})
mocked_response = requests.Response()
mocked_response._content = b'400'
mocked_response.status_code = 400
mocker.patch('RTIR.add_reply_request', return_value=mocked_response)
mocked_demisto_results = mocker.patch('RTIR.return_error')
add_reply()
mocked_demisto_results.assert_called_with('Failed to reply')
6 changes: 6 additions & 0 deletions Packs/RTIR/ReleaseNotes/1_0_15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### RTIR

- Fixed an issue where `!rtir-add-reply` or `!rtir-add-comment` would fail when provided with the `text` argument.
2 changes: 1 addition & 1 deletion Packs/RTIR/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "RTIR",
"description": "Request Tracker for Incident Response is a ticketing system which provides pre-configured queues and workflows designed for incident response teams.",
"support": "xsoar",
"currentVersion": "1.0.14",
"currentVersion": "1.0.15",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 40fe9a4

Please sign in to comment.