From 905a06111cf4f7ac041bcc61ea5449dad4b0a9e3 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 7 Apr 2025 13:38:04 -0400 Subject: [PATCH] Added test for checking for wrong hashed password --- src/hashing/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index a3fbbd4..83e7806 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -81,4 +81,30 @@ mod tests { } } } + + #[test] + fn test_wrong_password() { + let some_password = String::from("somethingrandom"); + let salt = generate_salt().unwrap(); + match hash_password(&some_password, &salt) { + Ok(p) => { + match verify_password(&some_password, p.clone()) { + Ok(res) => { + assert_eq!(res, true, "Passwords are not verified"); + let wrong_password = String::from("Differentanotherlevel"); + // wrong_password = some_password; + // let hashed_wrong_password = hash_password(&wrong_password, &salt).unwrap(); + let result = verify_password(&wrong_password, p.clone()).unwrap(); + assert_eq!(false, result, "Passwords should not match"); + } + Err(err) => { + assert!(false, "Error: {:?}", err.to_string()); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err.to_string()); + } + } + } }