mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-13 22:34:06 +00:00
Remove check from the test
This commit is contained in:
parent
9fdc6f892a
commit
fa423dffbc
@ -104,12 +104,11 @@ def test_init_missing_key_uses_aad_token_provider(monkeypatch):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_aad_token_provider_wires_into_sdk_auth_headers(monkeypatch):
|
async def test_aad_token_provider_wires_into_sdk_auth_headers(monkeypatch):
|
||||||
"""End-to-end: SDK ``_refresh_api_key`` invokes our callable and the
|
"""Regression guard: the token provider must be wired into the
|
||||||
resulting bearer token shows up in ``auth_headers``.
|
OpenAI SDK so ``_refresh_api_key`` pulls a fresh token and the
|
||||||
|
bearer ends up in ``auth_headers``. Without this, a refactor that
|
||||||
This is a regression guard against a future refactor that constructs
|
constructs ``_AzureTokenProvider`` but forgets to pass it to
|
||||||
``_AzureTokenProvider`` but forgets to pass it to ``AsyncOpenAI`` (in
|
``AsyncOpenAI`` would silently send unauthenticated requests.
|
||||||
which case the outgoing request would carry no Authorization header).
|
|
||||||
"""
|
"""
|
||||||
access_token = SimpleNamespace(token="token-A", expires_on=time.time() + 3600)
|
access_token = SimpleNamespace(token="token-A", expires_on=time.time() + 3600)
|
||||||
credential_instance = MagicMock()
|
credential_instance = MagicMock()
|
||||||
@ -121,23 +120,18 @@ async def test_aad_token_provider_wires_into_sdk_auth_headers(monkeypatch):
|
|||||||
api_key="", api_base="https://res.openai.azure.com",
|
api_key="", api_base="https://res.openai.azure.com",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Before any refresh, the SDK has no key yet -> no auth header.
|
|
||||||
assert provider._client.api_key == ""
|
assert provider._client.api_key == ""
|
||||||
assert provider._client.auth_headers == {}
|
assert provider._client.auth_headers == {}
|
||||||
|
|
||||||
# Trigger the SDK's refresh path; it must call our async callable.
|
await provider._client._refresh_api_key()
|
||||||
refreshed = await provider._client._refresh_api_key()
|
|
||||||
|
|
||||||
assert refreshed == "token-A"
|
|
||||||
assert provider._client.api_key == "token-A"
|
assert provider._client.api_key == "token-A"
|
||||||
assert provider._client.auth_headers == {"Authorization": "Bearer token-A"}
|
assert provider._client.auth_headers == {"Authorization": "Bearer token-A"}
|
||||||
credential_instance.get_token.assert_awaited_with(
|
credential_instance.get_token.assert_awaited_with(
|
||||||
"https://cognitiveservices.azure.com/.default"
|
"https://cognitiveservices.azure.com/.default"
|
||||||
)
|
)
|
||||||
|
|
||||||
# A second refresh picks up a rotated token without re-instantiating
|
# Rotated token on second refresh proves per-request delegation (no client-side caching).
|
||||||
# the credential — proves we delegate per-request rather than caching
|
|
||||||
# the first value.
|
|
||||||
credential_instance.get_token = AsyncMock(
|
credential_instance.get_token = AsyncMock(
|
||||||
return_value=SimpleNamespace(token="token-B", expires_on=time.time() + 3600)
|
return_value=SimpleNamespace(token="token-B", expires_on=time.time() + 3600)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user