-
Notifications
You must be signed in to change notification settings - Fork 81
Normalize composite channels for all user token operations #457
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
Merged
rodrigobr-msft
merged 2 commits into
microsoft:main
from
Carvalh0XYZ:fix/copilot-base-channel-token-refresh
Jul 13, 2026
+130
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Tests for UserToken Bot Framework operations.""" | ||
|
|
||
| import pytest | ||
| from aiohttp import ClientSession, web | ||
| from aiohttp.test_utils import TestServer | ||
|
|
||
| from microsoft_agents.hosting.core.connector.client.user_token_client import UserToken | ||
|
|
||
|
|
||
| class TestUserTokenBaseChannel: | ||
| """Bot Framework token operations use the base channel partition.""" | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_all_token_operations_normalize_composite_channel(self): | ||
| captured = [] | ||
|
|
||
| async def handler(request): | ||
| captured.append( | ||
| (request.method, request.path, request.query.get("channelId")) | ||
| ) | ||
| path = request.path.lower() | ||
| if path.endswith("/gettokenorsigninresource"): | ||
| return web.json_response({"tokenResponse": {"token": "token"}}) | ||
| if path.endswith("/gettoken") or path.endswith("/exchange"): | ||
| return web.json_response({"token": "token"}) | ||
| if path.endswith("/getaadtokens"): | ||
| return web.json_response({"resource": {"token": "token"}}) | ||
| if path.endswith("/gettokenstatus"): | ||
| return web.json_response([]) | ||
| if path.endswith("/signout"): | ||
| return web.Response(status=204) | ||
| raise AssertionError(f"Unexpected token operation: {request.path}") | ||
|
|
||
| app = web.Application() | ||
| app.router.add_route("*", "/{tail:.*}", handler) | ||
| server = TestServer(app) | ||
| await server.start_server() | ||
| try: | ||
| async with ClientSession(base_url=server.make_url("/")) as session: | ||
| user_token = UserToken(session) | ||
| args = { | ||
| "user_id": "user", | ||
| "connection_name": "connection", | ||
| "channel_id": "msteams:COPILOT", | ||
| } | ||
| await user_token.get_token(**args) | ||
| await user_token._get_token_or_sign_in_resource(**args, state="state") | ||
| await user_token.get_aad_tokens(**args) | ||
| await user_token.sign_out(**args) | ||
| await user_token.get_token_status( | ||
| user_id="user", channel_id="msteams:COPILOT" | ||
| ) | ||
| await user_token.exchange_token(**args) | ||
| finally: | ||
| await server.close() | ||
|
|
||
| assert len(captured) == 6 | ||
| assert all(channel_id == "msteams" for _, _, channel_id in captured) | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_optional_channel_is_omitted_when_none(self): | ||
| captured = [] | ||
|
|
||
| async def handler(request): | ||
| captured.append(request.query.get("channelId")) | ||
| path = request.path.lower() | ||
| if path.endswith("/gettoken"): | ||
| return web.json_response({"token": "token"}) | ||
| if path.endswith("/getaadtokens"): | ||
| return web.json_response({"resource": {"token": "token"}}) | ||
| if path.endswith("/gettokenstatus"): | ||
| return web.json_response([]) | ||
| if path.endswith("/signout"): | ||
| return web.Response(status=204) | ||
| raise AssertionError(f"Unexpected token operation: {request.path}") | ||
|
|
||
| app = web.Application() | ||
| app.router.add_route("*", "/{tail:.*}", handler) | ||
| server = TestServer(app) | ||
| await server.start_server() | ||
| try: | ||
| async with ClientSession(base_url=server.make_url("/")) as session: | ||
| user_token = UserToken(session) | ||
| await user_token.get_token("user", "connection") | ||
| await user_token.get_aad_tokens("user", "connection") | ||
| await user_token.sign_out("user", "connection") | ||
| await user_token.get_token_status("user") | ||
| finally: | ||
| await server.close() | ||
|
|
||
| assert captured == [None, None, None, None] | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("channel_id", "expected"), | ||
| [ | ||
| ("msteams", "msteams"), | ||
| ("msteams:COPILOT", "msteams"), | ||
| ("msteams:", "msteams"), | ||
| (":COPILOT", ":COPILOT"), | ||
| (" ", " "), | ||
| (None, None), | ||
| ], | ||
| ) | ||
| def test_base_channel_id(self, channel_id, expected): | ||
| assert UserToken._base_channel_id(channel_id) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.