From 8ada1d5c0c7c36735f460aa5176c817bd844a121 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Sun, 11 Jun 2023 14:49:15 +0300 Subject: [PATCH 1/3] fix type --- Packs/RTIR/Integrations/RTIR/RTIR.py | 11 +++++------ Packs/RTIR/Integrations/RTIR/RTIR.yml | 2 +- Packs/RTIR/ReleaseNotes/1_0_15.md | 6 ++++++ Packs/RTIR/pack_metadata.json | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 Packs/RTIR/ReleaseNotes/1_0_15.md diff --git a/Packs/RTIR/Integrations/RTIR/RTIR.py b/Packs/RTIR/Integrations/RTIR/RTIR.py index 98a4c5454392..8cfc85f6cc12 100644 --- a/Packs/RTIR/Integrations/RTIR/RTIR.py +++ b/Packs/RTIR/Integrations/RTIR/RTIR.py @@ -5,6 +5,7 @@ import json import re import urllib3 +import urllib urllib3.disable_warnings() @@ -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) diff --git a/Packs/RTIR/Integrations/RTIR/RTIR.yml b/Packs/RTIR/Integrations/RTIR/RTIR.yml index 298c5f5e0ae4..5fdf4da3c4cb 100644 --- a/Packs/RTIR/Integrations/RTIR/RTIR.yml +++ b/Packs/RTIR/Integrations/RTIR/RTIR.yml @@ -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 diff --git a/Packs/RTIR/ReleaseNotes/1_0_15.md b/Packs/RTIR/ReleaseNotes/1_0_15.md new file mode 100644 index 000000000000..20c1c103111e --- /dev/null +++ b/Packs/RTIR/ReleaseNotes/1_0_15.md @@ -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. \ No newline at end of file diff --git a/Packs/RTIR/pack_metadata.json b/Packs/RTIR/pack_metadata.json index edf441602637..5f84db3a9d28 100644 --- a/Packs/RTIR/pack_metadata.json +++ b/Packs/RTIR/pack_metadata.json @@ -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": "", From b9413bcf85d194f213ed244ed08843e3f0ddcc84 Mon Sep 17 00:00:00 2001 From: samuelFain <65926551+samuelFain@users.noreply.github.com> Date: Sun, 11 Jun 2023 16:26:58 +0300 Subject: [PATCH 2/3] Add UTs for changed add_reply function --- Packs/RTIR/Integrations/RTIR/RTIR_test.py | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Packs/RTIR/Integrations/RTIR/RTIR_test.py b/Packs/RTIR/Integrations/RTIR/RTIR_test.py index 9515bd3ad19b..a9d0378dfa7c 100644 --- a/Packs/RTIR/Integrations/RTIR/RTIR_test.py +++ b/Packs/RTIR/Integrations/RTIR/RTIR_test.py @@ -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') From 20d892185c1327de62c21f5e1085b9529e735144 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Sun, 11 Jun 2023 17:32:34 +0300 Subject: [PATCH 3/3] add credential defaults, improve UT --- Packs/RTIR/Integrations/RTIR/RTIR.py | 4 ++-- Packs/RTIR/Integrations/RTIR/RTIR_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Packs/RTIR/Integrations/RTIR/RTIR.py b/Packs/RTIR/Integrations/RTIR/RTIR.py index 8cfc85f6cc12..904cf93343b9 100644 --- a/Packs/RTIR/Integrations/RTIR/RTIR.py +++ b/Packs/RTIR/Integrations/RTIR/RTIR.py @@ -917,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 diff --git a/Packs/RTIR/Integrations/RTIR/RTIR_test.py b/Packs/RTIR/Integrations/RTIR/RTIR_test.py index a9d0378dfa7c..e23319fbfd61 100644 --- a/Packs/RTIR/Integrations/RTIR/RTIR_test.py +++ b/Packs/RTIR/Integrations/RTIR/RTIR_test.py @@ -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 = """