Skip to content

Commit

Permalink
rust: validation of release assets upload
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indygreg committed May 14, 2023
1 parent d0a0bb0 commit 85923ca
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,32 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
&client,
&release,
"SHA256SUMS".to_string(),
shasums.into_bytes(),
shasums.clone().into_bytes(),
dry_run,
)
.await?;

// Check that content wasn't munged as part of uploading. This once happened
// and created a busted release. Never again.
let release = releases
.get_by_tag(tag)
.await
.map_err(|_| anyhow!("could not find release; this should not happen!"))?;
let shasums_asset = release
.assets
.into_iter()
.find(|x| x.name == "SHA256SUMS")
.ok_or_else(|| anyhow!("unable to find SHA256SUMs release asset"))?;

let asset_bytes = client
.execute(client.request_builder(shasums_asset.browser_download_url, reqwest::Method::GET))
.await?
.bytes()
.await?;

if shasums != asset_bytes {
return Err(anyhow!("SHA256SUM content mismatch; release might be bad!"));
}

Ok(())
}

0 comments on commit 85923ca

Please sign in to comment.