From 8491520a1b91338127e31de94353e8ceb9f6a337 Mon Sep 17 00:00:00 2001 From: Brian Borge Date: Fri, 15 Nov 2024 10:57:38 -0500 Subject: [PATCH] Deny unknown fields (#272) (#349) --- buildpacks/ruby/src/layers/shared.rs | 1 + buildpacks/ruby/src/main.rs | 1 + commons/src/gemfile_lock.rs | 2 ++ commons/src/metadata_digest.rs | 4 ++++ 4 files changed, 8 insertions(+) diff --git a/buildpacks/ruby/src/layers/shared.rs b/buildpacks/ruby/src/layers/shared.rs index cbb2af4f..58854211 100644 --- a/buildpacks/ruby/src/layers/shared.rs +++ b/buildpacks/ruby/src/layers/shared.rs @@ -207,6 +207,7 @@ mod tests { /// Struct for asserting the behavior of `cached_layer_write_metadata` #[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] + #[serde(deny_unknown_fields)] struct TestMetadata { value: String, } diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 62e42c29..5ad3560a 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -285,6 +285,7 @@ impl From for libcnb::Error { buildpack_main!(RubyBuildpack); #[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PartialEq, Eq)] +#[serde(deny_unknown_fields)] struct BundleWithout(String); impl BundleWithout { diff --git a/commons/src/gemfile_lock.rs b/commons/src/gemfile_lock.rs index e3990753..455222de 100644 --- a/commons/src/gemfile_lock.rs +++ b/commons/src/gemfile_lock.rs @@ -81,6 +81,7 @@ impl GemfileLock { } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +#[serde(deny_unknown_fields)] pub struct ResolvedRubyVersion(pub String); impl Display for ResolvedRubyVersion { @@ -90,6 +91,7 @@ impl Display for ResolvedRubyVersion { } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +#[serde(deny_unknown_fields)] pub struct ResolvedBundlerVersion(pub String); impl Display for ResolvedBundlerVersion { diff --git a/commons/src/metadata_digest.rs b/commons/src/metadata_digest.rs index 1ef09719..2f9ce418 100644 --- a/commons/src/metadata_digest.rs +++ b/commons/src/metadata_digest.rs @@ -148,6 +148,7 @@ const PLATFORM_ENV_VAR: &str = "user configured environment variables"; /// add logic to your buildpack to re-run that command similar to the "escape valve" discussed /// above, but triggered by buildpack author instead of the end user. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)] +#[serde(deny_unknown_fields)] pub struct MetadataDigest { platform_env: Option, files: Option, // Must be last for serde to be happy https://github.com/toml-rs/toml-rs/issues/142 @@ -235,9 +236,11 @@ impl MetadataDigest { } #[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq)] +#[serde(deny_unknown_fields)] struct ShaString(String); #[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq)] +#[serde(deny_unknown_fields)] struct PlatformEnvDigest(ShaString); impl PlatformEnvDigest { fn new(platform: &impl Platform) -> Self { @@ -248,6 +251,7 @@ impl PlatformEnvDigest { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)] +#[serde(deny_unknown_fields)] struct PathsDigest(HashMap); /// Main struct for detecting changes between two iterations