@@ -68,18 +68,54 @@ def test_dependency_override_applied(self):
6868 from odoo .addons .spp_api_v2 .middleware .auth import get_authenticated_client
6969
7070 endpoint = self .env ["fastapi.endpoint" ].search ([("app" , "=" , "api_v2" )], limit = 1 )
71- if endpoint :
72- overrides = endpoint ._get_app_dependencies_overrides ()
73- self .assertIn (
74- get_authenticated_client ,
75- overrides ,
76- "get_authenticated_client should be in dependency overrides" ,
77- )
78-
79- from ..middleware .auth_rs256 import get_authenticated_client_rs256
80-
81- self .assertEqual (
82- overrides [get_authenticated_client ],
83- get_authenticated_client_rs256 ,
84- "Override should point to the RS256 bridge function" ,
85- )
71+ if not endpoint :
72+ self .skipTest ("No api_v2 endpoint configured in test database" )
73+
74+ overrides = endpoint ._get_app_dependencies_overrides ()
75+ self .assertIn (
76+ get_authenticated_client ,
77+ overrides ,
78+ "get_authenticated_client should be in dependency overrides" ,
79+ )
80+
81+ from ..middleware .auth_rs256 import get_authenticated_client_rs256
82+
83+ self .assertEqual (
84+ overrides [get_authenticated_client ],
85+ get_authenticated_client_rs256 ,
86+ "Override should point to the RS256 bridge function" ,
87+ )
88+
89+ def test_router_registration (self ):
90+ """Verify the RS256 router is registered for api_v2 endpoints."""
91+ endpoint = self .env ["fastapi.endpoint" ].search ([("app" , "=" , "api_v2" )], limit = 1 )
92+ if not endpoint :
93+ self .skipTest ("No api_v2 endpoint configured in test database" )
94+
95+ routers = endpoint ._get_fastapi_routers ()
96+ # Check that at least one router contains a route to /oauth/token/rs256
97+ rs256_routes = [
98+ route
99+ for router in routers
100+ for route in router .routes
101+ if hasattr (route , "path" ) and route .path == "/oauth/token/rs256"
102+ ]
103+ self .assertTrue (
104+ rs256_routes ,
105+ "RS256 token endpoint should be registered in api_v2 routers" ,
106+ )
107+
108+ def test_no_override_for_non_api_v2 (self ):
109+ """Bridge overrides should NOT apply to non-api_v2 endpoints."""
110+ from odoo .addons .spp_api_v2 .middleware .auth import get_authenticated_client
111+
112+ endpoint = self .env ["fastapi.endpoint" ].search ([("app" , "!=" , "api_v2" )], limit = 1 )
113+ if not endpoint :
114+ self .skipTest ("No non-api_v2 endpoint configured in test database" )
115+
116+ overrides = endpoint ._get_app_dependencies_overrides ()
117+ self .assertNotIn (
118+ get_authenticated_client ,
119+ overrides ,
120+ "get_authenticated_client should NOT be overridden for non-api_v2 endpoints" ,
121+ )
0 commit comments