From aac70e6607d3e8172f15df91bc16dc3244473ea9 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 26 Apr 2019 17:08:23 +0700 Subject: Comply to change requests - Added doc comments - Added an additional test case --- src/args.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 8f15ea4..97b391f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -38,7 +38,8 @@ struct CLIArgs { )] interfaces: Vec, - /// Set authentication (username:password, username:sha256:hash, or username:sha512:hash) + /// Set authentication. Currently supported formats: + /// username:password, username:sha256:hash, username:sha512:hash #[structopt(short = "a", long = "auth", parse(try_from_str = "parse_auth"))] auth: Option, @@ -88,6 +89,7 @@ fn parse_auth(src: &str) -> Result { None => return invalid_auth_format, }; + // second_part is either password in username:password or method in username:method:hash let second_part = match split.next() { // This allows empty passwords, as the spec does not forbid it Some(password) => password, @@ -169,6 +171,7 @@ mod tests { use super::*; use rstest::rstest_parametrize; + /// Helper function that creates a `RequiredAuth` structure fn create_required_auth(username: &str, password: &str, encrypt: &str) -> auth::RequiredAuth { use auth::*; use RequiredAuthPassword::*; @@ -211,6 +214,10 @@ mod tests { "username:sha256:invalid", "Invalid format for password hash. Expected hex code" ), + case( + "username:sha512:invalid", + "Invalid format for password hash. Expected hex code" + ), )] fn parse_auth_invalid(auth_string: &str, err_msg: &str) { let err = parse_auth(auth_string).unwrap_err(); -- cgit v1.2.3