From b57f0db13f5d2d55fb6ae2942279896fd3922586 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sat, 20 Apr 2019 02:59:29 +0700 Subject: Add tests for where parse_auth fails --- src/args.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index c749ac4..d42d317 100644 --- a/src/args.rs +++ b/src/args.rs @@ -200,4 +200,31 @@ mod tests { Ok(()) } + + #[test] + fn parse_auth_invalid_syntax() { + assert_eq!( + parse_auth("foo").unwrap_err(), + "Invalid credentials string, expected format is username:password".to_owned() + ); + } + + #[test] + fn parse_auth_invalid_hash_method() { + assert_eq!( + parse_auth("username:blahblah:hash").unwrap_err(), + "Invalid hash method, only accept either sha256 or sha512".to_owned() + ); + } + + #[test] + fn parse_auth_excessive_length() { + let password = &"x".repeat(256); + let param = "username:".to_owned() + password; + + assert_eq!( + parse_auth(&*param).unwrap_err(), + "Password length cannot exceed 255 characters".to_owned() + ); + } } \ No newline at end of file -- cgit v1.2.3