Repository: mozilla/cargo-vet
Pull request #468 (2023-05-08 19:31:44)

Show full publisher name when displaying trust hints


Patch:
diff --git a/src/format.rs b/src/format.rs
index e0598fd..b56ce83 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -1035,6 +1035,15 @@ pub struct PublisherCacheUser {
     pub login: String,
     pub name: Option<String>,
 }
+impl fmt::Display for PublisherCacheUser {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if let Some(name) = &self.name {
+            write!(f, "{} ({})", name, &self.login)
+        } else {
+            write!(f, "{}", &self.login)
+        }
+    }
+}
 
 #[derive(Serialize, Deserialize, Debug, Clone)]
 pub struct PublisherCacheVersion {
diff --git a/src/resolver.rs b/src/resolver.rs
index 562f626..06135b5 100644
--- a/src/resolver.rs
+++ b/src/resolver.rs
@@ -58,7 +58,7 @@ use crate::format::{
     ExemptedDependency, FastMap, FastSet, ImportName, ImportsFile, JsonPackage, JsonReport,
     JsonReportConclusion, JsonReportFailForVet, JsonReportFailForViolationConflict,
     JsonReportSuccess, JsonSuggest, JsonSuggestItem, JsonVetFailure, PackageName, PackageStr,
-    Policy, VetVersion, WildcardEntry,
+    Policy, PublisherCacheUser, VetVersion, WildcardEntry,
 };
 use crate::format::{SortedMap, SortedSet};
 use crate::network::Network;
@@ -142,7 +142,7 @@ pub struct Suggest {
 #[derive(Debug, Clone)]
 pub struct TrustHint {
     trusted_by: Vec<String>,
-    publisher: String,
+    publisher: PublisherCacheUser,
     exact_version: bool,
 }
 
@@ -1747,7 +1747,7 @@ impl<'a> ResolveReport<'a> {
                             if trusted_by.iter().any(|s| s == THIS_PROJECT) {
                                 trusted_by.retain(|s| s == THIS_PROJECT);
                             }
-                            let publisher = cache.get_crates_user_info(id).unwrap().login;
+                            let publisher = cache.get_crates_user_info(id).unwrap();
                             TrustHint {
                                 trusted_by,
                                 publisher,
@@ -2208,17 +2208,17 @@ impl Suggest {
                     } else {
                         ""
                     };
-                    let publisher_login = hint.publisher.clone();
+                    let publisher = hint.publisher.clone();
                     let trusted_by = format_short_list(hint.trusted_by.clone());
                     writeln!(
                         out,
                         "      {} {}",
                         dim.clone().apply_to(format_args!(
-                            "NOTE: {trusted_by} {trust} {publisher_login}{caveat} - consider",
+                            "NOTE: {trusted_by} {trust} {publisher}{caveat} - consider",
                         )),
                         if item.is_sole_publisher {
                             let this_cmd = format!("cargo vet trust {}", package.name);
-                            let all_cmd = format!("cargo vet trust --all {}", publisher_login);
+                            let all_cmd = format!("cargo vet trust --all {}", publisher.login);
                             format!(
                                 "{} {} {}",
                                 dim.clone().cyan().apply_to(this_cmd),
@@ -2227,7 +2227,7 @@ impl Suggest {
                             )
                         } else {
                             let cmd =
-                                format!("cargo vet trust {} {}", package.name, publisher_login);
+                                format!("cargo vet trust {} {}", package.name, publisher.login);
                             dim.clone().cyan().apply_to(cmd).to_string()
                         }
                     );
diff --git a/src/serialization.rs b/src/serialization.rs
index 5d316dc..3db3713 100644
--- a/src/serialization.rs
+++ b/src/serialization.rs
@@ -427,12 +427,7 @@ where
             let Some(v) = v.as_value_mut() else { return };
             let Some(user_id) = v.as_integer() else { return };
             let Some(info) = user_info.get(&(user_id as u64)) else { return };
-            let detail = if let Some(name) = &info.name {
-                format!("{} ({})", name, info.login)
-            } else {
-                info.login.clone()
-            };
-            v.decor_mut().set_suffix(format!(" # {}", detail));
+            v.decor_mut().set_suffix(format!(" # {}", info));
         }
     }
     impl VisitMut for TomlFormatter<'_> {


Test patch:
diff --git a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import.snap b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import.snap
index b41c853..bf58380 100644
--- a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import.snap
+++ b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import.snap
@@ -10,7 +10,7 @@ Vetting Failed!
 recommended audits for safe-to-deploy:
     Command                                           Publisher  Used By       Audit Size
     cargo vet inspect transitive-third-party1 10.0.0  testuser   third-party1  100 lines
-      NOTE: peer-company trusts testuser - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
+      NOTE: peer-company trusts Test user (testuser) - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
 
 estimated audit backlog: 100 lines
 
diff --git a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import_multiple.snap b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import_multiple.snap
index bb3f3a1..faf65f6 100644
--- a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import_multiple.snap
+++ b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_import_multiple.snap
@@ -10,7 +10,7 @@ Vetting Failed!
 recommended audits for safe-to-deploy:
     Command                                           Publisher  Used By       Audit Size
     cargo vet inspect transitive-third-party1 10.0.0  testuser   third-party1  100 lines
-      NOTE: peer-company and rival-company trust testuser - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
+      NOTE: peer-company and rival-company trust Test user (testuser) - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
 
 estimated audit backlog: 100 lines
 
diff --git a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local.snap b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local.snap
index f311ef5..8515e97 100644
--- a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local.snap
+++ b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local.snap
@@ -10,7 +10,7 @@ Vetting Failed!
 recommended audits for safe-to-deploy:
     Command                                           Publisher  Used By       Audit Size
     cargo vet inspect transitive-third-party1 10.0.0  testuser   third-party1  100 lines
-      NOTE: this project trusts testuser - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
+      NOTE: this project trusts Test user (testuser) - consider cargo vet trust transitive-third-party1 or cargo vet trust --all testuser
 
 estimated audit backlog: 100 lines
 
diff --git a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local_ambiguous.snap b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local_ambiguous.snap
index a39c192..5939218 100644
--- a/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local_ambiguous.snap
+++ b/src/tests/snapshots/cargo_vet__tests__trusted__trusted_suggest_local_ambiguous.snap
@@ -10,7 +10,7 @@ Vetting Failed!
 recommended audits for safe-to-deploy:
     Command                                           Publisher  Used By       Audit Size
     cargo vet inspect transitive-third-party1 10.0.0  testuser   third-party1  100 lines
-      NOTE: this project trusts testuser - consider cargo vet trust transitive-third-party1 testuser
+      NOTE: this project trusts Test user (testuser) - consider cargo vet trust transitive-third-party1 testuser
 
 estimated audit backlog: 100 lines
 
diff --git a/tests/snapshots/test_cli__test-project-suggest.snap b/tests/snapshots/test_cli__test-project-suggest.snap
index e2a6af1..55f0fdd 100644
--- a/tests/snapshots/test_cli__test-project-suggest.snap
+++ b/tests/snapshots/test_cli__test-project-suggest.snap
@@ -11,7 +11,7 @@ recommended audits for safe-to-deploy:
     cargo vet inspect try-lock 0.2.3                      seanmonstar    want                                                 380 lines
     cargo vet inspect openssl-probe 0.1.5                 alexcrichton   native-tls                                           442 lines
     cargo vet inspect tower-service 0.3.1                 davidpdrsn     hyper                                                501 lines
-      NOTE: this project trusts hawkw, who published another version of this crate - consider cargo vet trust tower-service hawkw
+      NOTE: this project trusts Eliza Weisman (hawkw), who published another version of this crate - consider cargo vet trust tower-service hawkw
     cargo vet inspect wasm-bindgen-shared 0.2.80          alexcrichton   wasm-bindgen-backend and wasm-bindgen-macro-support  515 lines
     cargo vet inspect pin-utils 0.1.0                     cramertj       futures-util                                         538 lines
     cargo vet inspect futures-sink 0.3.21                 taiki-e        h2 and tokio-util                                    544 lines
@@ -58,7 +58,7 @@ recommended audits for safe-to-deploy:
     cargo vet inspect winreg 0.10.1                       gentoo90       reqwest                                              3920 lines
     cargo vet inspect core-foundation 0.9.3               jrmuizel       security-framework                                   3953 lines
     cargo vet inspect tracing-attributes 0.1.20           hawkw          tracing                                              3957 lines
-      NOTE: this project trusts hawkw - consider cargo vet trust tracing-attributes or cargo vet trust --all hawkw
+      NOTE: this project trusts Eliza Weisman (hawkw) - consider cargo vet trust tracing-attributes or cargo vet trust --all hawkw
     cargo vet inspect ipnet 2.4.0                         krisprice      reqwest                                              3973 lines
     cargo vet inspect futures-channel 0.3.21              taiki-e        hyper                                                3992 lines
     cargo vet inspect tempfile 3.3.0                      Stebalien      native-tls                                           4059 lines
@@ -72,7 +72,7 @@ recommended audits for safe-to-deploy:
     cargo vet inspect socket2 0.4.4                       Thomasdezeeuw  hyper and tokio                                      6011 lines
     cargo vet inspect pin-project-lite 0.2.8              taiki-e        hyper, tokio, reqwest, and 4 others                  6100 lines
     cargo vet inspect tracing-core 0.1.25                 hawkw          tracing                                              6156 lines
-      NOTE: this project trusts hawkw - consider cargo vet trust tracing-core or cargo vet trust --all hawkw
+      NOTE: this project trusts Eliza Weisman (hawkw) - consider cargo vet trust tracing-core or cargo vet trust --all hawkw
     cargo vet inspect cc 1.0.73                           alexcrichton   openssl-sys                                          6554 lines
     cargo vet inspect httparse 1.7.0                      seanmonstar    hyper                                                7258 lines
     cargo vet inspect memchr 2.4.1                        BurntSushi     tokio and os_str_bytes                               8712 lines
@@ -84,7 +84,7 @@ recommended audits for safe-to-deploy:
     cargo vet inspect mio 0.8.2                           Thomasdezeeuw  tokio                                                11719 lines
     cargo vet inspect js-sys 0.3.57                       alexcrichton   reqwest, web-sys, and wasm-bindgen-futures           12874 lines
     cargo vet inspect tokio-util 0.7.1                    Darksonn       h2                                                   13870 lines
-      NOTE: this project trusts hawkw, who published another version of this crate - consider cargo vet trust tokio-util hawkw
+      NOTE: this project trusts Eliza Weisman (hawkw), who published another version of this crate - consider cargo vet trust tokio-util hawkw
     cargo vet inspect hashbrown 0.11.2                    Amanieu        indexmap                                             14603 lines
     cargo vet inspect url 2.2.2                           valenting      reqwest                                              16344 lines
     cargo vet inspect tinyvec 1.5.1                       Lokathor       unicode-normalization                                16751 lines
@@ -102,7 +102,7 @@ recommended audits for safe-to-deploy:
     cargo vet inspect idna 0.2.3                          SimonSapin     url                                                  32532 lines
     cargo vet inspect vcpkg 0.2.15                        waych          openssl-sys                                          42642 lines
     cargo vet inspect tokio 1.17.0                        hawkw          h2, hyper, reqwest, and 4 others                     91271 lines
-      NOTE: this project trusts hawkw - consider cargo vet trust tokio hawkw
+      NOTE: this project trusts Eliza Weisman (hawkw) - consider cargo vet trust tokio hawkw
     cargo vet inspect libc 0.2.123                        Amanieu        mio, atty, tokio, openssl, and 8 others              94060 lines
     cargo vet inspect winapi 0.3.9                        retep998       mio, atty, miow, ntapi, and 7 others                 181323 lines
     cargo vet inspect web-sys 0.3.57                      alexcrichton   reqwest and wasm-bindgen-futures                     197013 lines