2020-01-09 13:18:45 +00:00
|
|
|
//! Tests for the `cargo owner` command.
|
|
|
|
|
2020-01-14 07:15:29 +00:00
|
|
|
use std::fs;
|
2020-01-09 13:18:45 +00:00
|
|
|
|
2020-01-14 07:15:29 +00:00
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
2020-01-09 13:18:45 +00:00
|
|
|
use cargo_test_support::project;
|
2020-03-06 23:05:12 +00:00
|
|
|
use cargo_test_support::registry::{self, api_path};
|
2020-01-09 13:18:45 +00:00
|
|
|
|
2020-01-20 09:11:40 +00:00
|
|
|
fn setup(name: &str, content: Option<&str>) {
|
2020-01-14 07:15:29 +00:00
|
|
|
let dir = api_path().join(format!("api/v1/crates/{}", name));
|
|
|
|
dir.mkdir_p();
|
2020-02-21 11:15:16 +00:00
|
|
|
if let Some(body) = content {
|
|
|
|
fs::write(dir.join("owners"), body).unwrap();
|
2020-01-20 09:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple_list() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = registry::init();
|
2020-01-20 09:11:40 +00:00
|
|
|
let content = r#"{
|
2020-01-09 13:18:45 +00:00
|
|
|
"users": [
|
|
|
|
{
|
|
|
|
"id": 70,
|
|
|
|
"login": "github:rust-lang:core",
|
|
|
|
"name": "Core"
|
2020-05-12 15:03:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 123,
|
|
|
|
"login": "octocat"
|
2020-01-09 13:18:45 +00:00
|
|
|
}
|
|
|
|
]
|
2020-01-20 09:11:40 +00:00
|
|
|
}"#;
|
|
|
|
setup("foo", Some(content));
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
2020-01-20 09:11:40 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("owner -l")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2020-05-12 15:03:35 +00:00
|
|
|
.with_stdout(
|
|
|
|
"\
|
|
|
|
github:rust-lang:core (Core)
|
|
|
|
octocat
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2020-01-09 13:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
2020-01-20 09:11:40 +00:00
|
|
|
fn simple_add() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = registry::init();
|
2020-01-20 09:11:40 +00:00
|
|
|
setup("foo", None);
|
2020-01-09 13:18:45 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
2020-01-09 13:18:45 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("owner -a username")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2020-01-20 09:11:40 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2022-08-31 05:53:47 +00:00
|
|
|
" Updating crates.io index
|
2021-02-27 20:38:17 +00:00
|
|
|
error: failed to invite owners to crate `foo` on registry at file://[..]
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
EOF while parsing a value at line 1 column 0",
|
2020-01-20 09:11:40 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:49:22 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_add_with_asymmetric() {
|
|
|
|
let registry = registry::RegistryBuilder::new()
|
|
|
|
.http_api()
|
|
|
|
.token(cargo_test_support::registry::Token::rfc_key())
|
|
|
|
.build();
|
|
|
|
setup("foo", None);
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// The http_api server will check that the authorization is correct.
|
2022-12-13 23:46:20 +00:00
|
|
|
// If the authorization was not sent then we would get an unauthorized error.
|
2022-12-12 17:49:22 +00:00
|
|
|
p.cargo("owner -a username")
|
2023-08-24 05:12:50 +00:00
|
|
|
.arg("-Zasymmetric-token")
|
|
|
|
.masquerade_as_nightly_cargo(&["asymmetric-token"])
|
2022-12-12 17:49:22 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
|
|
|
.with_status(0)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-01-20 09:11:40 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_remove() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = registry::init();
|
2020-01-20 09:11:40 +00:00
|
|
|
setup("foo", None);
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
2020-01-20 09:11:40 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-08-31 05:53:47 +00:00
|
|
|
p.cargo("owner -r username")
|
|
|
|
.replace_crates_io(registry.index_url())
|
2020-01-20 09:11:40 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2022-08-31 05:53:47 +00:00
|
|
|
" Updating crates.io index
|
2020-01-20 09:11:40 +00:00
|
|
|
Owner removing [\"username\"] from crate foo
|
2021-02-27 20:38:17 +00:00
|
|
|
error: failed to remove owners from crate `foo` on registry at file://[..]
|
2020-01-20 09:11:40 +00:00
|
|
|
|
|
|
|
Caused by:
|
2020-01-22 00:19:59 +00:00
|
|
|
EOF while parsing a value at line 1 column 0",
|
2020-01-20 09:11:40 +00:00
|
|
|
)
|
2020-01-09 13:18:45 +00:00
|
|
|
.run();
|
|
|
|
}
|
2022-12-12 17:49:22 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple_remove_with_asymmetric() {
|
|
|
|
let registry = registry::RegistryBuilder::new()
|
|
|
|
.http_api()
|
|
|
|
.token(cargo_test_support::registry::Token::rfc_key())
|
|
|
|
.build();
|
|
|
|
setup("foo", None);
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// The http_api server will check that the authorization is correct.
|
2022-12-13 23:46:20 +00:00
|
|
|
// If the authorization was not sent then we would get an unauthorized error.
|
2022-12-12 17:49:22 +00:00
|
|
|
p.cargo("owner -r username")
|
2023-08-24 05:12:50 +00:00
|
|
|
.arg("-Zasymmetric-token")
|
2022-12-12 17:49:22 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2023-08-24 05:12:50 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["asymmetric-token"])
|
2022-12-12 17:49:22 +00:00
|
|
|
.with_status(0)
|
|
|
|
.run();
|
|
|
|
}
|