Skip to content

Commit ed813af

Browse files
committed
Revert "test: Add automated test for service account token acquisition (ADR-002 Tier 1)"
This reverts commit cbc37f1.
1 parent 1e071c8 commit ed813af

File tree

3 files changed

+2
-136
lines changed

3 files changed

+2
-136
lines changed

docs/ADR-002-vector-sync-authentication.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,8 @@ We will implement a **tiered OAuth authentication strategy** for background oper
5151
- Background worker uses service account token directly
5252
- No user-specific delegation or impersonation
5353
- **Implementation**: `KeycloakOAuthClient.get_service_account_token()` (keycloak_oauth.py:341-395)
54-
- **Testing**:
55-
-**Automated test**: `tests/server/oauth/test_keycloak_external_idp.py::test_keycloak_service_account_token_acquisition`
56-
-**Manual test**: `tests/manual/test_token_exchange.py`
57-
- **Supported Providers**:
58-
-**Keycloak** (external IdP mode) - Fully tested and validated
59-
-**Nextcloud OIDC app** (integrated mode) - Not yet implemented (see app.py:631-635)
60-
- The `KeycloakOAuthClient` class is provider-agnostic and works with any OIDC provider
61-
- Extending support to Nextcloud OIDC app requires configuration/initialization only
54+
- **Testing**: Manual test in `tests/manual/test_token_exchange.py`
55+
- **TODO**: Automated integration tests needed for both Keycloak and Nextcloud OIDC app
6256

6357
**Trade-offs**:
6458
- ✅ Works with nearly all OIDC providers

