fix-2183: populate team_id from user_context if it is none in kwargs#2184
Merged
crivetimihai merged 7 commits intoIBM:mainfrom Jan 19, 2026
Merged
fix-2183: populate team_id from user_context if it is none in kwargs#2184crivetimihai merged 7 commits intoIBM:mainfrom
crivetimihai merged 7 commits intoIBM:mainfrom
Conversation
6905982 to
c110c18
Compare
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Apply the same team_id fallback logic from require_permission to require_any_permission for consistency. When team_id is not in path parameters, fall back to user_context team_id. Closes IBM#2183 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add unit tests for issue IBM#2183 fix: - test_require_permission_uses_user_context_team_id_when_no_kwarg - test_require_permission_prefers_kwarg_team_id - test_require_any_permission_uses_user_context_team_id_when_no_kwarg - test_require_any_permission_prefers_kwarg_team_id - test_decorators_handle_none_user_context_team_id - test_plugin_permission_hook_receives_token_team_id (skipped, flaky) Add integration tests: - test_team_scoped_role_accesses_endpoint_without_team_id_param - test_team_scoped_role_with_mismatched_team_id_gets_403 - test_team_scoped_role_on_endpoint_without_team_id_param Closes IBM#2183 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
2f54b16 to
4ebb21f
Compare
Member
|
Thanks for the fix @KKNithin! I've rebased on main and added comprehensive tests to verify the behavior: Unit tests (
Integration tests (
The fix ensures that non-admin users with team-scoped roles can now access protected endpoints without needing to explicitly pass |
- Add plugin_framework mock to unit tests to ensure standard RBAC runs - Fix integration tests to mock PermissionService and verify team_id - Skip team mismatch test that requires auth middleware setup - Add assertions to verify check_permission receives correct team_id Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
crivetimihai
approved these changes
Jan 19, 2026
Use importlib.import_module and try/finally pattern to properly mock get_plugin_manager, matching the approach used by existing skipped tests. This ensures the mock is applied at the module level where the dynamic import occurs in the decorator. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
These tests require mocking the plugin manager singleton which is flaky in parallel execution (pytest-xdist). Mark them as skipped matching the pattern of existing plugin-related tests. Tests can be run individually with: pytest tests/unit/mcpgateway/middleware/test_rbac.py -k 'team_id' -v Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Member
|
@KKNithin - merged, please review and open a new issue if needed. |
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…BM#2184) * populate team_id from user_context if it is none in kwargs Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com> * lint issue fix Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com> * fix: Apply team_id fallback consistently to require_any_permission Apply the same team_id fallback logic from require_permission to require_any_permission for consistency. When team_id is not in path parameters, fall back to user_context team_id. Closes IBM#2183 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * test: Add comprehensive tests for team_id fallback from user_context Add unit tests for issue IBM#2183 fix: - test_require_permission_uses_user_context_team_id_when_no_kwarg - test_require_permission_prefers_kwarg_team_id - test_require_any_permission_uses_user_context_team_id_when_no_kwarg - test_require_any_permission_prefers_kwarg_team_id - test_decorators_handle_none_user_context_team_id - test_plugin_permission_hook_receives_token_team_id (skipped, flaky) Add integration tests: - test_team_scoped_role_accesses_endpoint_without_team_id_param - test_team_scoped_role_with_mismatched_team_id_gets_403 - test_team_scoped_role_on_endpoint_without_team_id_param Closes IBM#2183 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * test: Fix integration tests to properly mock PermissionService - Add plugin_framework mock to unit tests to ensure standard RBAC runs - Fix integration tests to mock PermissionService and verify team_id - Skip team mismatch test that requires auth middleware setup - Add assertions to verify check_permission receives correct team_id Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * test: Fix plugin manager mocking in team_id fallback tests Use importlib.import_module and try/finally pattern to properly mock get_plugin_manager, matching the approach used by existing skipped tests. This ensures the mock is applied at the module level where the dynamic import occurs in the decorator. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * test: Mark team_id fallback tests as skipped for parallel execution These tests require mocking the plugin manager singleton which is flaky in parallel execution (pytest-xdist). Mark them as skipped matching the pattern of existing plugin-related tests. Tests can be run individually with: pytest tests/unit/mcpgateway/middleware/test_rbac.py -k 'team_id' -v Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Nithin Katta <Nithin.Katta@ibm.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
resolves issue #2183
closes #2183