Skip to content

Commit 35ca858

Browse files
committed
chore(node): validate motd len
1 parent e431bc5 commit 35ca858

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tox_node/src/node_config.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ fn app() -> Command {
262262
- start_date: time when the node was started\n\
263263
- uptime: uptime in the format 'XX days XX hours XX minutes'\n")
264264
.num_args(1)
265-
// .validator(|m| {
266-
// if m.len() > BOOSTRAP_SERVER_MAX_MOTD_LENGTH {
267-
// Err(format!("Message of the day must not be longer than {} bytes", BOOSTRAP_SERVER_MAX_MOTD_LENGTH))
268-
// } else {
269-
// Ok(())
270-
// }
271-
// })
265+
.value_parser(|m: &str| {
266+
if m.len() > BOOSTRAP_SERVER_MAX_MOTD_LENGTH {
267+
Err(format!("Message of the day must not be longer than {} bytes", BOOSTRAP_SERVER_MAX_MOTD_LENGTH))
268+
} else {
269+
Ok(m.to_string())
270+
}
271+
})
272272
.default_value("This is tox-rs"))
273273
.arg(Arg::new("lan-discovery")
274274
.long("lan-discovery")
@@ -545,6 +545,21 @@ mod tests {
545545
assert_eq!(config.motd, motd);
546546
}
547547

548+
#[test]
549+
fn args_motd_too_long() {
550+
let motd = "x".repeat(BOOSTRAP_SERVER_MAX_MOTD_LENGTH + 1);
551+
let matches = app().try_get_matches_from(vec![
552+
"tox-node",
553+
"--keys-file",
554+
"./keys",
555+
"--udp-address",
556+
"127.0.0.1:33445",
557+
"--motd",
558+
&motd,
559+
]);
560+
assert!(matches.is_err());
561+
}
562+
548563
#[test]
549564
fn args_lan_discovery() {
550565
let matches = app().get_matches_from(vec![

0 commit comments

Comments
 (0)