From f18857d60d7d43e4e2c877d0a07be87a2c82bcfa Mon Sep 17 00:00:00 2001 From: merit Date: Wed, 31 Jan 2024 11:17:32 +0200 Subject: [PATCH 01/21] fixed a bug in teams where send-notification failed to send messages in GUID format --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 1ecc46067856..0a3775de23a4 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -502,6 +502,14 @@ def process_mirror_or_unknown_message(message: str) -> dict: return create_adaptive_card(body) +def is_json(msg): + try: + json.loads(msg) + except ValueError: + return False + return True + + def process_ask_user(message: str) -> dict: """ Processes ask user message and creates adaptive card @@ -2062,7 +2070,7 @@ def send_message(): if message: entitlement_match: Match[str] | None = re.search(ENTITLEMENT_REGEX, message) - if entitlement_match: + if entitlement_match and is_json(message): # In TeamsAsk process adaptive_card = process_ask_user(message) conversation = { From 99bd2b8289194fd47db952c64858afd699afb1db Mon Sep 17 00:00:00 2001 From: merit Date: Wed, 31 Jan 2024 11:22:49 +0200 Subject: [PATCH 02/21] added rn --- Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md | 6 ++++++ Packs/MicrosoftTeams/pack_metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md diff --git a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md new file mode 100644 index 000000000000..cf698249ef8d --- /dev/null +++ b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md @@ -0,0 +1,6 @@ + +#### Integrations + +##### Microsoft Teams + +- Fixed an issue where ***send-notification*** command failed when a message contains a GUID. diff --git a/Packs/MicrosoftTeams/pack_metadata.json b/Packs/MicrosoftTeams/pack_metadata.json index fe87a795e677..f33c6c004c7d 100644 --- a/Packs/MicrosoftTeams/pack_metadata.json +++ b/Packs/MicrosoftTeams/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Microsoft Teams", "description": "Send messages and notifications to your team members.", "support": "xsoar", - "currentVersion": "1.4.49", + "currentVersion": "1.4.50", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", From d2360cd0d683eddb73de194069f79849890b830b Mon Sep 17 00:00:00 2001 From: merit Date: Wed, 31 Jan 2024 12:15:02 +0200 Subject: [PATCH 03/21] updated docker, added unit test --- .../Integrations/MicrosoftTeams/MicrosoftTeams.yml | 2 +- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 8 +++++--- Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml index 894b09384c8c..f158d31fe4fc 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml @@ -712,7 +712,7 @@ script: - description: Generate the login url used for Authorization code flow. name: microsoft-teams-generate-login-url arguments: [] - dockerimage: demisto/teams:1.0.0.85097 + dockerimage: demisto/teams:1.0.0.86482 longRunning: true longRunningPort: true script: '' diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index b9ed964dca2a..b9a58d3b1f2d 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -464,7 +464,9 @@ def test_send_message_raising_errors(mocker, args, result): assert str(e.value) == result -def test_send_message_with_user(mocker, requests_mock): +@pytest.mark.parametrize('message, result', [('MESSAGE', 'Message was sent successfully.'), + ('891f1e9d-b8c3-4e24-bfbb-c44bcca4d586', 'Message was sent successfully.')]) +def test_send_message_with_user(mocker, requests_mock, message, result): # verify message is sent properly given user to send to from MicrosoftTeams import send_message mocker.patch.object(demisto, 'results') @@ -475,7 +477,7 @@ def test_send_message_with_user(mocker, requests_mock): 'args', return_value={ 'team_member': 'Denzel Washington', - 'message': 'MESSAGE' + 'message': message } ) requests_mock.post( @@ -506,7 +508,7 @@ def test_send_message_with_user(mocker, requests_mock): assert requests_mock.request_history[0].json() == expected_create_personal_conversation_data results = demisto.results.call_args[0] assert len(results) == 1 - assert results[0] == 'Message was sent successfully.' + assert results[0] == result def test_send_message_with_channel(mocker, requests_mock): diff --git a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md index cf698249ef8d..b5cab0d78e9e 100644 --- a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md +++ b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md @@ -4,3 +4,4 @@ ##### Microsoft Teams - Fixed an issue where ***send-notification*** command failed when a message contains a GUID. +- Updated the Docker image to *demisto/teams:1.0.0.86482*. \ No newline at end of file From 1b72b068c258c3fa2d0c8f64dd43796a88d8da9d Mon Sep 17 00:00:00 2001 From: merit Date: Wed, 31 Jan 2024 12:17:23 +0200 Subject: [PATCH 04/21] added doc --- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index b9a58d3b1f2d..8285301bc7cd 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -467,6 +467,14 @@ def test_send_message_raising_errors(mocker, args, result): @pytest.mark.parametrize('message, result', [('MESSAGE', 'Message was sent successfully.'), ('891f1e9d-b8c3-4e24-bfbb-c44bcca4d586', 'Message was sent successfully.')]) def test_send_message_with_user(mocker, requests_mock, message, result): + """ + Given: + - a message as a basic string and a message that contains GUID. + When: + - running send message function. + Then: + - The message is sent successfully in both cases. + """ # verify message is sent properly given user to send to from MicrosoftTeams import send_message mocker.patch.object(demisto, 'results') From 17b7d4e3199aaab1e32e864ffc8339772cd16761 Mon Sep 17 00:00:00 2001 From: merit Date: Thu, 1 Feb 2024 00:52:11 +0200 Subject: [PATCH 05/21] m --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 0a3775de23a4..7bc716efb736 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -502,7 +502,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: return create_adaptive_card(body) -def is_json(msg): +def is_json(msg: str) -> bool: try: json.loads(msg) except ValueError: From bbdd075bc506a52d714c4cd3a66892811fc50598 Mon Sep 17 00:00:00 2001 From: merit Date: Sun, 4 Feb 2024 20:00:51 +0200 Subject: [PATCH 06/21] added unit test --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 +- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 8 ++++---- Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 7bc716efb736..f1da66b96d97 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -505,7 +505,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: def is_json(msg: str) -> bool: try: json.loads(msg) - except ValueError: + except json.decoder.JSONDecodeError: return False return True diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index 8285301bc7cd..c3a140083240 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -464,9 +464,9 @@ def test_send_message_raising_errors(mocker, args, result): assert str(e.value) == result -@pytest.mark.parametrize('message, result', [('MESSAGE', 'Message was sent successfully.'), - ('891f1e9d-b8c3-4e24-bfbb-c44bcca4d586', 'Message was sent successfully.')]) -def test_send_message_with_user(mocker, requests_mock, message, result): +@pytest.mark.parametrize('message', ['MESSAGE', '891f1e9d-b8c3-4e24-bfbb-c44bcca4d586', + 'testing 891f1e9d-b8c3-4e24-bfbb-c44bcca4d586 testing']) +def test_send_message_with_user(mocker, requests_mock, message): """ Given: - a message as a basic string and a message that contains GUID. @@ -516,7 +516,7 @@ def test_send_message_with_user(mocker, requests_mock, message, result): assert requests_mock.request_history[0].json() == expected_create_personal_conversation_data results = demisto.results.call_args[0] assert len(results) == 1 - assert results[0] == result + assert results[0] == 'Message was sent successfully.' def test_send_message_with_channel(mocker, requests_mock): diff --git a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md index b5cab0d78e9e..508e12248479 100644 --- a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md +++ b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md @@ -3,5 +3,5 @@ ##### Microsoft Teams -- Fixed an issue where ***send-notification*** command failed when a message contains a GUID. +- Fixed an issue where ***send-notification*** failed on messages containing a GUID. - Updated the Docker image to *demisto/teams:1.0.0.86482*. \ No newline at end of file From dbf8f2a6e49923d1facd7c4eb524490b9f9d5886 Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:12:10 +0200 Subject: [PATCH 07/21] added unittest in ms teams --- .../MicrosoftTeams/MicrosoftTeams.py | 8 +++--- .../MicrosoftTeams/MicrosoftTeams_test.py | 27 +++++++++++++++++++ .../MicrosoftTeamsAsk_test.py | 3 +++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index f1da66b96d97..1ff285f65b52 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -103,6 +103,7 @@ class FormType(Enum): # Used for 'send-message', and by the MicrosoftTeamsAsk s TOKEN_EXPIRED_ERROR_CODES = {50173, 700082, } # See: https://login.microsoftonline.com/error?code= REGEX_SEARCH_ERROR_DESC = r"^[^:]*:\s(?P.*?\.)" +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} class Handler: @staticmethod @@ -502,13 +503,12 @@ def process_mirror_or_unknown_message(message: str) -> dict: return create_adaptive_card(body) -def is_json(msg: str) -> bool: +def is_teams_ask_message(msg: str) -> bool: # is_teams_ask_message (add unit test, to update with the test in ask test) try: - json.loads(msg) + message: dict = json.loads(msg) + return MS_TEAMS_ASK_MESSAGE_KEYS == message.keys() except json.decoder.JSONDecodeError: return False - return True - def process_ask_user(message: str) -> dict: """ diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index c3a140083240..28b042018b1b 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2350,3 +2350,30 @@ def test_handle_teams_proxy_and_ssl(mocker, is_xsoar_8, expected_result): proxies, use_ssl = ms_teams.handle_teams_proxy_and_ssl() assert (proxies, use_ssl) == expected_result + + +@pytest.mark.parametrize('message, result', [ + ('{"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task", ' + '"form_type": "form"}', True), + ('{"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task",' + ' "form_type": "form", "extra_key": "extra"}', False), + ("non json message", False) +]) +def test_is_teams_ask_message(message, result): + """ + Given: + - A message in json format that has the exact same keys as ms teams ask card keys. + - A message in json format that has all ms teams ask card keys and an extra key. + - A message that's not json format. + When: + - Running is_teams_ask_message. + Then: + - Assert that the message is a legit ms teams ask message (from ms teams ask script flow). + - Assert that the message is not a message from ms teams ask script. + - Assert that the message is not a message from ms teams ask script. + If the test fails, please update the MS_TEAMS_ASK_MESSAGE_KEYS constant in MicrosoftTeams, and update the is_valid_card_keys + test in MsTeamsAsk script. + """ + from MicrosoftTeams import is_teams_ask_message + + assert is_teams_ask_message(message) == result diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index 87898260f9cf..5086f6dd0376 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -82,3 +82,6 @@ def test_microsoft_teams_ask(mocker): ) main() assert demisto.executeCommand.call_count == 2 + + +# todo: add test to validate the message stucture is the same all dict keys, describe why, and point to teams integration to update accordingly wih the keys \ No newline at end of file From ba302cbe338e59aa5ecb4e3fd2b0d421823b32bc Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:12:43 +0200 Subject: [PATCH 08/21] uodated the code --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 1ff285f65b52..3e9aa1e451dd 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -2070,7 +2070,7 @@ def send_message(): if message: entitlement_match: Match[str] | None = re.search(ENTITLEMENT_REGEX, message) - if entitlement_match and is_json(message): + if entitlement_match and is_teams_ask_message(message): # In TeamsAsk process adaptive_card = process_ask_user(message) conversation = { From ffd30e6a57a17c1a6331cf7944df53a56a9c7ec3 Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:13:02 +0200 Subject: [PATCH 09/21] removed comment --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 3e9aa1e451dd..8a6ab4638374 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -503,7 +503,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: return create_adaptive_card(body) -def is_teams_ask_message(msg: str) -> bool: # is_teams_ask_message (add unit test, to update with the test in ask test) +def is_teams_ask_message(msg: str) -> bool: try: message: dict = json.loads(msg) return MS_TEAMS_ASK_MESSAGE_KEYS == message.keys() From 72366f80e82339ca6c3d6a07128a21bd99313523 Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:44:05 +0200 Subject: [PATCH 10/21] added test to ms teams ask --- .../MicrosoftTeams/MicrosoftTeams_test.py | 4 ++-- .../MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index 28b042018b1b..1694d214b9dc 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2371,8 +2371,8 @@ def test_is_teams_ask_message(message, result): - Assert that the message is a legit ms teams ask message (from ms teams ask script flow). - Assert that the message is not a message from ms teams ask script. - Assert that the message is not a message from ms teams ask script. - If the test fails, please update the MS_TEAMS_ASK_MESSAGE_KEYS constant in MicrosoftTeams, and update the is_valid_card_keys - test in MsTeamsAsk script. + If the test fails, please update the first message param in the test to have the same keys as MS_TEAMS_ASK_MESSAGE_KEYS + constant in MicrosoftTeams. """ from MicrosoftTeams import is_teams_ask_message diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index 5086f6dd0376..c3affea86a73 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -3,9 +3,14 @@ import demistomock as demisto import json import pytest +from Packs.MicrosoftTeams.Integrations.MicrosoftTeams.MicrosoftTeams import MS_TEAMS_ASK_MESSAGE_KEYS def execute_command(name, args=None): + """ + if assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() test fails, update the MS_TEAMS_ASK_MESSAGE_KEYS constant in + MicrosoftTeams to have the same keys as the message keys in the test. + """ if name == 'addEntitlement': return [ { @@ -14,14 +19,16 @@ def execute_command(name, args=None): } ] elif name == 'send-notification': - expected_message: str = json.dumps({ + json_message = { 'message_text': 'How are you today?', 'options': ['Great', 'Wonderful', 'SSDD', 'Wooah'], 'entitlement': '4404dae8-2d45-46bd-85fa-64779c12abe8', 'investigation_id': '32', 'task_id': '44', - 'form_type': 'predefined-options', - }) + 'form_type': 'predefined-options'} + + expected_message: str = json.dumps(json_message) + assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() expected_script_arguments: dict = { 'message': expected_message, 'using-brand': 'Microsoft Teams' From 113b0ef2f8cfad4ddbecc16ba331896334ffe4a0 Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:56:45 +0200 Subject: [PATCH 11/21] fixed tests --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 ++ .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 8a6ab4638374..fb9ed34ae3b5 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -105,6 +105,7 @@ class FormType(Enum): # Used for 'send-message', and by the MicrosoftTeamsAsk s MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} + class Handler: @staticmethod def write(msg: str): @@ -510,6 +511,7 @@ def is_teams_ask_message(msg: str) -> bool: except json.decoder.JSONDecodeError: return False + def process_ask_user(message: str) -> dict: """ Processes ask user message and creates adaptive card diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index 1694d214b9dc..b9dca178f7ee 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -560,7 +560,8 @@ def test_send_message_with_entitlement(mocker, requests_mock): 'options': ['yes', 'no', 'maybe'], 'entitlement': '4404dae8-2d45-46bd-85fa-64779c12abe8', 'investigation_id': '72', - 'task_id': '23' + 'task_id': '23', + 'form_type': 'predefined-options' } mocker.patch.object( demisto, From 1819fbd854e9ce717774151cd41fc4147feb74d7 Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 12:59:12 +0200 Subject: [PATCH 12/21] removed comment --- .../Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index c3affea86a73..f01718cc32df 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -89,6 +89,3 @@ def test_microsoft_teams_ask(mocker): ) main() assert demisto.executeCommand.call_count == 2 - - -# todo: add test to validate the message stucture is the same all dict keys, describe why, and point to teams integration to update accordingly wih the keys \ No newline at end of file From f85b1789d89f3128861445ea3f7a09a52d8659af Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 13:00:05 +0200 Subject: [PATCH 13/21] minor doc update --- .../Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index f01718cc32df..170f012db5c9 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -9,7 +9,7 @@ def execute_command(name, args=None): """ if assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() test fails, update the MS_TEAMS_ASK_MESSAGE_KEYS constant in - MicrosoftTeams to have the same keys as the message keys in the test. + MicrosoftTeams to have the same keys as the message keys in the MsTeamsAsk script and the test. """ if name == 'addEntitlement': return [ From 617d22a75ae2de910a5e9d1952f6c88b6275070e Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 14:10:33 +0200 Subject: [PATCH 14/21] update after build failed --- .../Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index 170f012db5c9..de605b3fb236 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -3,13 +3,14 @@ import demistomock as demisto import json import pytest -from Packs.MicrosoftTeams.Integrations.MicrosoftTeams.MicrosoftTeams import MS_TEAMS_ASK_MESSAGE_KEYS + +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} def execute_command(name, args=None): """ - if assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() test fails, update the MS_TEAMS_ASK_MESSAGE_KEYS constant in - MicrosoftTeams to have the same keys as the message keys in the MsTeamsAsk script and the test. + if assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() test fails, update the MS_TEAMS_ASK_MESSAGE_KEYS constant + to have the same keys as the message keys in the MsTeamsAsk script and the test. """ if name == 'addEntitlement': return [ From 38ac4a32a33c7502e83277e2a80d560dbf8bf8f1 Mon Sep 17 00:00:00 2001 From: merit-maita <49760643+merit-maita@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:12:38 +0200 Subject: [PATCH 15/21] Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com> --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index fb9ed34ae3b5..406a63afaf6d 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -507,7 +507,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: def is_teams_ask_message(msg: str) -> bool: try: message: dict = json.loads(msg) - return MS_TEAMS_ASK_MESSAGE_KEYS == message.keys() + return set(message.keys()) == MS_TEAMS_ASK_MESSAGE_KEYS except json.decoder.JSONDecodeError: return False From ea8c8ccdf089f8a9991e28bee95a9eb1fec87b96 Mon Sep 17 00:00:00 2001 From: merit-maita <49760643+merit-maita@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:14:11 +0200 Subject: [PATCH 16/21] Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com> --- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index b9dca178f7ee..f54364d5cc75 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2353,11 +2353,12 @@ def test_handle_teams_proxy_and_ssl(mocker, is_xsoar_8, expected_result): assert (proxies, use_ssl) == expected_result + +DUMMY_ASK_MESSAGE = {"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task", "form_type": "form"} + @pytest.mark.parametrize('message, result', [ - ('{"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task", ' - '"form_type": "form"}', True), - ('{"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task",' - ' "form_type": "form", "extra_key": "extra"}', False), + (json.dumps(DUMMY_ASK_MESSAGE), True), + (json.dumps(DUMMY_ASK_MESSAGE | {"extra_key": "extra"}), False), ("non json message", False) ]) def test_is_teams_ask_message(message, result): From fa503cadb6f3918d6aac893582ebecd746074502 Mon Sep 17 00:00:00 2001 From: merit-maita <49760643+merit-maita@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:14:21 +0200 Subject: [PATCH 17/21] Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com> --- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index f54364d5cc75..75df9c5e598e 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2364,9 +2364,7 @@ def test_handle_teams_proxy_and_ssl(mocker, is_xsoar_8, expected_result): def test_is_teams_ask_message(message, result): """ Given: - - A message in json format that has the exact same keys as ms teams ask card keys. - - A message in json format that has all ms teams ask card keys and an extra key. - - A message that's not json format. + - input message string When: - Running is_teams_ask_message. Then: From 64c2bb9e8d2a48a80dda33b8d3f5f7b5ddb96c12 Mon Sep 17 00:00:00 2001 From: merit-maita <49760643+merit-maita@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:14:37 +0200 Subject: [PATCH 18/21] Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com> --- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index 75df9c5e598e..a7556d1107ff 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2368,9 +2368,7 @@ def test_is_teams_ask_message(message, result): When: - Running is_teams_ask_message. Then: - - Assert that the message is a legit ms teams ask message (from ms teams ask script flow). - - Assert that the message is not a message from ms teams ask script. - - Assert that the message is not a message from ms teams ask script. + - Assert only ask_teams messages return True If the test fails, please update the first message param in the test to have the same keys as MS_TEAMS_ASK_MESSAGE_KEYS constant in MicrosoftTeams. """ From 6ee937978cb973558e9e9b4eb2faba7c13625106 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:38:11 +0200 Subject: [PATCH 19/21] Apply suggestions from code review --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 4 ++-- .../Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index 406a63afaf6d..e2aa7e3c9459 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -103,7 +103,7 @@ class FormType(Enum): # Used for 'send-message', and by the MicrosoftTeamsAsk s TOKEN_EXPIRED_ERROR_CODES = {50173, 700082, } # See: https://login.microsoftonline.com/error?code= REGEX_SEARCH_ERROR_DESC = r"^[^:]*:\s(?P.*?\.)" -MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} # must be synced with ones in TeamsAsk class Handler: @@ -507,7 +507,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: def is_teams_ask_message(msg: str) -> bool: try: message: dict = json.loads(msg) - return set(message.keys()) == MS_TEAMS_ASK_MESSAGE_KEYS + return message.keys() == MS_TEAMS_ASK_MESSAGE_KEYS except json.decoder.JSONDecodeError: return False diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index de605b3fb236..71dce93ae385 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -4,7 +4,7 @@ import json import pytest -MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} # must be synced with ones in MicrosoftTeams.py def execute_command(name, args=None): From bd7500c5b8d3441b0a9254594c3a9077b5cc8bcf Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 17:29:15 +0200 Subject: [PATCH 20/21] updated do --- .../Integrations/MicrosoftTeams/MicrosoftTeams.yml | 2 +- Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml index f158d31fe4fc..3ed5b29a5b2e 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml @@ -712,7 +712,7 @@ script: - description: Generate the login url used for Authorization code flow. name: microsoft-teams-generate-login-url arguments: [] - dockerimage: demisto/teams:1.0.0.86482 + dockerimage: demisto/teams:1.0.0.86933 longRunning: true longRunningPort: true script: '' diff --git a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md index 508e12248479..d6227b11d92f 100644 --- a/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md +++ b/Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md @@ -4,4 +4,4 @@ ##### Microsoft Teams - Fixed an issue where ***send-notification*** failed on messages containing a GUID. -- Updated the Docker image to *demisto/teams:1.0.0.86482*. \ No newline at end of file +- Updated the Docker image to *demisto/teams:1.0.0.86933*. \ No newline at end of file From 4598672820bdf3de4cff263ae60ed841120ca8fb Mon Sep 17 00:00:00 2001 From: merit Date: Tue, 6 Feb 2024 19:00:59 +0200 Subject: [PATCH 21/21] fixed precommit issues --- .../Integrations/MicrosoftTeams/MicrosoftTeams.py | 5 +++-- .../Integrations/MicrosoftTeams/MicrosoftTeams_test.py | 3 ++- .../Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py index e2aa7e3c9459..e4e3a1483341 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.py @@ -103,7 +103,8 @@ class FormType(Enum): # Used for 'send-message', and by the MicrosoftTeamsAsk s TOKEN_EXPIRED_ERROR_CODES = {50173, 700082, } # See: https://login.microsoftonline.com/error?code= REGEX_SEARCH_ERROR_DESC = r"^[^:]*:\s(?P.*?\.)" -MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} # must be synced with ones in TeamsAsk +# must be synced with ones in TeamsAsk +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} class Handler: @@ -507,7 +508,7 @@ def process_mirror_or_unknown_message(message: str) -> dict: def is_teams_ask_message(msg: str) -> bool: try: message: dict = json.loads(msg) - return message.keys() == MS_TEAMS_ASK_MESSAGE_KEYS + return message.keys() == MS_TEAMS_ASK_MESSAGE_KEYS except json.decoder.JSONDecodeError: return False diff --git a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py index a7556d1107ff..21d8c3fc1e65 100644 --- a/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py +++ b/Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py @@ -2353,8 +2353,9 @@ def test_handle_teams_proxy_and_ssl(mocker, is_xsoar_8, expected_result): assert (proxies, use_ssl) == expected_result +DUMMY_ASK_MESSAGE = {"message_text": "message", "options": [ + "option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task", "form_type": "form"} -DUMMY_ASK_MESSAGE = {"message_text": "message", "options": ["option"], "entitlement": "id", "investigation_id": "inv_id", "task_id": "task", "form_type": "form"} @pytest.mark.parametrize('message, result', [ (json.dumps(DUMMY_ASK_MESSAGE), True), diff --git a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py index 71dce93ae385..bba7494029e7 100644 --- a/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py +++ b/Packs/MicrosoftTeams/Scripts/MicrosoftTeamsAsk/MicrosoftTeamsAsk_test.py @@ -4,7 +4,8 @@ import json import pytest -MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'} # must be synced with ones in MicrosoftTeams.py +MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', + 'task_id', 'form_type'} # must be synced with ones in MicrosoftTeams.py def execute_command(name, args=None): @@ -29,7 +30,7 @@ def execute_command(name, args=None): 'form_type': 'predefined-options'} expected_message: str = json.dumps(json_message) - assert MS_TEAMS_ASK_MESSAGE_KEYS == json_message.keys() + assert json_message.keys() == MS_TEAMS_ASK_MESSAGE_KEYS expected_script_arguments: dict = { 'message': expected_message, 'using-brand': 'Microsoft Teams' @@ -41,8 +42,9 @@ def execute_command(name, args=None): if 'team' in args: expected_script_arguments['team'] = 'TestTeam' assert args == expected_script_arguments + return None else: - raise ValueError('Unimplemented command called: {}'.format(name)) + raise ValueError(f'Unimplemented command called: {name}') def test_microsoft_teams_ask(mocker):