Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS Teams send-notification command bug #32531

Merged
merged 31 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f18857d
fixed a bug in teams where send-notification failed to send messages …
merit-maita Jan 31, 2024
99bd2b8
added rn
merit-maita Jan 31, 2024
d2360cd
updated docker, added unit test
merit-maita Jan 31, 2024
1b72b06
added doc
merit-maita Jan 31, 2024
8a75d23
Merge branch 'master' into teams_bug
merit-maita Jan 31, 2024
c5ec7c6
Merge branch 'master' into teams_bug
merit-maita Jan 31, 2024
17b7d4e
m
merit-maita Jan 31, 2024
c9ff0ee
Merge branch 'master' into teams_bug
merit-maita Feb 4, 2024
bbdd075
added unit test
merit-maita Feb 4, 2024
fe50d50
Merge branch 'master' into teams_bug
merit-maita Feb 5, 2024
dbf8f2a
added unittest in ms teams
merit-maita Feb 6, 2024
ba302cb
uodated the code
merit-maita Feb 6, 2024
ffd30e6
removed comment
merit-maita Feb 6, 2024
72366f8
added test to ms teams ask
merit-maita Feb 6, 2024
113b0ef
fixed tests
merit-maita Feb 6, 2024
1819fbd
removed comment
merit-maita Feb 6, 2024
f85b178
minor doc update
merit-maita Feb 6, 2024
475d72f
Merge branch 'master' into teams_bug
merit-maita Feb 6, 2024
617d22a
update after build failed
merit-maita Feb 6, 2024
0c58d65
Merge branch 'master' into teams_bug
merit-maita Feb 6, 2024
38ac4a3
Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeam…
merit-maita Feb 6, 2024
ea8c8cc
Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeam…
merit-maita Feb 6, 2024
fa503ca
Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeam…
merit-maita Feb 6, 2024
64c2bb9
Update Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeam…
merit-maita Feb 6, 2024
edf356a
Merge remote-tracking branch 'origin/teams_bug' into teams_bug
merit-maita Feb 6, 2024
58de11f
Merge branch 'master' into teams_bug
merit-maita Feb 6, 2024
6ee9379
Apply suggestions from code review
dorschw Feb 6, 2024
eca228c
Merge branch 'master' into teams_bug
merit-maita Feb 6, 2024
bd7500c
updated do
merit-maita Feb 6, 2024
4598672
fixed precommit issues
merit-maita Feb 6, 2024
9127e6a
Merge branch 'master' into teams_bug
merit-maita Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +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<desc>.*?\.)"

MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'}
dorschw marked this conversation as resolved.
Show resolved Hide resolved


class Handler:
@staticmethod
Expand Down Expand Up @@ -502,6 +504,14 @@ def process_mirror_or_unknown_message(message: str) -> dict:
return create_adaptive_card(body)


def is_teams_ask_message(msg: str) -> bool:
try:
message: dict = json.loads(msg)
return set(message.keys()) == MS_TEAMS_ASK_MESSAGE_KEYS
dorschw marked this conversation as resolved.
Show resolved Hide resolved
except json.decoder.JSONDecodeError:
return False


def process_ask_user(message: str) -> dict:
"""
Processes ask user message and creates adaptive card
Expand Down Expand Up @@ -2062,7 +2072,7 @@ def send_message():

if message:
entitlement_match: Match[str] | None = re.search(ENTITLEMENT_REGEX, message)
if entitlement_match:
if entitlement_match and is_teams_ask_message(message):
# In TeamsAsk process
adaptive_card = process_ask_user(message)
conversation = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
category: Messaging and Conferencing

Check failure on line 1 in Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Validation Error DO106

The docker image tag is not the latest numeric tag, please update it. The docker image tag in the yml file is: 1.0.0.86482 The latest docker image tag in docker hub is: 1.0.0.86933 You can check for the most updated version of demisto/teams here: https://hub.docker.com/r/demisto/teams/tags To update the docker image run: demisto-sdk format -ud -i Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams.yml
sectionOrder:
- Connect
- Collect
Expand Down Expand Up @@ -712,7 +712,7 @@
- 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: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,17 @@
assert str(e.value) == result


def test_send_message_with_user(mocker, requests_mock):
@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.
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')
Expand All @@ -475,7 +485,7 @@
'args',
return_value={
'team_member': 'Denzel Washington',
'message': 'MESSAGE'
'message': message
}
)
requests_mock.post(
Expand Down Expand Up @@ -550,7 +560,8 @@
'options': ['yes', 'no', 'maybe'],
'entitlement': '4404dae8-2d45-46bd-85fa-64779c12abe8',
'investigation_id': '72',
'task_id': '23'
'task_id': '23',
'form_type': 'predefined-options'
dorschw marked this conversation as resolved.
Show resolved Hide resolved
}
mocker.patch.object(
demisto,
Expand Down Expand Up @@ -2340,3 +2351,27 @@

proxies, use_ssl = ms_teams.handle_teams_proxy_and_ssl()
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"}

Check failure on line 2357 in Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Ruff (E501)

Packs/MicrosoftTeams/Integrations/MicrosoftTeams/MicrosoftTeams_test.py:2357:131: E501 Line too long (161 > 130 characters)

@pytest.mark.parametrize('message, result', [
(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):
"""
Given:
- input message string
When:
- Running is_teams_ask_message.
Then:
- 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 MicrosoftTeams import is_teams_ask_message

assert is_teams_ask_message(message) == result
7 changes: 7 additions & 0 deletions Packs/MicrosoftTeams/ReleaseNotes/1_4_50.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### 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*.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import json
import pytest

MS_TEAMS_ASK_MESSAGE_KEYS = {'message_text', 'options', 'entitlement', 'investigation_id', 'task_id', 'form_type'}
dorschw marked this conversation as resolved.
Show resolved Hide resolved


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
to have the same keys as the message keys in the MsTeamsAsk script and the test.
"""
if name == 'addEntitlement':
return [
{
Expand All @@ -14,14 +20,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'
Expand Down
2 changes: 1 addition & 1 deletion Packs/MicrosoftTeams/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
Loading