Skip to content

Commit

Permalink
count calls to credential process
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Dec 21, 2022
1 parent d464dbb commit 16177ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cargo/util/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn auth_token_optional(
}
};

if mutation.is_none() {
if independent_of_endpoint || mutation.is_none() {
cache.insert(
url.clone(),
CredentialCacheValue {
Expand Down Expand Up @@ -582,7 +582,7 @@ fn run_command(
}
}
// todo: PASETO with process
let independent_of_endpoint = false;
let independent_of_endpoint = true;
let action_str = match action {
Action::Get => "get",
Action::Store(_) => "store",
Expand Down
23 changes: 21 additions & 2 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cargo_test_support::registry::{Package, TestRegistry};
use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, Project};
use std::fs;
use std::fs::{self, read_to_string};

fn toml_bin(proj: &Project, name: &str) -> String {
proj.bin(name).display().to_string().replace('\\', "\\\\")
Expand Down Expand Up @@ -168,7 +168,22 @@ fn get_token_test() -> (Project, TestRegistry) {
let cred_proj = project()
.at("cred_proj")
.file("Cargo.toml", &basic_manifest("test-cred", "1.0.0"))
.file("src/main.rs", r#"fn main() { println!("sekrit"); } "#)
.file(
"src/main.rs",
r#"
use std::fs::File;
use std::io::Write;
fn main() {
let mut f = File::options()
.write(true)
.create(true)
.append(true)
.open("runs.log")
.unwrap();
write!(f, "+");
println!("sekrit");
} "#,
)
.build();
cred_proj.cargo("build").run();

Expand Down Expand Up @@ -209,6 +224,7 @@ fn publish() {

p.cargo("publish --no-verify --registry alternative -Z credential-process")
.masquerade_as_nightly_cargo(&["credential-process"])
.stream()
.with_stderr(
"\
[UPDATING] [..]
Expand All @@ -219,6 +235,9 @@ fn publish() {
",
)
.run();

let calls = read_to_string(p.root().join("runs.log")).unwrap().len();
assert_eq!(calls, 1);
}

#[cargo_test]
Expand Down

0 comments on commit 16177ba

Please sign in to comment.