@@ -18,12 +18,13 @@ use crates_io_index::{Credentials, RepositoryConfig};
1818use crates_io_team_repo:: MockTeamRepo ;
1919use crates_io_test_db:: TestDatabase ;
2020use crates_io_trustpub:: github:: test_helpers:: AUDIENCE ;
21+ use crates_io_trustpub:: keystore:: { MockOidcKeyStore , OidcKeyStore } ;
2122use crates_io_worker:: Runner ;
2223use diesel_async:: AsyncPgConnection ;
2324use futures_util:: TryStreamExt ;
2425use oauth2:: { ClientId , ClientSecret } ;
2526use regex:: Regex ;
26- use std:: collections:: HashSet ;
27+ use std:: collections:: { HashMap , HashSet } ;
2728use std:: sync:: LazyLock ;
2829use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
2930use tokio:: runtime:: Handle ;
@@ -104,6 +105,7 @@ impl TestApp {
104105 team_repo : MockTeamRepo :: new ( ) ,
105106 github : None ,
106107 docs_rs : None ,
108+ oidc_key_stores : Default :: default ( ) ,
107109 }
108110 }
109111
@@ -246,6 +248,7 @@ pub struct TestAppBuilder {
246248 team_repo : MockTeamRepo ,
247249 github : Option < MockGitHubClient > ,
248250 docs_rs : Option < MockDocsRsClient > ,
251+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
249252}
250253
251254impl TestAppBuilder {
@@ -284,7 +287,7 @@ impl TestAppBuilder {
284287 ( primary_proxy, replica_proxy)
285288 } ;
286289
287- let ( app, router) = build_app ( self . config , self . github ) ;
290+ let ( app, router) = build_app ( self . config , self . github , self . oidc_key_stores ) ;
288291
289292 let runner = if self . build_job_runner {
290293 let index = self
@@ -398,6 +401,17 @@ impl TestAppBuilder {
398401 self
399402 }
400403
404+ /// Add a new OIDC keystore to the application
405+ pub fn with_oidc_keystore (
406+ mut self ,
407+ issuer_url : impl Into < String > ,
408+ keystore : MockOidcKeyStore ,
409+ ) -> Self {
410+ self . oidc_key_stores
411+ . insert ( issuer_url. into ( ) , Box :: new ( keystore) ) ;
412+ self
413+ }
414+
401415 pub fn with_team_repo ( mut self , team_repo : MockTeamRepo ) -> Self {
402416 self . team_repo = team_repo;
403417 self
@@ -496,7 +510,11 @@ fn simple_config() -> config::Server {
496510 }
497511}
498512
499- fn build_app ( config : config:: Server , github : Option < MockGitHubClient > ) -> ( Arc < App > , axum:: Router ) {
513+ fn build_app (
514+ config : config:: Server ,
515+ github : Option < MockGitHubClient > ,
516+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
517+ ) -> ( Arc < App > , axum:: Router ) {
500518 // Use the in-memory email backend for all tests, allowing tests to analyze the emails sent by
501519 // the application. This will also prevent cluttering the filesystem.
502520 let emails = Emails :: new_in_memory ( ) ;
@@ -508,6 +526,7 @@ fn build_app(config: config::Server, github: Option<MockGitHubClient>) -> (Arc<A
508526 . databases_from_config ( & config. db )
509527 . github ( github)
510528 . github_oauth_from_config ( & config)
529+ . oidc_key_stores ( oidc_key_stores)
511530 . emails ( emails)
512531 . storage_from_config ( & config. storage )
513532 . rate_limiter_from_config ( config. rate_limiter . clone ( ) )
0 commit comments