mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 21:46:50 +00:00
test: prune redundant cases and add high-risk coverage across crates (#4208)
Remove or consolidate 57 test cases that cannot catch regressions (literal-constant asserts, construct-then-assert, derived-serde round-trips, near-duplicate env/getter matrices) in common, config, iam, madmin, and object-capacity, keeping all wire-format and error-path guards. Add 13 tests for previously uncovered high-risk behavior: filemeta version-sort determinism and merge resilience to garbage headers, zip extraction path-traversal rejection and exact limit boundaries, JWT tampered-signature rejection, and the bytes variant of dual-key (rustfs/minio) metadata fallback and precedence. Test-only change; no production code touched. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -725,24 +725,6 @@ mod tests {
|
||||
use time::OffsetDateTime;
|
||||
use time::macros::datetime;
|
||||
|
||||
#[test]
|
||||
fn test_account_status_default() {
|
||||
let status = AccountStatus::default();
|
||||
assert_eq!(status, AccountStatus::Disabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_status_as_ref() {
|
||||
assert_eq!(AccountStatus::Enabled.as_ref(), "enabled");
|
||||
assert_eq!(AccountStatus::Disabled.as_ref(), "disabled");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_status_try_from_valid() {
|
||||
assert_eq!(AccountStatus::try_from("enabled").unwrap(), AccountStatus::Enabled);
|
||||
assert_eq!(AccountStatus::try_from("disabled").unwrap(), AccountStatus::Disabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_status_try_from_invalid() {
|
||||
let result = AccountStatus::try_from("invalid");
|
||||
@@ -783,32 +765,6 @@ mod tests {
|
||||
assert_eq!(ldap_json, "\"ldap\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_auth_info_creation() {
|
||||
let auth_info = UserAuthInfo {
|
||||
auth_type: UserAuthType::Ldap,
|
||||
auth_server: Some("ldap.example.com".to_string()),
|
||||
auth_server_user_id: Some("user123".to_string()),
|
||||
};
|
||||
|
||||
assert!(matches!(auth_info.auth_type, UserAuthType::Ldap));
|
||||
assert_eq!(auth_info.auth_server.unwrap(), "ldap.example.com");
|
||||
assert_eq!(auth_info.auth_server_user_id.unwrap(), "user123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_auth_info_serialization() {
|
||||
let auth_info = UserAuthInfo {
|
||||
auth_type: UserAuthType::Builtin,
|
||||
auth_server: None,
|
||||
auth_server_user_id: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&auth_info).unwrap();
|
||||
assert!(json.contains("builtin"));
|
||||
assert!(!json.contains("authServer"), "None fields should be skipped");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_info_default() {
|
||||
let user_info = UserInfo::default();
|
||||
@@ -1020,57 +976,6 @@ mod tests {
|
||||
assert!(json.contains("session123"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_credentials_without_optional_fields() {
|
||||
let credentials = Credentials {
|
||||
access_key: "AKIAIOSFODNN7EXAMPLE",
|
||||
secret_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
|
||||
session_token: None,
|
||||
expiration: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&credentials).unwrap();
|
||||
assert!(json.contains("AKIAIOSFODNN7EXAMPLE"));
|
||||
assert!(!json.contains("sessionToken"), "None fields should be skipped");
|
||||
assert!(!json.contains("expiration"), "None fields should be skipped");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_service_account_resp_creation() {
|
||||
let credentials = Credentials {
|
||||
access_key: "AKIAIOSFODNN7EXAMPLE",
|
||||
secret_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
|
||||
session_token: None,
|
||||
expiration: None,
|
||||
};
|
||||
|
||||
let resp = AddServiceAccountResp { credentials };
|
||||
|
||||
assert_eq!(resp.credentials.access_key, "AKIAIOSFODNN7EXAMPLE");
|
||||
assert_eq!(resp.credentials.secret_key, "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_info_service_account_resp_creation() {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let resp = InfoServiceAccountResp {
|
||||
parent_user: "admin".to_string(),
|
||||
account_status: "enabled".to_string(),
|
||||
implied_policy: true,
|
||||
policy: Some("ReadOnlyAccess".to_string()),
|
||||
name: Some("test-service".to_string()),
|
||||
description: Some("Test service account".to_string()),
|
||||
expiration: Some(now),
|
||||
};
|
||||
|
||||
assert_eq!(resp.parent_user, "admin");
|
||||
assert_eq!(resp.account_status, "enabled");
|
||||
assert!(resp.implied_policy);
|
||||
assert_eq!(resp.policy.unwrap(), "ReadOnlyAccess");
|
||||
assert_eq!(resp.name.unwrap(), "test-service");
|
||||
assert!(resp.expiration.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_service_account_req_validate() {
|
||||
let req = UpdateServiceAccountReq {
|
||||
@@ -1105,22 +1010,6 @@ mod tests {
|
||||
assert_eq!(req.new_policy, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_info_creation() {
|
||||
use crate::BackendInfo;
|
||||
|
||||
let account_info = AccountInfo {
|
||||
account_name: "testuser".to_string(),
|
||||
server: BackendInfo::default(),
|
||||
policy: serde_json::json!({"Version": "2012-10-17"}),
|
||||
buckets: vec![],
|
||||
};
|
||||
|
||||
assert_eq!(account_info.account_name, "testuser");
|
||||
assert!(account_info.buckets.is_empty());
|
||||
assert!(account_info.policy.is_object());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bucket_access_info_creation() {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
|
||||
Reference in New Issue
Block a user