@@ -10,6 +10,7 @@ use crate::config::Credentials;
1010
1111/// Configuration for the siguldry server.
1212#[ derive( Debug , Clone , Serialize , Deserialize ) ]
13+ #[ serde( deny_unknown_fields) ]
1314pub struct Config {
1415 /// The location where the server should store its state.
1516 ///
@@ -83,6 +84,7 @@ pub struct Config {
8384///
8485/// The user provides the common name to use, all other values are defined here.
8586#[ derive( Debug , Clone , Serialize , Deserialize ) ]
87+ #[ serde( deny_unknown_fields) ]
8688pub struct X509SubjectName {
8789 pub country : String ,
8890 pub state_or_province : String ,
@@ -108,6 +110,7 @@ impl Default for X509SubjectName {
108110/// The server encrypts the secret needed to use a signing key with a user-provided password. It
109111/// then encrypts _that_ with one or more secrets accessible only to the server.
110112#[ derive( Debug , Clone , Serialize , Deserialize , Default ) ]
113+ #[ serde( deny_unknown_fields) ]
111114pub struct Pkcs11Binding {
112115 /// The PEM-encoded X509 certificate to use to encrypt secrets.
113116 pub certificate : PathBuf ,
@@ -193,4 +196,83 @@ mod tests {
193196
194197 Ok ( ( ) )
195198 }
199+
200+ #[ test]
201+ fn pkcs11_bindings_extra_key ( ) -> anyhow:: Result < ( ) > {
202+ let config = r#"
203+ certificate = "cert.pem"
204+ private_key = "pkcs11:token"
205+ other_key = 42
206+ "# ;
207+
208+ if let Err ( error) = toml:: from_str :: < super :: Pkcs11Binding > ( config) {
209+ assert_eq ! (
210+ error. message( ) ,
211+ "unknown field `other_key`, expected `certificate` or `private_key`"
212+ ) ;
213+ } else {
214+ panic ! ( "Config should fail to load" ) ;
215+ }
216+
217+ Ok ( ( ) )
218+ }
219+
220+ #[ test]
221+ fn x509_subject_name_extra_key ( ) -> anyhow:: Result < ( ) > {
222+ let config = r#"
223+ other_key = 42
224+ country = "US"
225+ state_or_province = "Maryland"
226+ locality = "Bethesda"
227+ organization = "Cat Caretaker"
228+ organizational_unit = "Primary Cat Scratcher"
229+ "# ;
230+
231+ if let Err ( error) = toml:: from_str :: < super :: X509SubjectName > ( config) {
232+ assert_eq ! (
233+ error. message( ) ,
234+ "unknown field `other_key`, expected one of \
235+ `country`, `state_or_province`, `locality`, `organization`, `organizational_unit`"
236+ ) ;
237+ } else {
238+ panic ! ( "Config should fail to load" ) ;
239+ }
240+
241+ Ok ( ( ) )
242+ }
243+
244+ #[ test]
245+ fn config_extra_key ( ) -> anyhow:: Result < ( ) > {
246+ let config = r#"
247+ state_directory = "/var/lib/siguldry/"
248+ bridge_hostname = "bridge.example.com"
249+ bridge_port = 44333
250+ connection_pool_size = 16
251+ user_password_length = 64
252+ openpgp_user_id = "Fedora <fedora-openpgp@fedoraproject.org>"
253+ another_key = 42
254+
255+ pkcs11_bindings = []
256+
257+ [credentials]
258+ private_key = "siguldry.server.private_key.pem"
259+ certificate = "/etc/siguldry/server.cert"
260+ ca_certificate = "/etc/siguldry/ca.crt"
261+
262+ [certificate_subject]
263+ country = "US"
264+ state_or_province = "Maryland"
265+ locality = "Bethesda"
266+ organization = "Cat Caretaker"
267+ organizational_unit = "Primary Cat Scratcher"
268+ "# ;
269+
270+ if let Err ( error) = toml:: from_str :: < super :: Config > ( config) {
271+ assert ! ( error. message( ) . contains( "unknown field `another_key`" ) ) ;
272+ } else {
273+ panic ! ( "Config should fail to load" ) ;
274+ }
275+
276+ Ok ( ( ) )
277+ }
196278}
0 commit comments