Skip to content

Commit 85923ca

Browse files
committed
rust: validation of release assets upload
Just a spot check of SHA256SUM content. But this is enough to detect the issue from the Octocrab upgrade and it would have prevented me from releasing a bad release. Related to #172.
1 parent d0a0bb0 commit 85923ca

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/github.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,32 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
414414
&client,
415415
&release,
416416
"SHA256SUMS".to_string(),
417-
shasums.into_bytes(),
417+
shasums.clone().into_bytes(),
418418
dry_run,
419419
)
420420
.await?;
421421

422+
// Check that content wasn't munged as part of uploading. This once happened
423+
// and created a busted release. Never again.
424+
let release = releases
425+
.get_by_tag(tag)
426+
.await
427+
.map_err(|_| anyhow!("could not find release; this should not happen!"))?;
428+
let shasums_asset = release
429+
.assets
430+
.into_iter()
431+
.find(|x| x.name == "SHA256SUMS")
432+
.ok_or_else(|| anyhow!("unable to find SHA256SUMs release asset"))?;
433+
434+
let asset_bytes = client
435+
.execute(client.request_builder(shasums_asset.browser_download_url, reqwest::Method::GET))
436+
.await?
437+
.bytes()
438+
.await?;
439+
440+
if shasums != asset_bytes {
441+
return Err(anyhow!("SHA256SUM content mismatch; release might be bad!"));
442+
}
443+
422444
Ok(())
423445
}

0 commit comments

Comments
 (0)