Enable strict config parsing.

This commit is contained in:
Tomasz Drwięga 2018-01-03 10:51:39 +01:00
parent 6a01113610
commit e439eae54f
No known key found for this signature in database
GPG Key ID: D066F497E62CAF66
3 changed files with 30 additions and 5 deletions

View File

@ -28,7 +28,7 @@ extern crate memory_cache;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[cfg_attr(feature = "evm-debug", macro_use)]
extern crate log; extern crate log;
#[cfg(feature = "jit")] #[cfg(feature = "jit")]

View File

@ -994,6 +994,7 @@ struct Config {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Operating { struct Operating {
mode: Option<String>, mode: Option<String>,
mode_timeout: Option<u64>, mode_timeout: Option<u64>,
@ -1013,6 +1014,7 @@ struct Operating {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Account { struct Account {
unlock: Option<Vec<String>>, unlock: Option<Vec<String>>,
password: Option<Vec<String>>, password: Option<Vec<String>>,
@ -1023,6 +1025,7 @@ struct Account {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ui { struct Ui {
force: Option<bool>, force: Option<bool>,
disable: Option<bool>, disable: Option<bool>,
@ -1033,6 +1036,7 @@ struct Ui {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Network { struct Network {
warp: Option<bool>, warp: Option<bool>,
port: Option<u16>, port: Option<u16>,
@ -1052,6 +1056,7 @@ struct Network {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Rpc { struct Rpc {
disable: Option<bool>, disable: Option<bool>,
port: Option<u16>, port: Option<u16>,
@ -1064,6 +1069,7 @@ struct Rpc {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ws { struct Ws {
disable: Option<bool>, disable: Option<bool>,
port: Option<u16>, port: Option<u16>,
@ -1074,6 +1080,7 @@ struct Ws {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ipc { struct Ipc {
disable: Option<bool>, disable: Option<bool>,
path: Option<String>, path: Option<String>,
@ -1081,6 +1088,7 @@ struct Ipc {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Dapps { struct Dapps {
disable: Option<bool>, disable: Option<bool>,
port: Option<u16>, port: Option<u16>,
@ -1093,6 +1101,7 @@ struct Dapps {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct SecretStore { struct SecretStore {
disable: Option<bool>, disable: Option<bool>,
disable_http: Option<bool>, disable_http: Option<bool>,
@ -1109,6 +1118,7 @@ struct SecretStore {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ipfs { struct Ipfs {
enable: Option<bool>, enable: Option<bool>,
port: Option<u16>, port: Option<u16>,
@ -1118,6 +1128,7 @@ struct Ipfs {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Mining { struct Mining {
author: Option<String>, author: Option<String>,
engine_signer: Option<String>, engine_signer: Option<String>,
@ -1150,6 +1161,7 @@ struct Mining {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Stratum { struct Stratum {
interface: Option<String>, interface: Option<String>,
port: Option<u16>, port: Option<u16>,
@ -1157,6 +1169,7 @@ struct Stratum {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Footprint { struct Footprint {
tracing: Option<String>, tracing: Option<String>,
pruning: Option<String>, pruning: Option<String>,
@ -1175,16 +1188,19 @@ struct Footprint {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Snapshots { struct Snapshots {
disable_periodic: Option<bool>, disable_periodic: Option<bool>,
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct VM { struct VM {
jit: Option<bool>, jit: Option<bool>,
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Misc { struct Misc {
ntp_servers: Option<Vec<String>>, ntp_servers: Option<Vec<String>>,
logging: Option<String>, logging: Option<String>,
@ -1195,6 +1211,7 @@ struct Misc {
} }
#[derive(Default, Debug, PartialEq, Deserialize)] #[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Whisper { struct Whisper {
enabled: Option<bool>, enabled: Option<bool>,
pool_size: Option<usize>, pool_size: Option<usize>,
@ -1642,11 +1659,17 @@ mod tests {
let config1 = Args::parse_config(include_str!("./tests/config.invalid1.toml")); let config1 = Args::parse_config(include_str!("./tests/config.invalid1.toml"));
let config2 = Args::parse_config(include_str!("./tests/config.invalid2.toml")); let config2 = Args::parse_config(include_str!("./tests/config.invalid2.toml"));
let config3 = Args::parse_config(include_str!("./tests/config.invalid3.toml")); let config3 = Args::parse_config(include_str!("./tests/config.invalid3.toml"));
let config4 = Args::parse_config(include_str!("./tests/config.invalid4.toml"));
match (config1, config2, config3) { match (config1, config2, config3, config4) {
(Err(ArgsError::Decode(_)), Err(ArgsError::Decode(_)), Err(ArgsError::Decode(_))) => {}, (
(a, b, c) => { Err(ArgsError::Decode(_)),
assert!(false, "Got invalid error types: {:?}, {:?}, {:?}", a, b, c); Err(ArgsError::Decode(_)),
Err(ArgsError::Decode(_)),
Err(ArgsError::Decode(_)),
) => {},
(a, b, c, d) => {
assert!(false, "Got invalid error types: {:?}, {:?}, {:?}, {:?}", a, b, c, d);
} }
} }
} }

View File

@ -0,0 +1,2 @@
[account]
invalid = 5