-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load credentials only when needed #7774
Changes from 3 commits
4b70f14
5e15286
3c673cb
8076f57
438d005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Tests for the `cargo owner` command. | ||
|
||
use std::fs::{self, File}; | ||
use std::io::prelude::*; | ||
|
||
use cargo_test_support::project; | ||
use cargo_test_support::registry::{self, api_path, registry_url}; | ||
|
||
fn setup(name: &str) { | ||
fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}", name))).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to yank. let dir = api_path().join(format!("api/v1/crates/{}", name));
dir.mkdir_p();
// ...
fs::write(dir.join("owners"), content).unwrap(); |
||
|
||
let dest = api_path().join(format!("api/v1/crates/{}/owners", name)); | ||
|
||
let content = r#"{ | ||
"users": [ | ||
{ | ||
"id": 70, | ||
"login": "github:rust-lang:core", | ||
"name": "Core" | ||
} | ||
] | ||
}"#; | ||
|
||
File::create(&dest) | ||
.unwrap() | ||
.write_all(content.as_bytes()) | ||
.unwrap(); | ||
} | ||
|
||
#[cargo_test] | ||
fn simple_list() { | ||
registry::init(); | ||
setup("foo"); | ||
|
||
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(); | ||
|
||
p.cargo("owner -l --index") | ||
.arg(registry_url().to_string()) | ||
.run(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1261,3 +1261,40 @@ repository = "foo" | |
)], | ||
); | ||
} | ||
|
||
#[cargo_test] | ||
fn credentials_ambiguous_filename() { | ||
registry::init(); | ||
|
||
let credentials_toml = paths::home().join(".cargo/credentials.toml"); | ||
File::create(&credentials_toml) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.unwrap() | ||
.write_all(br#"token = "api-token""#) | ||
.unwrap(); | ||
|
||
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(); | ||
|
||
p.cargo("publish --no-verify --index") | ||
.arg(registry_url().to_string()) | ||
.with_stderr_contains( | ||
"\ | ||
[WARNING] Both `[..]/credentials` and `[..]/credentials.toml` exist. Using `[..]/credentials` | ||
", | ||
) | ||
.run(); | ||
|
||
validate_upload_foo(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Tests for the `cargo yank` command. | ||
|
||
use std::fs::{self, File}; | ||
use std::io::prelude::*; | ||
|
||
use cargo_test_support::project; | ||
use cargo_test_support::registry::{self, api_path, registry_url}; | ||
|
||
fn setup(name: &str, version: &str) { | ||
fs::create_dir_all(&api_path().join(format!("api/v1/crates/{}/{}", name, version))).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be simplified a little with: let dir = api_path().join(format!("api/v1/crates/{}/{}", name, version));
dir.mkdir_p();
fs::write(dir.join("yank"), r#"{"ok": true}"#).unwrap();
|
||
|
||
let dest = api_path().join(format!("api/v1/crates/{}/{}/yank", name, version)); | ||
|
||
let content = r#"{ | ||
"ok": true | ||
}"#; | ||
|
||
File::create(&dest) | ||
.unwrap() | ||
.write_all(content.as_bytes()) | ||
.unwrap(); | ||
} | ||
|
||
#[cargo_test] | ||
fn simple() { | ||
registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
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(); | ||
|
||
p.cargo("yank --vers 0.0.1 --index") | ||
.arg(registry_url().to_string()) | ||
.run(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this maybe be simplified a little instead of removing and reinserting? Maybe something like this?