@@ -280,7 +280,7 @@ def factory(request: httpx.Request) -> httpx.Response:
280280
281281
282282@pytest .mark .asyncio
283- async def test_http_upstream_resolves_identity_at_derived_orbit_url ():
283+ async def test_http_upstream_resolves_identity_at_configured_url ():
284284 captured : dict [str , Any ] = {}
285285
286286 def factory (request : httpx .Request ) -> httpx .Response :
@@ -300,7 +300,10 @@ def factory(request: httpx.Request) -> httpx.Response:
300300 provider = _build_upstream (
301301 factory ,
302302 config_overrides = {
303- "url" : ("https://orbit.example/prefix/internal/auth/agent_control/check_management_access" ),
303+ "url" : (
304+ "https://orbit.example/prefix/internal/auth/agent_control/check_management_access"
305+ ),
306+ "identity_url" : "https://orbit.example/prefix/internal/auth/resolve_tenant_context" ,
304307 "service_token" : "service-secret" ,
305308 "extra_forward_headers" : ("X-Deployer-Auth" ,),
306309 },
@@ -1671,13 +1674,51 @@ async def test_configure_http_upstream_extra_forward_headers_env(monkeypatch):
16711674 await auth_config .teardown_auth ()
16721675
16731676
1677+ @pytest .mark .parametrize (
1678+ ("upstream_url" , "expected_identity_url" ),
1679+ [
1680+ (
1681+ "https://orbit.example/prefix/internal/auth/agent_control/check_management_access" ,
1682+ "https://orbit.example/prefix/internal/auth/resolve_tenant_context" ,
1683+ ),
1684+ ("https://auth.example.test/check" , None ),
1685+ ],
1686+ )
16741687@pytest .mark .asyncio
1675- async def test_configure_http_upstream_identity_url_env (monkeypatch ):
1688+ async def test_configure_http_upstream_selects_identity_url (
1689+ monkeypatch , upstream_url : str , expected_identity_url : str | None
1690+ ):
16761691 from agent_control_server .auth_framework import config as auth_config
16771692
16781693 clear_authorizers ()
16791694 monkeypatch .setenv ("AGENT_CONTROL_AUTH_MODE" , "http_upstream" )
1680- monkeypatch .setenv ("AGENT_CONTROL_AUTH_UPSTREAM_URL" , "https://auth.example.test/check" )
1695+ monkeypatch .setenv ("AGENT_CONTROL_AUTH_UPSTREAM_URL" , upstream_url )
1696+ monkeypatch .delenv ("AGENT_CONTROL_AUTH_UPSTREAM_IDENTITY_URL" , raising = False )
1697+
1698+ try :
1699+ auth_config .configure_auth_from_env ()
1700+ provider = get_authorizer (Operation .CONTROL_BINDINGS_READ )
1701+ assert isinstance (provider , HttpUpstreamAuthProvider )
1702+ assert provider ._config .identity_url == expected_identity_url
1703+ assert provider .binding_target_authorization is (expected_identity_url is not None )
1704+ finally :
1705+ await auth_config .teardown_auth ()
1706+
1707+
1708+ @pytest .mark .parametrize (
1709+ "upstream_url" ,
1710+ [
1711+ "https://auth.example.test/check" ,
1712+ "https://orbit.example/internal/auth/agent_control/check_management_access" ,
1713+ ],
1714+ )
1715+ @pytest .mark .asyncio
1716+ async def test_configure_http_upstream_identity_url_env (monkeypatch , upstream_url : str ):
1717+ from agent_control_server .auth_framework import config as auth_config
1718+
1719+ clear_authorizers ()
1720+ monkeypatch .setenv ("AGENT_CONTROL_AUTH_MODE" , "http_upstream" )
1721+ monkeypatch .setenv ("AGENT_CONTROL_AUTH_UPSTREAM_URL" , upstream_url )
16811722 monkeypatch .setenv (
16821723 "AGENT_CONTROL_AUTH_UPSTREAM_IDENTITY_URL" ,
16831724 " https://identity.example.test/resolve " ,
@@ -1688,6 +1729,7 @@ async def test_configure_http_upstream_identity_url_env(monkeypatch):
16881729 provider = get_authorizer (Operation .CONTROL_BINDINGS_READ )
16891730 assert isinstance (provider , HttpUpstreamAuthProvider )
16901731 assert provider ._config .identity_url == "https://identity.example.test/resolve"
1732+ assert provider .binding_target_authorization is True
16911733 finally :
16921734 await auth_config .teardown_auth ()
16931735
0 commit comments