diff --git a/tests/test_fixture_replay.py b/tests/test_fixture_replay.py index 3b28bdfd..076788ae 100644 --- a/tests/test_fixture_replay.py +++ b/tests/test_fixture_replay.py @@ -15,6 +15,7 @@ import hashlib import hmac +import inspect import json import time from typing import Any @@ -137,8 +138,20 @@ def _teams_skip_auth(): real_initialize = HttpServer.initialize - def _initialize_skip_auth(self, credentials=None, skip_auth=False, cloud=None): - return real_initialize(self, credentials=credentials, skip_auth=True, cloud=cloud) + # microsoft-teams-apps 2.0.14+ renamed the SDK's ``skip_auth`` flag to + # ``dangerously_allow_unauthenticated_requests``; force whichever flag this + # version has and forward everything else untouched (the SDK calls + # ``initialize`` with keywords only). + skip_flag = ( + "dangerously_allow_unauthenticated_requests" + if "dangerously_allow_unauthenticated_requests" in inspect.signature(real_initialize).parameters + else "skip_auth" + ) + + def _initialize_skip_auth(self, *args, **kwargs): + kwargs.pop("skip_auth", None) + kwargs.pop("dangerously_allow_unauthenticated_requests", None) + return real_initialize(self, *args, **{**kwargs, skip_flag: True}) return patch.object(HttpServer, "initialize", _initialize_skip_auth) diff --git a/tests/test_teams_adapter.py b/tests/test_teams_adapter.py index a70da72e..9f33190b 100644 --- a/tests/test_teams_adapter.py +++ b/tests/test_teams_adapter.py @@ -5,6 +5,7 @@ from __future__ import annotations +import inspect import re from datetime import datetime, timezone from unittest.mock import AsyncMock, MagicMock @@ -817,8 +818,20 @@ def _skip_jwt(self, monkeypatch): real_initialize = HttpServer.initialize - def _initialize_skip_auth(self, credentials=None, skip_auth=False, cloud=None): - return real_initialize(self, credentials=credentials, skip_auth=True, cloud=cloud) + # microsoft-teams-apps 2.0.14+ renamed the SDK's ``skip_auth`` flag to + # ``dangerously_allow_unauthenticated_requests``; force whichever flag this + # version has and forward everything else untouched (the SDK calls + # ``initialize`` with keywords only). + skip_flag = ( + "dangerously_allow_unauthenticated_requests" + if "dangerously_allow_unauthenticated_requests" in inspect.signature(real_initialize).parameters + else "skip_auth" + ) + + def _initialize_skip_auth(self, *args, **kwargs): + kwargs.pop("skip_auth", None) + kwargs.pop("dangerously_allow_unauthenticated_requests", None) + return real_initialize(self, *args, **{**kwargs, skip_flag: True}) monkeypatch.setattr(HttpServer, "initialize", _initialize_skip_auth) diff --git a/tests/test_teams_coverage.py b/tests/test_teams_coverage.py index 71675c5e..d6cfb89a 100644 --- a/tests/test_teams_coverage.py +++ b/tests/test_teams_coverage.py @@ -17,6 +17,7 @@ from __future__ import annotations +import inspect import json from typing import Any from unittest.mock import AsyncMock, MagicMock, patch @@ -57,8 +58,20 @@ def _skip_teams_jwt(monkeypatch): real_initialize = HttpServer.initialize - def _initialize_skip_auth(self, credentials=None, skip_auth=False, cloud=None): - return real_initialize(self, credentials=credentials, skip_auth=True, cloud=cloud) + # microsoft-teams-apps 2.0.14+ renamed the SDK's ``skip_auth`` flag to + # ``dangerously_allow_unauthenticated_requests``; force whichever flag this + # version has and forward everything else untouched (the SDK calls + # ``initialize`` with keywords only). + skip_flag = ( + "dangerously_allow_unauthenticated_requests" + if "dangerously_allow_unauthenticated_requests" in inspect.signature(real_initialize).parameters + else "skip_auth" + ) + + def _initialize_skip_auth(self, *args, **kwargs): + kwargs.pop("skip_auth", None) + kwargs.pop("dangerously_allow_unauthenticated_requests", None) + return real_initialize(self, *args, **{**kwargs, skip_flag: True}) monkeypatch.setattr(HttpServer, "initialize", _initialize_skip_auth) diff --git a/tests/test_teams_extended.py b/tests/test_teams_extended.py index 171d9195..5b057f06 100644 --- a/tests/test_teams_extended.py +++ b/tests/test_teams_extended.py @@ -15,6 +15,7 @@ from __future__ import annotations +import inspect import json from datetime import datetime from typing import Any @@ -63,8 +64,20 @@ def _skip_teams_jwt(monkeypatch): real_initialize = HttpServer.initialize - def _initialize_skip_auth(self, credentials=None, skip_auth=False, cloud=None): - return real_initialize(self, credentials=credentials, skip_auth=True, cloud=cloud) + # microsoft-teams-apps 2.0.14+ renamed the SDK's ``skip_auth`` flag to + # ``dangerously_allow_unauthenticated_requests``; force whichever flag this + # version has and forward everything else untouched (the SDK calls + # ``initialize`` with keywords only). + skip_flag = ( + "dangerously_allow_unauthenticated_requests" + if "dangerously_allow_unauthenticated_requests" in inspect.signature(real_initialize).parameters + else "skip_auth" + ) + + def _initialize_skip_auth(self, *args, **kwargs): + kwargs.pop("skip_auth", None) + kwargs.pop("dangerously_allow_unauthenticated_requests", None) + return real_initialize(self, *args, **{**kwargs, skip_flag: True}) monkeypatch.setattr(HttpServer, "initialize", _initialize_skip_auth)