22from unittest .mock import MagicMock , patch
33
44from utils .jwt_helper import (
5+ _jwks_clients ,
56 AUDIENCE ,
67 BUILDKITE_ISSUER ,
78 BUILDKITE_REPO_MAP ,
@@ -259,7 +260,7 @@ def tearDown(self):
259260 BUILDKITE_REPO_MAP .clear ()
260261 BUILDKITE_REPO_MAP .update (self ._orig_map )
261262
262- def test_loads_valid_buildkite_entries (self ):
263+ def test_loads_valid_buildkite_entries_legacy (self ):
263264 raw = {
264265 "buildkite" : {
265266 "org-id-1/pipe-id-1" : "vllm-project/vllm" ,
@@ -275,7 +276,7 @@ def test_loads_valid_buildkite_entries(self):
275276 BUILDKITE_REPO_MAP [("org-id-2" , "pipe-id-2" )]["repo" ], "acme/repo"
276277 )
277278
278- def test_loads_constrained_entries (self ):
279+ def test_loads_constrained_entries_legacy (self ):
279280 raw = {
280281 "buildkite" : {
281282 "org-id/pipe-id" : {
@@ -293,6 +294,59 @@ def test_loads_constrained_entries(self):
293294 self .assertEqual (entry ["required_claims" ]["build_branch" ], ["main" , "nightly" ])
294295 self .assertEqual (entry ["required_claims" ]["cluster_id" ], ["cluster-uuid" ])
295296
297+ def test_providers_section_loads_repo_map (self ):
298+ raw = {
299+ "providers" : {
300+ "buildkite" : {
301+ "repo_map" : {
302+ "org-id/pipe-id" : "vllm-project/vllm" ,
303+ },
304+ },
305+ }
306+ }
307+ load_ci_provider_mappings (raw )
308+ self .assertEqual (
309+ BUILDKITE_REPO_MAP [("org-id" , "pipe-id" )]["repo" ], "vllm-project/vllm"
310+ )
311+
312+ def test_providers_section_loads_constrained_repo_map (self ):
313+ raw = {
314+ "providers" : {
315+ "buildkite" : {
316+ "repo_map" : {
317+ "org-id/pipe-id" : {
318+ "repo" : "myorg/myrepo" ,
319+ "required_claims" : {"build_branch" : ["main" ]},
320+ },
321+ },
322+ },
323+ }
324+ }
325+ load_ci_provider_mappings (raw )
326+ entry = BUILDKITE_REPO_MAP [("org-id" , "pipe-id" )]
327+ self .assertEqual (entry ["repo" ], "myorg/myrepo" )
328+ self .assertEqual (entry ["required_claims" ]["build_branch" ], ["main" ])
329+
330+ def test_providers_ignores_issuer_jwks_fields (self ):
331+ """Config may still contain issuer/jwks_uri for documentation but they
332+ are ignored — trust anchors are compiled in."""
333+ raw = {
334+ "providers" : {
335+ "buildkite" : {
336+ "issuer" : "https://evil.example.com" ,
337+ "jwks_uri" : "https://evil.example.com/.well-known/jwks" ,
338+ "repo_map" : {
339+ "org-id/pipe-id" : "vllm-project/vllm" ,
340+ },
341+ },
342+ }
343+ }
344+ load_ci_provider_mappings (raw )
345+ self .assertNotIn ("https://evil.example.com" , _jwks_clients )
346+ self .assertEqual (
347+ BUILDKITE_REPO_MAP [("org-id" , "pipe-id" )]["repo" ], "vllm-project/vllm"
348+ )
349+
296350 def test_empty_config_clears_map (self ):
297351 BUILDKITE_REPO_MAP [("old" , "entry" )] = {
298352 "repo" : "old/repo" ,
@@ -317,6 +371,18 @@ def test_skips_invalid_entries(self):
317371 self .assertNotIn (("noslash" , "" ), BUILDKITE_REPO_MAP )
318372 self .assertEqual (BUILDKITE_REPO_MAP [("ok-id" , "pipe-id" )]["repo" ], "ok/repo" )
319373
374+ def test_legacy_fallback_when_providers_has_no_repo_map (self ):
375+ """If providers section exists but has no buildkite repo_map,
376+ fall back to legacy flat buildkite section."""
377+ raw = {
378+ "providers" : {"github" : {}},
379+ "buildkite" : {"org-id/pipe-id" : "legacy/repo" },
380+ }
381+ load_ci_provider_mappings (raw )
382+ self .assertEqual (
383+ BUILDKITE_REPO_MAP [("org-id" , "pipe-id" )]["repo" ], "legacy/repo"
384+ )
385+
320386
321387class TestUnsupportedIssuer (unittest .TestCase ):
322388 """Tests for tokens from unsupported issuers."""
@@ -342,5 +408,28 @@ def test_none_issuer_raises_401(self):
342408 self .assertEqual (ctx .exception .status_code , 401 )
343409
344410
411+ class TestTrustAnchorsCompiledIn (unittest .TestCase ):
412+ """Verify that JWKS clients are hardcoded and not modifiable via config."""
413+
414+ def test_jwks_clients_contain_known_issuers (self ):
415+ self .assertIn (GITHUB_ISSUER , _jwks_clients )
416+ self .assertIn (BUILDKITE_ISSUER , _jwks_clients )
417+
418+ def test_jwks_clients_not_expandable_via_config (self ):
419+ """Loading config with a rogue issuer must not add a JWKS client."""
420+ fake_issuer = "https://rogue.example.com"
421+ raw = {
422+ "providers" : {
423+ "rogue" : {
424+ "issuer" : fake_issuer ,
425+ "jwks_uri" : f"{ fake_issuer } /.well-known/jwks" ,
426+ "repo_map" : {"org/pipe" : "owner/repo" },
427+ },
428+ }
429+ }
430+ load_ci_provider_mappings (raw )
431+ self .assertNotIn (fake_issuer , _jwks_clients )
432+
433+
345434if __name__ == "__main__" :
346435 unittest .main ()
0 commit comments