Remove the oauth Docker Compose profile (mcp-oauth service, port 8001) which used OAuth bearer tokens for direct NC API access, requiring upstream OIDC patches. All NC access should use app passwords via Login Flow v2 or BasicAuth. Changes: - Remove mcp-oauth service from docker-compose.yml - Remove oauth mode from CI test matrix - Delete oauth pass-through tests (core, permissions, token exchange) - Delete oauth-specific tests (elicitation, NC PHP app, astrolabe) - Migrate MCP/OAuth integration tests to login-flow profile: - DCR lifecycle, deletion, token type tests - Scope authorization (tool filtering) tests - Token introspection tests - Fix flaky consent screen automation: replace JS btn.click() with Playwright native click + retry (handles Vue.js event binding race) - Add scope-filtered OAuth client fixtures to login-flow conftest - Keep keycloak profile for external IdP testing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
"""Unit tests for user info routes.
|
|
|
|
These unit tests cover the simple _query_idp_userinfo helper function.
|
|
"""
|
|
|
|
from unittest.mock import AsyncMock, Mock
|
|
|
|
import pytest
|
|
|
|
from nextcloud_mcp_server.auth.userinfo_routes import _query_idp_userinfo
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
async def test_query_idp_userinfo_success(mocker):
|
|
"""Test successful IdP userinfo query."""
|
|
mock_response = Mock()
|
|
mock_response.json.return_value = {
|
|
"sub": "alice",
|
|
"email": "alice@example.com",
|
|
"name": "Alice Smith",
|
|
}
|
|
mock_response.raise_for_status = Mock()
|
|
|
|
# Mock the async context manager properly
|
|
mock_client = AsyncMock()
|
|
mock_client.get.return_value = mock_response
|
|
mock_client.__aenter__.return_value = mock_client
|
|
mock_client.__aexit__.return_value = None
|
|
|
|
mocker.patch(
|
|
"nextcloud_mcp_server.auth.userinfo_routes.nextcloud_httpx_client",
|
|
return_value=mock_client,
|
|
)
|
|
|
|
result = await _query_idp_userinfo("test_token", "https://example.com/userinfo")
|
|
|
|
assert result == {
|
|
"sub": "alice",
|
|
"email": "alice@example.com",
|
|
"name": "Alice Smith",
|
|
}
|
|
mock_client.get.assert_called_once_with(
|
|
"https://example.com/userinfo",
|
|
headers={"Authorization": "Bearer test_token"},
|
|
)
|
|
|
|
|
|
async def test_query_idp_userinfo_failure(mocker):
|
|
"""Test IdP userinfo query failure handling."""
|
|
mock_client = AsyncMock()
|
|
mock_client.get.side_effect = Exception("Network error")
|
|
mock_client.__aenter__.return_value = mock_client
|
|
mock_client.__aexit__.return_value = None
|
|
|
|
mocker.patch(
|
|
"nextcloud_mcp_server.auth.userinfo_routes.nextcloud_httpx_client",
|
|
return_value=mock_client,
|
|
)
|
|
|
|
result = await _query_idp_userinfo("test_token", "https://example.com/userinfo")
|
|
|
|
assert result is None
|