@@ -17,12 +17,13 @@ use crates_io_index::{Credentials, RepositoryConfig};
1717use crates_io_team_repo:: MockTeamRepo ;
1818use crates_io_test_db:: TestDatabase ;
1919use crates_io_trustpub:: github:: test_helpers:: AUDIENCE ;
20+ use crates_io_trustpub:: keystore:: { MockOidcKeyStore , OidcKeyStore } ;
2021use crates_io_worker:: Runner ;
2122use diesel_async:: AsyncPgConnection ;
2223use futures_util:: TryStreamExt ;
2324use oauth2:: { ClientId , ClientSecret } ;
2425use regex:: Regex ;
25- use std:: collections:: HashSet ;
26+ use std:: collections:: { HashMap , HashSet } ;
2627use std:: sync:: LazyLock ;
2728use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
2829use tokio:: runtime:: Handle ;
@@ -102,6 +103,7 @@ impl TestApp {
102103 use_chaos_proxy : false ,
103104 team_repo : MockTeamRepo :: new ( ) ,
104105 github : None ,
106+ oidc_key_stores : Default :: default ( ) ,
105107 }
106108 }
107109
@@ -243,6 +245,7 @@ pub struct TestAppBuilder {
243245 use_chaos_proxy : bool ,
244246 team_repo : MockTeamRepo ,
245247 github : Option < MockGitHubClient > ,
248+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
246249}
247250
248251impl TestAppBuilder {
@@ -281,7 +284,7 @@ impl TestAppBuilder {
281284 ( primary_proxy, replica_proxy)
282285 } ;
283286
284- let ( app, router) = build_app ( self . config , self . github ) ;
287+ let ( app, router) = build_app ( self . config , self . github , self . oidc_key_stores ) ;
285288
286289 let runner = if self . build_job_runner {
287290 let index = self
@@ -389,6 +392,17 @@ impl TestAppBuilder {
389392 self
390393 }
391394
395+ /// Add a new OIDC keystore to the application
396+ pub fn with_oidc_keystore (
397+ mut self ,
398+ issuer_url : impl Into < String > ,
399+ keystore : MockOidcKeyStore ,
400+ ) -> Self {
401+ self . oidc_key_stores
402+ . insert ( issuer_url. into ( ) , Box :: new ( keystore) ) ;
403+ self
404+ }
405+
392406 pub fn with_team_repo ( mut self , team_repo : MockTeamRepo ) -> Self {
393407 self . team_repo = team_repo;
394408 self
@@ -482,7 +496,11 @@ fn simple_config() -> config::Server {
482496 }
483497}
484498
485- fn build_app ( config : config:: Server , github : Option < MockGitHubClient > ) -> ( Arc < App > , axum:: Router ) {
499+ fn build_app (
500+ config : config:: Server ,
501+ github : Option < MockGitHubClient > ,
502+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
503+ ) -> ( Arc < App > , axum:: Router ) {
486504 // Use the in-memory email backend for all tests, allowing tests to analyze the emails sent by
487505 // the application. This will also prevent cluttering the filesystem.
488506 let emails = Emails :: new_in_memory ( ) ;
@@ -494,6 +512,7 @@ fn build_app(config: config::Server, github: Option<MockGitHubClient>) -> (Arc<A
494512 . databases_from_config ( & config. db )
495513 . github ( github)
496514 . github_oauth_from_config ( & config)
515+ . oidc_key_stores ( oidc_key_stores)
497516 . emails ( emails)
498517 . storage_from_config ( & config. storage )
499518 . rate_limiter_from_config ( config. rate_limiter . clone ( ) )
0 commit comments