Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #535 from cgwalters/tar-opts-nonexhaustive
Browse files Browse the repository at this point in the history
A story in which `#[non_exhaustive]` is discovered
  • Loading branch information
cgwalters authored Sep 11, 2023
2 parents f148ec5 + 258e04a commit 2781808
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 46 deletions.
1 change: 1 addition & 0 deletions lib/src/container/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const STATEROOT_DEFAULT: &str = "default";

/// Options configuring deployment.
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct DeployOpts<'a> {
/// Kernel arguments to use.
pub kargs: Option<&'a [&'a str]>,
Expand Down
1 change: 1 addition & 0 deletions lib/src/container/encapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ async fn build_impl(

/// Options controlling commit export into OCI
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct ExportOpts {
/// If true, do not perform gzip compression of the tar layers.
pub skip_compression: bool,
Expand Down
1 change: 1 addition & 0 deletions lib/src/tar/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ fn validate_sha256(input: String) -> Result<String> {

/// Configuration for tar import.
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct TarImportOptions {
/// Name of the remote to use for signature verification.
pub remote: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions lib/src/tar/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(crate) fn copy_entry(

/// Configuration for tar layer commits.
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct WriteTarOptions {
/// Base ostree commit hash
pub base: Option<String>,
Expand Down
65 changes: 19 additions & 46 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,9 @@ async fn test_tar_import_signed() -> Result<()> {

// Verify we fail with an unknown remote.
let src_tar = tokio::fs::File::from_std(fixture.dir.open(test_tar)?.into_std());
let r = ostree_ext::tar::import_tar(
fixture.destrepo(),
src_tar,
Some(TarImportOptions {
remote: Some("nosuchremote".to_string()),
}),
)
.await;
let mut taropts = TarImportOptions::default();
taropts.remote = Some("nosuchremote".to_string());
let r = ostree_ext::tar::import_tar(fixture.destrepo(), src_tar, Some(taropts)).await;
assert_err_contains(r, r#"Remote "nosuchremote" not found"#);

// Test a remote, but without a key
Expand All @@ -124,14 +119,9 @@ async fn test_tar_import_signed() -> Result<()> {
.destrepo()
.remote_add("myremote", None, Some(&opts.end()), gio::Cancellable::NONE)?;
let src_tar = tokio::fs::File::from_std(fixture.dir.open(test_tar)?.into_std());
let r = ostree_ext::tar::import_tar(
fixture.destrepo(),
src_tar,
Some(TarImportOptions {
remote: Some("myremote".to_string()),
}),
)
.await;
let mut taropts = TarImportOptions::default();
taropts.remote = Some("myremote".to_string());
let r = ostree_ext::tar::import_tar(fixture.destrepo(), src_tar, Some(taropts)).await;
assert_err_contains(r, r#"Can't check signature: public key not found"#);

// And signed correctly
Expand All @@ -143,14 +133,9 @@ async fn test_tar_import_signed() -> Result<()> {
.ignore_stdout()
.run()?;
let src_tar = tokio::fs::File::from_std(fixture.dir.open(test_tar)?.into_std());
let imported = ostree_ext::tar::import_tar(
fixture.destrepo(),
src_tar,
Some(TarImportOptions {
remote: Some("myremote".to_string()),
}),
)
.await?;
let mut taropts = TarImportOptions::default();
taropts.remote = Some("myremote".to_string());
let imported = ostree_ext::tar::import_tar(fixture.destrepo(), src_tar, Some(taropts)).await?;
let (commitdata, state) = fixture.destrepo().load_commit(&imported)?;
assert_eq!(
CONTENTS_CHECKSUM_V0,
Expand All @@ -173,14 +158,9 @@ async fn test_tar_import_signed() -> Result<()> {
})
.await??;
let src_tar = tokio::fs::File::from_std(fixture.dir.open(nometa)?.into_std());
let r = ostree_ext::tar::import_tar(
fixture.destrepo(),
src_tar,
Some(TarImportOptions {
remote: Some("myremote".to_string()),
}),
)
.await;
let mut taropts = TarImportOptions::default();
taropts.remote = Some("myremote".to_string());
let r = ostree_ext::tar::import_tar(fixture.destrepo(), src_tar, Some(taropts)).await;
assert_err_contains(r, "Expected commitmeta object");

// Now inject garbage into the commitmeta by flipping some bits in the signature
Expand Down Expand Up @@ -210,14 +190,9 @@ async fn test_tar_import_signed() -> Result<()> {
})
.await??;
let src_tar = tokio::fs::File::from_std(fixture.dir.open(nometa)?.into_std());
let r = ostree_ext::tar::import_tar(
fixture.destrepo(),
src_tar,
Some(TarImportOptions {
remote: Some("myremote".to_string()),
}),
)
.await;
let mut taropts = TarImportOptions::default();
taropts.remote = Some("myremote".to_string());
let r = ostree_ext::tar::import_tar(fixture.destrepo(), src_tar, Some(taropts)).await;
assert_err_contains(r, "BAD signature");

Ok(())
Expand Down Expand Up @@ -478,12 +453,10 @@ async fn impl_test_container_import_export(chunked: bool) -> Result<()> {
ObjectMetaSized::compute_sizes(fixture.srcrepo(), meta).context("Computing sizes")
})
.transpose()?;
let opts = ExportOpts {
copy_meta_keys: vec!["buildsys.checksum".to_string()],
copy_meta_opt_keys: vec!["nosuchvalue".to_string()],
max_layers: std::num::NonZeroU32::new(PKGS_V0_LEN as u32),
..Default::default()
};
let mut opts = ExportOpts::default();
opts.copy_meta_keys = vec!["buildsys.checksum".to_string()];
opts.copy_meta_opt_keys = vec!["nosuchvalue".to_string()];
opts.max_layers = std::num::NonZeroU32::new(PKGS_V0_LEN as u32);
let digest = ostree_ext::container::encapsulate(
fixture.srcrepo(),
fixture.testref(),
Expand Down

0 comments on commit 2781808

Please sign in to comment.