diff options
author | khai96_ <hvksmr1996@gmail.com> | 2019-04-19 19:59:29 +0000 |
---|---|---|
committer | khai96_ <hvksmr1996@gmail.com> | 2019-04-19 19:59:29 +0000 |
commit | b57f0db13f5d2d55fb6ae2942279896fd3922586 (patch) | |
tree | 2ca082e389a2031f2ee0b5dc719ba843525c4c37 | |
parent | Correct error message (diff) | |
download | miniserve-b57f0db13f5d2d55fb6ae2942279896fd3922586.tar.gz miniserve-b57f0db13f5d2d55fb6ae2942279896fd3922586.zip |
Add tests for where parse_auth fails
-rw-r--r-- | src/args.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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 |