Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Strict config parsing #7433

Merged
merged 2 commits into from
Jan 3, 2018
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
2 changes: 1 addition & 1 deletion ethcore/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern crate memory_cache;
#[macro_use]
extern crate lazy_static;

#[macro_use]
#[cfg_attr(feature = "evm-debug", macro_use)]
extern crate log;

#[cfg(feature = "jit")]
Expand Down
33 changes: 28 additions & 5 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ struct Config {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Operating {
mode: Option<String>,
mode_timeout: Option<u64>,
Expand All @@ -1013,6 +1014,7 @@ struct Operating {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Account {
unlock: Option<Vec<String>>,
password: Option<Vec<String>>,
Expand All @@ -1023,6 +1025,7 @@ struct Account {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ui {
force: Option<bool>,
disable: Option<bool>,
Expand All @@ -1033,6 +1036,7 @@ struct Ui {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Network {
warp: Option<bool>,
port: Option<u16>,
Expand All @@ -1052,6 +1056,7 @@ struct Network {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Rpc {
disable: Option<bool>,
port: Option<u16>,
Expand All @@ -1064,6 +1069,7 @@ struct Rpc {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ws {
disable: Option<bool>,
port: Option<u16>,
Expand All @@ -1074,13 +1080,15 @@ struct Ws {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ipc {
disable: Option<bool>,
path: Option<String>,
apis: Option<Vec<String>>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Dapps {
disable: Option<bool>,
port: Option<u16>,
Expand All @@ -1093,6 +1101,7 @@ struct Dapps {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct SecretStore {
disable: Option<bool>,
disable_http: Option<bool>,
Expand All @@ -1109,6 +1118,7 @@ struct SecretStore {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Ipfs {
enable: Option<bool>,
port: Option<u16>,
Expand All @@ -1118,6 +1128,7 @@ struct Ipfs {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Mining {
author: Option<String>,
engine_signer: Option<String>,
Expand Down Expand Up @@ -1150,13 +1161,15 @@ struct Mining {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Stratum {
interface: Option<String>,
port: Option<u16>,
secret: Option<String>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Footprint {
tracing: Option<String>,
pruning: Option<String>,
Expand All @@ -1175,16 +1188,19 @@ struct Footprint {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Snapshots {
disable_periodic: Option<bool>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct VM {
jit: Option<bool>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Misc {
ntp_servers: Option<Vec<String>>,
logging: Option<String>,
Expand All @@ -1195,6 +1211,7 @@ struct Misc {
}

#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Whisper {
enabled: Option<bool>,
pool_size: Option<usize>,
Expand Down Expand Up @@ -1642,11 +1659,17 @@ mod tests {
let config1 = Args::parse_config(include_str!("./tests/config.invalid1.toml"));
let config2 = Args::parse_config(include_str!("./tests/config.invalid2.toml"));
let config3 = Args::parse_config(include_str!("./tests/config.invalid3.toml"));

match (config1, config2, config3) {
(Err(ArgsError::Decode(_)), Err(ArgsError::Decode(_)), Err(ArgsError::Decode(_))) => {},
(a, b, c) => {
assert!(false, "Got invalid error types: {:?}, {:?}, {:?}", a, b, c);
let config4 = Args::parse_config(include_str!("./tests/config.invalid4.toml"));

match (config1, config2, config3, config4) {
(
Err(ArgsError::Decode(_)),
Err(ArgsError::Decode(_)),
Err(ArgsError::Decode(_)),
Err(ArgsError::Decode(_)),
) => {},
(a, b, c, d) => {
assert!(false, "Got invalid error types: {:?}, {:?}, {:?}, {:?}", a, b, c, d);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions parity/cli/tests/config.invalid4.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[account]
invalid = 5