GeezerVison is showing github.com — Adapt yarn classic sha1 pins to main's URL redaction and empty-range … · SocketDev/socket-patch@224bd92
File treeExpand file treeCollapse file tree Open diff view settings socket-patch-cli/tests/scan
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: crates/socket-patch-cli/tests/scan/hosted_yarn_classic_sha1.rs +16-5Lines changed: 16 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -225,7 +225,7 @@ async fn issue_558_served_tarball_not_matching_the_grant_skips_the_patch() { | 225 | 225 | write_classic_project(&root); | 226 | 226 |
| 227 | 227 | let (_, doc, stderr) = scan(&root, &server.uri()); | 228 | | - assert_skipped_untouched(&root, &server, &doc, &stderr); | | 228 | + assert_skipped_untouched(&root, &doc, &stderr); | 229 | 229 | } | 230 | 230 |
| 231 | 231 | #[tokio::test] | @@ -238,10 +238,18 @@ async fn issue_558_unfetchable_tarball_skips_the_patch() { | 238 | 238 | write_classic_project(&root); | 239 | 239 |
| 240 | 240 | let (_, doc, stderr) = scan(&root, &server.uri()); | 241 | | - assert_skipped_untouched(&root, &server, &doc, &stderr); | | 241 | + let detail = assert_skipped_untouched(&root, &doc, &stderr); | | 242 | + // The detail still says where the fetch went, with the token redacted. | | 243 | + assert!( | | 244 | + detail.contains(&format!( | | 245 | + "cannot fetch the hosted tarball: artifact not found: {}/patch/npm/left-pad/1.3.0/<redacted>/{UUID}/left-pad-1.3.0.tgz", | | 246 | + server.uri() | | 247 | + )), | | 248 | + "{detail}" | | 249 | + ); | 242 | 250 | } | 243 | 251 |
| 244 | | -fn assert_skipped_untouched(root: &Path, server: &MockServer, doc: &Value, stderr: &str) { | | 252 | +fn assert_skipped_untouched(root: &Path, doc: &Value, stderr: &str) -> String { | 245 | 253 | let skipped: Vec<&Value> = doc["redirect"]["skipped"] | 246 | 254 | .as_array() | 247 | 255 | .unwrap_or_else(|| panic!("redirect.skipped: {doc:#}\n{stderr}")) | @@ -250,17 +258,20 @@ fn assert_skipped_untouched(root: &Path, server: &MockServer, doc: &Value, stder | 250 | 258 | .collect(); | 251 | 259 | assert_eq!(skipped.len(), 1, "{doc:#}"); | 252 | 260 | assert_eq!(skipped[0]["purl"], PURL, "{doc:#}"); | | 261 | + // The served URL's grant token authorizes the org's download: never | | 262 | + // shown, whatever the detail says. | 253 | 263 | let detail = skipped[0]["detail"].as_str().unwrap(); | 254 | 264 | assert!( | 255 | | - !detail.contains(&server.uri()), | 256 | | - "the hosted URL is redacted: {detail}" | | 265 | + !detail.contains(TOKEN), | | 266 | + "the grant token is redacted: {detail}" | 257 | 267 | ); | 258 | 268 | assert_eq!(doc["redirect"]["redirected"], 0, "{doc:#}"); | 259 | 269 | assert_eq!( | 260 | 270 | std::fs::read_to_string(root.join("yarn.lock")).unwrap(), | 261 | 271 | LOCK, | 262 | 272 | "no fragmentless hosted pin is written" | 263 | 273 | ); | | 274 | + detail.to_string() | 264 | 275 | } | 265 | 276 |
| 266 | 277 | /// #591: the served tarball's package.json adds a dependency yarn.lock | |
Collapse file Copy file name to clipboardExpand all lines: crates/socket-patch-core/src/hosted/engine.rs +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1210,8 +1210,8 @@ pub fn record_classic_artifact( | 1210 | 1210 |
| 1211 | 1211 | /// The skip recorded for an npm dep whose served tarball could not be | 1212 | 1212 | /// fetched, did not match its grant's sha512 or had no readable | 1213 | | -/// package.json, so its yarn classic pin could not be checked (the grant | 1214 | | -/// token in `detail` is redacted to `<hosted artifact>`). | | 1213 | +/// package.json, so its yarn classic pin could not be checked (`detail` | | 1214 | +/// redacted by [`redact_artifact_text`]). | 1215 | 1215 | pub fn npm_tarball_unavailable(dep: &DepOverride, detail: &str) -> SkippedPatch { | 1216 | 1216 | SkippedPatch { | 1217 | 1217 | purl: format!( | @@ -1221,7 +1221,11 @@ pub fn npm_tarball_unavailable(dep: &DepOverride, detail: &str) -> SkippedPatch | 1221 | 1221 | ), | 1222 | 1222 | uuid: dep.patch_uuid.clone(), | 1223 | 1223 | reason: "npm_tarball_unavailable".to_string(), | 1224 | | - detail: Some(detail.replace(&dep.artifact_url, "<hosted artifact>")), | | 1224 | + detail: Some(redact_artifact_text( | | 1225 | + detail, | | 1226 | + &dep.artifact_url, | | 1227 | + &dep.patch_uuid, | | 1228 | + )), | 1225 | 1229 | } | 1226 | 1230 | } | 1227 | 1231 |
| |
Collapse file Copy file name to clipboardExpand all lines: crates/socket-patch-core/src/patch/redirect/mod.rs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10819,7 +10819,7 @@ mod tests { | 10819 | 10819 | .unwrap_or_else(|| panic!("{key}: the block must be pinned: {:?}", r.warnings)); | 10820 | 10820 | assert!(out.contains(&format!("\n{key}\n")), "{key}: {out}"); | 10821 | 10821 | assert!( | 10822 | | - out.contains("resolved \"http://p.test/lp.tgz\"") | | 10822 | + out.contains("resolved \"http://p.test/lp.tgz#5ha1\"") | 10823 | 10823 | && out.contains("integrity sha512-PATCHED=="), | 10824 | 10824 | "{key}: {out}" | 10825 | 10825 | ); | |
|