mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Support store public request body in the HTTP mock server
This commit is contained in:
parent
04d592c7ad
commit
a8233d4df5
@ -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());
|
||||
|
@ -465,7 +465,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",
|
||||
@ -486,10 +493,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#"{
|
||||
|
Loading…
x
Reference in New Issue
Block a user