@@ -17,12 +17,13 @@ use crates_io_index::{Credentials, RepositoryConfig};
17
17
use crates_io_team_repo:: MockTeamRepo ;
18
18
use crates_io_test_db:: TestDatabase ;
19
19
use crates_io_trustpub:: github:: test_helpers:: AUDIENCE ;
20
+ use crates_io_trustpub:: keystore:: { MockOidcKeyStore , OidcKeyStore } ;
20
21
use crates_io_worker:: Runner ;
21
22
use diesel_async:: AsyncPgConnection ;
22
23
use futures_util:: TryStreamExt ;
23
24
use oauth2:: { ClientId , ClientSecret } ;
24
25
use regex:: Regex ;
25
- use std:: collections:: HashSet ;
26
+ use std:: collections:: { HashMap , HashSet } ;
26
27
use std:: sync:: LazyLock ;
27
28
use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
28
29
use tokio:: runtime:: Handle ;
@@ -102,6 +103,7 @@ impl TestApp {
102
103
use_chaos_proxy : false ,
103
104
team_repo : MockTeamRepo :: new ( ) ,
104
105
github : None ,
106
+ oidc_key_stores : Default :: default ( ) ,
105
107
}
106
108
}
107
109
@@ -243,6 +245,7 @@ pub struct TestAppBuilder {
243
245
use_chaos_proxy : bool ,
244
246
team_repo : MockTeamRepo ,
245
247
github : Option < MockGitHubClient > ,
248
+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
246
249
}
247
250
248
251
impl TestAppBuilder {
@@ -281,7 +284,7 @@ impl TestAppBuilder {
281
284
( primary_proxy, replica_proxy)
282
285
} ;
283
286
284
- let ( app, router) = build_app ( self . config , self . github ) ;
287
+ let ( app, router) = build_app ( self . config , self . github , self . oidc_key_stores ) ;
285
288
286
289
let runner = if self . build_job_runner {
287
290
let index = self
@@ -389,6 +392,17 @@ impl TestAppBuilder {
389
392
self
390
393
}
391
394
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
+
392
406
pub fn with_team_repo ( mut self , team_repo : MockTeamRepo ) -> Self {
393
407
self . team_repo = team_repo;
394
408
self
@@ -487,7 +501,11 @@ fn simple_config() -> config::Server {
487
501
}
488
502
}
489
503
490
- fn build_app ( config : config:: Server , github : Option < MockGitHubClient > ) -> ( Arc < App > , axum:: Router ) {
504
+ fn build_app (
505
+ config : config:: Server ,
506
+ github : Option < MockGitHubClient > ,
507
+ oidc_key_stores : HashMap < String , Box < dyn OidcKeyStore > > ,
508
+ ) -> ( Arc < App > , axum:: Router ) {
491
509
// Use the in-memory email backend for all tests, allowing tests to analyze the emails sent by
492
510
// the application. This will also prevent cluttering the filesystem.
493
511
let emails = Emails :: new_in_memory ( ) ;
@@ -499,6 +517,7 @@ fn build_app(config: config::Server, github: Option<MockGitHubClient>) -> (Arc<A
499
517
. databases_from_config ( & config. db )
500
518
. github ( github)
501
519
. github_oauth_from_config ( & config)
520
+ . oidc_key_stores ( oidc_key_stores)
502
521
. emails ( emails)
503
522
. storage_from_config ( & config. storage )
504
523
. rate_limiter_from_config ( config. rate_limiter . clone ( ) )
0 commit comments