Files
DocsGPT/tests/parser/connectors/token_patch.py
T
arc53-machine 3511004f50 Connections own their credentials
Migration 0038 moves every stored secret (OAuth tokens, MCP OAuth
tokens and client registrations, API keys) into the connection's
encrypted envelope, links API-key tools to one connection per distinct
credential, allows several accounts per provider, and adds
credential_mode to sources and tools. OAuth MCP tools keep resolving
each member's own token, as they did before.

docsgpt.connectors.service is now the only reader of OAuth tokens:
get_valid_token_info refreshes under a row lock and persists rotated
refresh tokens, and a revoked grant flags the connection, pauses its
sources and notifies the owner. Loaders build from a connection
(BaseConnectorLoader.from_connection), so scheduled sync covers Drive,
SharePoint and Confluence sources with no browser. S3 and Reddit keys
stay on the connection instead of in remote_data.

New endpoints: POST /api/connections, /setup, /reconnect,
/picker-token, /claim, DELETE /api/connections/<id>, per-action
permissions and MCP refresh-tools. Upload, file listing, sync and
validate-session take a connection_id; session tokens keep working for
this release. The tool executor reads credentials from the resolved
connection (owner or member mode) and pauses on a Connect card when a
connection needs signing in. docsgpt connectors reencrypt rewrites
stored credentials after a key rotation.
2026-09-28 17:03:09 +01:00

24 lines
805 B
Python

"""Stand-in for the connection service in connector loader tests."""
from __future__ import annotations
from contextlib import ExitStack, contextmanager
from unittest.mock import patch
@contextmanager
def patch_tokens(token_info: dict, connection_id: str = "conn-1"):
"""Make every loader resolve ``connection_id`` and read ``token_info``.
Yields the ``get_valid_token_info`` mock so a test can assert on or
change what a refresh returns.
"""
with ExitStack() as stack:
stack.enter_context(
patch("docsgpt.connectors.service.connection_id_for_session_token", return_value=connection_id)
)
tokens = stack.enter_context(
patch("docsgpt.connectors.service.get_valid_token_info", return_value=token_info)
)
yield tokens