From b6adac1a6b2786e5beeee56d31732046da5b7ca3 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Wed, 21 Dec 2022 21:46:18 +0000 Subject: [PATCH] count calls to credential process --- src/cargo/util/auth.rs | 4 ++-- tests/testsuite/credential_process.rs | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cargo/util/auth.rs b/src/cargo/util/auth.rs index 25f912cd4..0235f517a 100644 --- a/src/cargo/util/auth.rs +++ b/src/cargo/util/auth.rs @@ -429,7 +429,7 @@ fn auth_token_optional( } }; - if mutation.is_none() { + if independent_of_endpoint || mutation.is_none() { cache.insert( url.clone(), CredentialCacheValue { @@ -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", diff --git a/tests/testsuite/credential_process.rs b/tests/testsuite/credential_process.rs index 92a038179..cd1794bda 100644 --- a/tests/testsuite/credential_process.rs +++ b/tests/testsuite/credential_process.rs @@ -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('\\', "\\\\") @@ -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(); @@ -219,6 +234,9 @@ fn publish() { ", ) .run(); + + let calls = read_to_string(p.root().join("runs.log")).unwrap().len(); + assert_eq!(calls, 1); } #[cargo_test]