diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index a9d458c04695..6b854855c362 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -261,6 +261,7 @@ impl RegistryBuilder { let server = HttpServer::new( registry_path.clone(), dl_path, + api_path.clone(), token.clone(), self.auth_required, self.custom_responders, @@ -585,6 +586,7 @@ pub struct HttpServer { listener: TcpListener, registry_path: PathBuf, dl_path: PathBuf, + api_path: PathBuf, addr: SocketAddr, token: Token, auth_required: bool, @@ -604,6 +606,7 @@ impl HttpServer { pub fn new( registry_path: PathBuf, dl_path: PathBuf, + api_path: PathBuf, token: Token, auth_required: bool, api_responders: HashMap< @@ -617,6 +620,7 @@ impl HttpServer { listener, registry_path, dl_path, + api_path, addr, token, auth_required, @@ -1007,6 +1011,10 @@ impl HttpServer { pub fn check_authorized_publish(&self, req: &Request) -> Response { if let Some(body) = &req.body { + let path = self.api_path.join("api/v1/crates/new"); + t!(fs::create_dir_all(path.parent().unwrap())); + t!(fs::write(&path, body)); + // Get the metadata of the package let (len, remaining) = body.split_at(4); let json_len = u32::from_le_bytes(len.try_into().unwrap()); diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 938d9f3895b7..2c4560be2e2c 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -429,7 +429,14 @@ fn publish_to_alt_registry() { #[cargo_test] fn publish_with_crates_io_dep() { - registry::alt_init(); + // crates.io registry. + let _dummy_reg = registry::init(); + // Alternative registry. + let _alt_reg = RegistryBuilder::new() + .http_api() + .http_index() + .alternative_named("alternative") + .build(); let p = project() .file( "Cargo.toml", @@ -450,10 +457,26 @@ fn publish_with_crates_io_dep() { Package::new("bar", "0.0.1").publish(); - // Login so that we have the token available - p.cargo("login --registry alternative TOKEN").run(); - - p.cargo("publish --registry alternative").run(); + p.cargo("publish --registry alternative") + .with_stderr( + "\ +[UPDATING] `alternative` index +[WARNING] [..] +[..] +[PACKAGING] foo v0.0.1 [..] +[UPDATING] `dummy-registry` index +[VERIFYING] foo v0.0.1 [..] +[DOWNLOADING] [..] +[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`) +[COMPILING] bar v0.0.1 +[COMPILING] foo v0.0.1 [..] +[FINISHED] [..] +[PACKAGED] [..] +[UPLOADING] foo v0.0.1 [..] +[UPDATING] `alternative` index +", + ) + .run(); validate_alt_upload( r#"{