Refactor IAM tests: Remove unused repository tests, streamline service tests, and enhance validation checks for team and user services
This commit is contained in:
@@ -9,3 +9,22 @@ pub fn get_iso_date() -> String {
|
||||
info!(date_str = %date_str, "get_iso_date returning RFC3339 date string");
|
||||
date_str
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use chrono::DateTime;
|
||||
|
||||
#[test]
|
||||
fn test_get_iso_date() {
|
||||
let date_str = get_iso_date();
|
||||
// Should be valid RFC3339
|
||||
let parsed = DateTime::parse_from_rfc3339(&date_str);
|
||||
assert!(parsed.is_ok());
|
||||
// Should be recent (within last second)
|
||||
let now = Utc::now();
|
||||
let parsed = parsed.unwrap().with_timezone(&Utc);
|
||||
let diff = (now - parsed).num_milliseconds().abs();
|
||||
assert!(diff < 1000); // Within 1 second
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,3 +43,45 @@ impl OtpManager {
|
||||
user_hash == stored.hash
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_generate_otp() {
|
||||
let otp = OtpManager::generate_otp();
|
||||
assert!(otp.code >= 100_000 && otp.code < 1_000_000);
|
||||
assert!(!otp.hash.is_empty());
|
||||
assert!(otp.expires_at > Utc::now());
|
||||
assert!(otp.expires_at <= Utc::now() + chrono::Duration::minutes(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_otp_valid() {
|
||||
let otp = OtpManager::generate_otp();
|
||||
assert!(OtpManager::validate_otp(&otp, otp.code));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_otp_invalid_code() {
|
||||
let otp = OtpManager::generate_otp();
|
||||
assert!(!OtpManager::validate_otp(&otp, 123456)); // Wrong code
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_otp_expired() {
|
||||
let mut otp = OtpManager::generate_otp();
|
||||
otp.expires_at = Utc::now() - chrono::Duration::seconds(1); // Expired
|
||||
assert!(!OtpManager::validate_otp(&otp, otp.code));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_otp_uniqueness() {
|
||||
let otp1 = OtpManager::generate_otp();
|
||||
let otp2 = OtpManager::generate_otp();
|
||||
// Codes should be different (high probability)
|
||||
assert_ne!(otp1.code, otp2.code);
|
||||
assert_ne!(otp1.hash, otp2.hash);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user