34 lines
1 KiB
Rust
34 lines
1 KiB
Rust
|
|
use auth::crypto::{hash_password, verify_password};
|
||
|
|
|
||
|
|
#[cfg(test)]
|
||
|
|
mod tests {
|
||
|
|
use super::*;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test_password_hashing() {
|
||
|
|
let password = "test_password_123";
|
||
|
|
let hash = hash_password(password).expect("Failed to hash password");
|
||
|
|
assert!(!hash.is_empty());
|
||
|
|
assert_ne!(hash, password);
|
||
|
|
|
||
|
|
let is_valid = verify_password(password, &hash).expect("Failed to verify password");
|
||
|
|
assert!(is_valid);
|
||
|
|
|
||
|
|
let is_invalid =
|
||
|
|
verify_password("wrong_password", &hash).expect("Failed to verify password");
|
||
|
|
assert!(!is_invalid);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test_empty_password() {
|
||
|
|
let password = "";
|
||
|
|
let hash = hash_password(password).expect("Failed to hash password");
|
||
|
|
// Argon2 allows empty passwords, so we just verify it produces a hash
|
||
|
|
assert!(!hash.is_empty());
|
||
|
|
|
||
|
|
// And verify that verification works
|
||
|
|
let is_valid = verify_password(password, &hash).expect("Failed to verify password");
|
||
|
|
assert!(is_valid);
|
||
|
|
}
|
||
|
|
}
|