Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Update to Rust 2024 Edition. ([#588](https://github.com/fastly/Viceroy/pull/588))
- Add stub implementations for bot detection hostcalls. ([#592](https://github.com/fastly/Viceroy/pull/592))
- Add no-op implementations for stale-if-error hostcalls ([#591](https://github.com/fastly/Viceroy/pull/591))
- Add `manifest_version` validation to fastly.toml parsing. ([#590](https://github.com/fastly/Viceroy/pull/590))

## 0.16.4 (2026-01-26)

Expand Down
32 changes: 8 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ regex = "^1.3.9"
rustls = "^0.21.1"
rustls-native-certs = "^0.6.3"
rustls-pemfile = "^1.0.3"
semver = "^0.10.0"
serde = "^1.0.145"
serde_derive = "^1.0.114"
serde_json = { workspace = true }
Expand Down
32 changes: 8 additions & 24 deletions cli/tests/trap-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl FromStr for FastlyConfig {
/// [fromt-str]: https://docs.rs/toml/latest/toml/de/fn.from_str.html
#[derive(Deserialize)]
struct TomlFastlyConfig {
manifest_version: Option<u32>,
local_server: Option<RawLocalServerConfig>,
// AJT 2020.03.10: the following fields are marked as optional because, for the time being,
// we are not expecting to actually use the fastly.toml manifest, but instead use a separate
Expand All @@ -175,16 +176,30 @@ struct TomlFastlyConfig {
language: Option<String>,
}

/// Manifest versions greater than this are not yet supported.
const MAX_MANIFEST_VERSION: u32 = 3;

impl TryInto<FastlyConfig> for TomlFastlyConfig {
type Error = FastlyConfigError;
fn try_into(self) -> Result<FastlyConfig, Self::Error> {
let Self {
manifest_version,
name,
description,
authors,
language,
local_server,
} = self;

if let Some(manifest_version) = manifest_version {
if manifest_version > MAX_MANIFEST_VERSION {
return Err(FastlyConfigError::UnsupportedManifestVersion(
manifest_version,
MAX_MANIFEST_VERSION,
));
}
}

let local_server = local_server
.map(TryInto::try_into)
.transpose()?
Expand Down
23 changes: 20 additions & 3 deletions src/config/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn fastly_toml_files_can_be_read() {
fn fastly_toml_files_with_simple_backend_configurations_can_be_read() {
let config = FastlyConfig::from_str(
r#"
manifest_version = "1.2.3"
manifest_version = 3
name = "backend-config-example"
description = "a toml example with backend configuration"
authors = [
Expand Down Expand Up @@ -111,7 +111,7 @@ fn fastly_toml_files_with_simple_dictionary_configurations_can_be_read() {
writeln!(file, "{{}}").unwrap();
let config = FastlyConfig::from_str(format!(
r#"
manifest_version = "1.2.3"
manifest_version = 3
name = "dictionary-config-example"
description = "a toml example with dictionary configuration"
authors = [
Expand Down Expand Up @@ -150,7 +150,7 @@ fn fastly_toml_files_with_simple_config_store_configurations_can_be_read() {
writeln!(file, "{{}}").unwrap();
let config = FastlyConfig::from_str(format!(
r#"
manifest_version = "1.2.3"
manifest_version = 3
name = "dictionary-config-example"
description = "a toml example with config store configuration"
authors = [
Expand Down Expand Up @@ -1216,3 +1216,20 @@ Qq7tJAMLnPnAdAUousI0RDcLpB8adGkhZH66lL4oV9U+aQ0dA0oiqSKZtMoHeWbr
assert_eq!(3, shark_backend.ca_certs.len());
}
}

#[test]
fn fastly_toml_files_with_unsupported_manifest_version() {
let err = FastlyConfig::from_str(
r#"
manifest_version = 4
name = "backend-config-example"
language = "rust"
"#,
)
.expect_err("an unsupported manifest_version should have evoked an error");

assert!(matches!(
err,
FastlyConfigError::UnsupportedManifestVersion(4, 3)
));
}
12 changes: 4 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,10 @@ pub enum FastlyConfigError {
#[error("error parsing `fastly.toml`: {0}")]
InvalidFastlyToml(#[from] toml::de::Error),

/// An error caused by an invalid manifest version.
///
/// This means that the provided version is not compliant with the semver spec. See the
/// documentation of [`semver::Version::parse`][parse-errors] for more information.
///
/// [parse-errors]: https://docs.rs/semver/latest/semver/struct.Version.html#errors
#[error("invalid manifest version: {0}")]
InvalidManifestVersion(#[from] semver::SemVerError),
/// The `manifest_version` field contained a value greater than is
/// currently supported.
#[error("unsupported manifest version {0}; max supported version is {1}")]
UnsupportedManifestVersion(u32, u32),
}

/// Errors that may occur while validating acl configurations.
Expand Down
Loading