2026-03-20 00:49:44 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from src.core.vertex_auth import VertexAuthError, VertexAuthService
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _TimeoutAsyncClient:
|
|
|
|
|
def __init__(self, **_: object) -> None:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
async def __aenter__(self) -> "_TimeoutAsyncClient":
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
async def __aexit__(self, exc_type: object, exc: object, tb: object) -> bool:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
async def post(self, *args: object, **kwargs: object) -> object:
|
|
|
|
|
raise httpx.ReadTimeout("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
2026-03-31 19:19:04 +08:00
|
|
|
async def test_vertex_auth_is_rust_only(
|
2026-03-20 00:49:44 +08:00
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
|
) -> None:
|
|
|
|
|
service = VertexAuthService(
|
|
|
|
|
json.dumps(
|
|
|
|
|
{
|
|
|
|
|
"client_email": "svc@example.iam.gserviceaccount.com",
|
|
|
|
|
"private_key": "not-used-in-test",
|
|
|
|
|
"project_id": "demo-project",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr(service, "_create_jwt", lambda: "signed-jwt")
|
|
|
|
|
monkeypatch.setattr("src.core.vertex_auth.httpx.AsyncClient", _TimeoutAsyncClient)
|
|
|
|
|
|
2026-03-31 19:19:04 +08:00
|
|
|
with pytest.raises(VertexAuthError, match=r"仅支持 Rust executor"):
|
2026-03-20 00:49:44 +08:00
|
|
|
await service.get_access_token(httpx_client_kwargs={"timeout": 30})
|