use microvms_core::provision::{
self, ASSET, Bundles, GitHubRelease, HttpsFetch, ReleaseSource, Request, Source, Verification,
};
#[test]
#[ignore = "needs network: downloads the public GitHub release; no AWS and no credentials"]
fn the_real_release_is_fetched_and_verified_by_attestation() {
let version = std::env::var("MICROVM_RELEASE_VERSION")
.unwrap_or_else(|_| microvms_core::VERSION.to_string());
let state = tempfile::tempdir().expect("a temp dir");
let request = Request {
version: Some(&version),
state_dir: Some(state.path()),
binary: None,
};
let no_env = |_: &str| None;
let provisioned = provision::resolve(
&request,
&no_env,
&HttpsFetch::from_env(&no_env),
&mut |line| eprintln!("PROVISION {line}"),
)
.expect("the release fetches and verifies");
eprintln!(
"PROVISION source={} verified={:?} sha256={} bytes={}",
provisioned.source.as_str(),
provisioned.verification().map(Verification::as_str),
provisioned.sha256,
provisioned.bytes.len()
);
assert_eq!(
provisioned.source,
Source::Fetched(Verification::Attestation)
);
assert_eq!(
provision::elf_machine(&provisioned.bytes),
Some(provision::REQUIRED_ELF_MACHINE)
);
let tag = format!("v{}", version.trim_start_matches('v'));
let sums = GitHubRelease::new(None)
.checksums(&tag)
.expect("the release publishes SHA256SUMS");
provision::verify_sha256(&sums, ASSET, &provisioned.bytes)
.expect("the attested bytes match the release's SHA256SUMS");
}
#[test]
#[ignore = "needs network: two attestations API requests; no AWS and no credentials"]
fn the_api_answers_for_a_release_without_its_bundle_asset() {
let release = GitHubRelease::new(None);
let bytes = release
.asset("v0.4.0", ASSET)
.expect("v0.4.0 has an agentd");
let digest = provision::sha256_hex(&bytes);
let found = release.attestations("v0.4.0", &digest);
let Bundles::Published(bundles) = &found else {
panic!("the API lists v0.4.0's attestation: {found:?}")
};
assert!(!bundles.is_empty());
eprintln!("PROVISION v0.4.0 API bundles={}", bundles.len());
let found = release.attestations("v0.4.0", &"0".repeat(64));
assert!(matches!(found, Bundles::Absent(_)), "{found:?}");
}