[PR #2375] [MERGED] Strict parsing of configuration files #2991

Closed
opened 2026-03-16 11:19:19 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hickory-dns/hickory-dns/pull/2375
Author: @divergentdave
Created: 8/22/2024
Status: Merged
Merged: 8/26/2024
Merged by: @djc

Base: mainHead: david/config-deny-unknown-fields


📝 Commits (3)

  • c63c00b Add serde(deny_unknown_fields) to config types
  • 27412a7 Fix error in example config
  • 5bb8800 Add mutation testing of config for unknown fields

📊 Changes

9 files changed (+247 additions, -4 deletions)

View changed files

📝 crates/resolver/src/config.rs (+10 -2)
📝 crates/server/src/config/dnssec.rs (+2 -0)
📝 crates/server/src/config/mod.rs (+2 -0)
📝 crates/server/src/store/file/config.rs (+1 -0)
📝 crates/server/src/store/forwarder/config.rs (+1 -0)
📝 crates/server/src/store/recursor/config.rs (+1 -0)
📝 crates/server/src/store/sqlite/config.rs (+1 -0)
📝 crates/server/tests/config_tests.rs (+227 -0)
📝 tests/test-data/test_configs/example_forwarder.toml (+2 -2)

📄 Description

This PR implements one half of #2195. I added #[serde(deny_unknown_fields)] to all configuration types, which will cause an error if there are any unexpected keys in a table. This turned up one issue in the example forwarder config file.

I also added a test that starts with all config files in tests/test-data/test_configs, mutates them by adding an extra key to each table in turn, and confirms that it gets an "unknown field" error when trying to parse each mutated input. Since #[serde(deny_unknown_fields)] is configured on a type-by-type basis, it can be easy to forget, so this test is intended to help maintain this behavior going forward. It can't discover new tables on its own, but so long as the example/test configuration files have good coverage, it should help.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hickory-dns/hickory-dns/pull/2375 **Author:** [@divergentdave](https://github.com/divergentdave) **Created:** 8/22/2024 **Status:** ✅ Merged **Merged:** 8/26/2024 **Merged by:** [@djc](https://github.com/djc) **Base:** `main` ← **Head:** `david/config-deny-unknown-fields` --- ### 📝 Commits (3) - [`c63c00b`](https://github.com/hickory-dns/hickory-dns/commit/c63c00bd5124c5712f9c527909ddd37c10335f9c) Add serde(deny_unknown_fields) to config types - [`27412a7`](https://github.com/hickory-dns/hickory-dns/commit/27412a79f6e73268f4cee3b9cef1fe356deef8e7) Fix error in example config - [`5bb8800`](https://github.com/hickory-dns/hickory-dns/commit/5bb8800be63bf79ceb139a8af652d01c553ee415) Add mutation testing of config for unknown fields ### 📊 Changes **9 files changed** (+247 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/resolver/src/config.rs` (+10 -2) 📝 `crates/server/src/config/dnssec.rs` (+2 -0) 📝 `crates/server/src/config/mod.rs` (+2 -0) 📝 `crates/server/src/store/file/config.rs` (+1 -0) 📝 `crates/server/src/store/forwarder/config.rs` (+1 -0) 📝 `crates/server/src/store/recursor/config.rs` (+1 -0) 📝 `crates/server/src/store/sqlite/config.rs` (+1 -0) 📝 `crates/server/tests/config_tests.rs` (+227 -0) 📝 `tests/test-data/test_configs/example_forwarder.toml` (+2 -2) </details> ### 📄 Description This PR implements one half of #2195. I added `#[serde(deny_unknown_fields)]` to all configuration types, which will cause an error if there are any unexpected keys in a table. This turned up one issue in the example forwarder config file. I also added a test that starts with all config files in `tests/test-data/test_configs`, mutates them by adding an extra key to each table in turn, and confirms that it gets an "unknown field" error when trying to parse each mutated input. Since `#[serde(deny_unknown_fields)]` is configured on a type-by-type basis, it can be easy to forget, so this test is intended to help maintain this behavior going forward. It can't discover new tables on its own, but so long as the example/test configuration files have good coverage, it should help. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-16 11:19:19 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#2991
No description provided.