Skip to content

Commit

Permalink
RTIR: fix add-comment (#27549)
Browse files Browse the repository at this point in the history
* remove more `encode`s

* update image

* Update Packs/RTIR/ReleaseNotes/1_0_16.md

Co-authored-by: yuvalbenshalom <[email protected]>

---------

Co-authored-by: yuvalbenshalom <[email protected]>
  • Loading branch information
dorschw and yuvalbenshalom authored Jun 19, 2023
1 parent ab24b31 commit ffe82fd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
10 changes: 4 additions & 6 deletions Packs/RTIR/Integrations/RTIR/RTIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ def edit_ticket():
content += '\n' + key + value

if arguments_given:
encoded = "content=" + urllib.parse.quote_plus(content.encode('utf-8'))
edited_ticket = edit_ticket_request(ticket_id, encoded)
edited_ticket = edit_ticket_request(ticket_id, f"content={urllib.parse.quote_plus(content)}")
if "200 Ok" in edited_ticket.text:
ticket_context = ({
'ID': ticket_id,
Expand Down Expand Up @@ -815,10 +814,9 @@ def add_comment_attachment(ticket_id, encoded, files_data):

def add_comment():
ticket_id = demisto.args().get('ticket-id')
text = demisto.args().get('text')
content = 'Action: comment\n'
if text:
content += '\nText: ' + text.encode('utf-8')
if text := demisto.args().get('text'):
content += f'\nText: {text}'
attachments = demisto.args().get('attachment', '')
files_data = {}
if attachments:
Expand All @@ -833,7 +831,7 @@ def add_comment():
files_data['attachment_{:d}'.format(i + 1)] = (file_name, open(file['path'], 'rb'))
content += 'Attachment: {}\n'.format(file_name)

encoded = "content=" + urllib.parse.quote_plus(content)
encoded = f"content={urllib.parse.quote_plus(content)}"
if attachments:
files_data.update({'content': (None, content)}) # type: ignore
comment = add_comment_attachment(ticket_id, encoded, files_data)
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.12.62631
dockerimage: demisto/python3:3.10.12.63474
tests:
- RTIR Test
fromversion: 5.0.0
49 changes: 49 additions & 0 deletions Packs/RTIR/Integrations/RTIR/RTIR_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,52 @@ def test_add_reply_fail(mocker):
mocked_demisto_results = mocker.patch('RTIR.return_error')
add_reply()
mocked_demisto_results.assert_called_with('Failed to reply')


def test_add_comment(mocker):
"""
Test adding a comment to an existing ticket to the user.
Given:
- Valid ticket id and text
- Valid response
When:
- Adding a comment
Then:
- Ensure the comment is added sent successfully
"""
from RTIR import add_comment
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_comment_request', return_value=mocked_response)
mocked_demisto_results = mocker.patch.object(demisto, 'results')
add_comment()
mocked_demisto_results.assert_called_with('Added comment to ticket 1234 successfully.')


def test_add_comment_fail(mocker):
"""
Test failure in adding a comment to an existing ticket.
Given:
- Args for a comment
When:
- Getting a failed response
Then:
- Ensure the command fails with an error message.
"""
from RTIR import add_comment
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_comment_request', return_value=mocked_response)
mocked_demisto_results = mocker.patch('RTIR.return_error')
add_comment()
mocked_demisto_results.assert_called_with('Failed to add comment')
7 changes: 7 additions & 0 deletions Packs/RTIR/ReleaseNotes/1_0_16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### RTIR

- Fixed an issue where the commands **rtir-edit-ticket** and **rtir-add-comment** failed to run.
- Updated the Docker image to: *demisto/python3:3.10.12.63474*.
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.15",
"currentVersion": "1.0.16",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit ffe82fd

Please sign in to comment.