Repository: mozilla/cargo-vet
Pull request #428 (2023-03-07 16:58:48)

Fix wildcard audits from the network being considered non-fresh by default


Patch:
diff --git a/src/storage.rs b/src/storage.rs
index ff214ae..5cddaa1 100644
--- a/src/storage.rs
+++ b/src/storage.rs
@@ -726,6 +726,13 @@ fn process_imported_audits(
         for audit_entry in audits_file.audits.values_mut().flat_map(|v| v.iter_mut()) {
             audit_entry.is_fresh_import = true;
         }
+        for audit_entry in audits_file
+            .wildcard_audits
+            .values_mut()
+            .flat_map(|v| v.iter_mut())
+        {
+            audit_entry.is_fresh_import = true;
+        }
 
         // If we have an existing audits file for these imports, compare against it.
         if let Some(existing_audits_file) = imports_lock.audits.get(&import_name) {


Test patch:
diff --git a/src/tests/import.rs b/src/tests/import.rs
index b6bc768..21b2740 100644
--- a/src/tests/import.rs
+++ b/src/tests/import.rs
@@ -137,7 +137,18 @@ fn existing_peer_skip_import() {
 
     let new_foreign_audits = AuditsFile {
         criteria: SortedMap::new(),
-        wildcard_audits: SortedMap::new(),
+        wildcard_audits: [
+            (
+                "third-party2".to_owned(),
+                vec![wildcard_audit(1, SAFE_TO_DEPLOY)],
+            ),
+            (
+                "unused-package".to_owned(),
+                vec![wildcard_audit(1, SAFE_TO_DEPLOY)],
+            ),
+        ]
+        .into_iter()
+        .collect(),
         audits: [
             (
                 "third-party2".to_owned(),
@@ -168,11 +179,32 @@ fn existing_peer_skip_import() {
 
     let mut network = Network::new_mock();
     network.mock_serve_toml(FOREIGN_URL, &new_foreign_audits);
+    network.mock_serve_json(
+        "https://crates.io/api/v1/crates/third-party2",
+        &serde_json::json!({
+            "versions": [
+                {
+                    "crate": "third-party2",
+                    "created_at": "2022-12-12T04:51:37.251648+00:00",
+                    "num": "10.0.0",
+                    "published_by": {
+                        "id": 1,
+                        "login": "user1",
+                        "name": "User One",
+                        "url": "https://github.com/user1"
+                    }
+                }
+            ]
+        }),
+    );
 
     let store = Store::mock_online(&cfg, config, audits, imports, &network, true).unwrap();
 
     let output = get_imports_file_changes_prune(&metadata, &store);
-    insta::assert_snapshot!(output);
+    insta::assert_snapshot!("existing_peer_skip_import", output);
+
+    let output = get_imports_file_changes_noprune(&metadata, &store);
+    insta::assert_snapshot!("existing_peer_skip_import_noprune", output);
 }
 
 #[test]
diff --git a/src/tests/snapshots/cargo_vet__tests__import__existing_peer_skip_import_noprune.snap b/src/tests/snapshots/cargo_vet__tests__import__existing_peer_skip_import_noprune.snap
new file mode 100644
index 0000000..c24bb39
--- /dev/null
+++ b/src/tests/snapshots/cargo_vet__tests__import__existing_peer_skip_import_noprune.snap
@@ -0,0 +1,7 @@
+---
+source: src/tests/import.rs
+expression: output
+---
+ 
+ [audits.peer-company.audits]
+