diff --git a/src/bin/background-worker.rs b/src/bin/background-worker.rs index ebc1c4ce965..79fd9f400e8 100644 --- a/src/bin/background-worker.rs +++ b/src/bin/background-worker.rs @@ -18,6 +18,7 @@ use crates_io::cloudfront::CloudFront; use crates_io::db::DieselPool; use crates_io::fastly::Fastly; use crates_io::storage::Storage; +use crates_io::team_repo::TeamRepoImpl; use crates_io::worker::{Environment, RunnerExt}; use crates_io::{config, Emails}; use crates_io::{db, ssh}; @@ -76,7 +77,8 @@ fn main() -> anyhow::Result<()> { .expect("Couldn't build client"); let emails = Emails::from_environment(&config); - let fastly = Fastly::from_environment(client); + let fastly = Fastly::from_environment(client.clone()); + let team_repo = TeamRepoImpl::new(client); let connection_pool = r2d2::Pool::builder() .max_size(10) @@ -90,6 +92,7 @@ fn main() -> anyhow::Result<()> { .storage(storage) .connection_pool(DieselPool::new_background_worker(connection_pool.clone())) .emails(emails) + .team_repo(Box::new(team_repo)) .build()?; let environment = Arc::new(environment); diff --git a/src/tests/util/test_app.rs b/src/tests/util/test_app.rs index e434c28684d..0106dd604b3 100644 --- a/src/tests/util/test_app.rs +++ b/src/tests/util/test_app.rs @@ -7,6 +7,7 @@ use crates_io::middleware::cargo_compat::StatusCodeConfig; use crates_io::models::token::{CrateScope, EndpointScope}; use crates_io::rate_limiter::{LimitedAction, RateLimiterConfig}; use crates_io::storage::StorageConfig; +use crates_io::team_repo::MockTeamRepo; use crates_io::worker::{Environment, RunnerExt}; use crates_io::{App, Emails, Env}; use crates_io_index::testing::UpstreamIndex; @@ -80,6 +81,7 @@ impl TestApp { index: None, build_job_runner: false, use_chaos_proxy: false, + team_repo: MockTeamRepo::new(), } } @@ -204,6 +206,7 @@ pub struct TestAppBuilder { index: Option, build_job_runner: bool, use_chaos_proxy: bool, + team_repo: MockTeamRepo, } impl TestAppBuilder { @@ -259,11 +262,13 @@ impl TestAppBuilder { index_location: index.url(), credentials: Credentials::Missing, }; + let environment = Environment::builder() .repository_config(repository_config) .storage(app.storage.clone()) .connection_pool(app.primary_database.clone()) .emails(app.emails.clone()) + .team_repo(Box::new(self.team_repo)) .build() .unwrap(); @@ -351,6 +356,11 @@ impl TestAppBuilder { self } + pub fn with_team_repo(mut self, team_repo: MockTeamRepo) -> Self { + self.team_repo = team_repo; + self + } + pub fn with_replica(mut self) -> Self { let primary = &self.config.db.primary; diff --git a/src/worker/environment.rs b/src/worker/environment.rs index bc1e651cbbc..94143a36944 100644 --- a/src/worker/environment.rs +++ b/src/worker/environment.rs @@ -2,6 +2,7 @@ use crate::cloudfront::CloudFront; use crate::db::DieselPool; use crate::fastly::Fastly; use crate::storage::Storage; +use crate::team_repo::TeamRepo; use crate::typosquat; use crate::Emails; use crates_io_index::{Repository, RepositoryConfig}; @@ -25,6 +26,7 @@ pub struct Environment { pub storage: Arc, pub connection_pool: DieselPool, pub emails: Emails, + pub team_repo: Box, /// A lazily initialised cache of the most popular crates ready to use in typosquatting checks. #[builder(default, setter(skip))]