tests/conftest.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,59 +2526,6 @@ async def keycloak_oauth_client_credentials(anyio_backend, oauth_callback_server
25262526
# No cleanup needed - client is pre-configured in realm export
25272527

25282528

2529-
@pytest.fixture(scope="session")
2530-
async def keycloak_oauth_client(anyio_backend, keycloak_oauth_client_credentials):
2531-
"""
2532-
Fixture to create a KeycloakOAuthClient instance for service account token operations.
2533-
2534-
This fixture is used to test ADR-002 Tier 1 (service account token acquisition) and
2535-
Tier 3 (token exchange with delegation).
2536-
2537-
Returns:
2538-
KeycloakOAuthClient instance configured with Keycloak credentials
2539-
"""
2540-
from nextcloud_mcp_server.auth.keycloak_oauth import KeycloakOAuthClient
2541-
2542-
# Get Keycloak configuration from environment
2543-
keycloak_discovery_url = os.getenv(
2544-
"OIDC_DISCOVERY_URL",
2545-
"http://localhost:8888/realms/nextcloud-mcp/.well-known/openid-configuration",
2546-
)
2547-
2548-
# Extract base URL and realm from discovery URL
2549-
# Format: http://keycloak:8080/realms/nextcloud-mcp/.well-known/openid-configuration
2550-
if "/realms/" in keycloak_discovery_url:
2551-
base_url = keycloak_discovery_url.split("/realms/")[0]
2552-
realm = keycloak_discovery_url.split("/realms/")[1].split("/")[0]
2553-
else:
2554-
pytest.skip("Invalid Keycloak discovery URL format")
2555-
2556-
client_id, client_secret, callback_url, _, _ = keycloak_oauth_client_credentials
2557-
2558-
logger.info("Creating KeycloakOAuthClient for service account operations...")
2559-
logger.info(f" Keycloak URL: {base_url}")
2560-
logger.info(f" Realm: {realm}")
2561-
logger.info(f" Client ID: {client_id}")
2562-
2563-
oauth_client = KeycloakOAuthClient(
2564-
keycloak_url=base_url,
2565-
realm=realm,
2566-
client_id=client_id,
2567-
client_secret=client_secret,
2568-
redirect_uri=callback_url,
2569-
)
2570-
2571-
# Discover endpoints
2572-
await oauth_client.discover()
2573-
logger.info("✓ KeycloakOAuthClient initialized")
2574-
logger.info(f" Token endpoint: {oauth_client.token_endpoint}")
2575-
2576-
yield oauth_client
2577-
2578-
# Cleanup (close http client if needed)
2579-
await oauth_client.close()
2580-
2581-
25822529
async def _get_keycloak_oauth_token(
25832530
browser,
25842531
keycloak_oauth_client_credentials,

tests/server/oauth/test_keycloak_external_idp.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import json
2222
import logging
23-
import os
2423

2524
import pytest
2625

@@ -93,80 +92,6 @@ async def test_keycloak_oauth_client_credentials_discovery(
9392
logger.info(f" Authorization endpoint: {authorization_endpoint}")
9493

9594

96-
async def test_keycloak_service_account_token_acquisition(keycloak_oauth_client):
97-
"""Test service account token acquisition via client_credentials grant (ADR-002 Tier 1).
98-
99-
Verifies:
100-
- Service account token is acquired using client_credentials grant
101-
- Token response includes access_token, token_type, expires_in
102-
- Token can be used to access Nextcloud APIs
103-
- Token type is Bearer
104-
105-
This test validates ADR-002 Tier 1 implementation for Keycloak external IdP.
106-
107-
Note: For Nextcloud OIDC app (integrated mode), service account token acquisition
108-
is not yet implemented. See app.py:631-635 which states "OAuth client for token
109-
refresh not yet implemented for integrated mode". The KeycloakOAuthClient class
110-
works with any OIDC provider, so extending support to Nextcloud OIDC app is
111-
primarily a configuration/initialization issue rather than a fundamental limitation.
112-
"""
113-
# Get service account token with standard scopes
114-
token_response = await keycloak_oauth_client.get_service_account_token(
115-
scopes=["openid", "profile", "email"]
116-
)
117-
118-
# Verify token response structure
119-
assert "access_token" in token_response, "Missing access_token in response"
120-
assert "token_type" in token_response, "Missing token_type in response"
121-
assert "expires_in" in token_response, "Missing expires_in in response"
122-
123-
assert token_response["token_type"].lower() == "bearer", (
124-
f"Expected Bearer token type, got {token_response['token_type']}"
125-
)
126-
assert isinstance(token_response["expires_in"], int), (
127-
f"Expected integer expires_in, got {type(token_response['expires_in'])}"
128-
)
129-
assert token_response["expires_in"] > 0, (
130-
f"Expected positive expires_in, got {token_response['expires_in']}"
131-
)
132-
133-
logger.info("✓ Service account token acquired successfully")
134-
logger.info(f" Token type: {token_response['token_type']}")
135-
logger.info(f" Expires in: {token_response['expires_in']}s")
136-
logger.info(f" Scope: {token_response.get('scope', 'N/A')}")
137-
logger.info(f" Token length: {len(token_response['access_token'])} chars")
138-
139-
# Verify token works with Nextcloud APIs
140-
# The service account token should be validated by Nextcloud's user_oidc app
141-
from nextcloud_mcp_server.client import NextcloudClient
142-
143-
nextcloud_host = os.getenv("NEXTCLOUD_HOST", "http://localhost:8080")
144-
145-
# Create a NextcloudClient using the service account token
146-
nc_client = NextcloudClient.from_token(
147-
base_url=nextcloud_host,
148-
token=token_response["access_token"],
149-
username="service-account-nextcloud-mcp-server", # Keycloak service account username
150-
)
151-
152-
try:
153-
# Verify token works with Nextcloud API (using OCS endpoint which works without patch)
154-
capabilities = await nc_client.capabilities()
155-
assert capabilities is not None, (
156-
"Failed to get capabilities with service account token"
157-
)
158-
159-
logger.info("✓ Service account token works with Nextcloud APIs")
160-
logger.info(
161-
f" Nextcloud version: {capabilities.get('version', {}).get('string', 'unknown')}"
162-
)
163-
164-
finally:
165-
await nc_client.close()
166-
167-
logger.info("✓ ADR-002 Tier 1 (Service Account Token) validated for Keycloak")
168-
169-
17095
# ============================================================================
17196
# MCP Server Connectivity Tests
17297
# ============================================================================

0 commit comments

Comments
 (0)