#[test]
fn test_security_results_all_have_names() {
let config = SecurityConfig::default();
let results = run_all_security_tests(&config);
for result in &results {
assert!(
!result.name.is_empty(),
"Result {} has empty name",
result.id
);
}
}
#[test]
fn test_security_results_all_have_details() {
let config = SecurityConfig::default();
let results = run_all_security_tests(&config);
for result in &results {
assert!(
!result.details.is_empty(),
"Result {} has empty details",
result.id
);
}
}
#[test]
fn test_is_path_safe_backslash_traversal() {
assert!(!is_path_safe("..\\etc\\passwd"));
assert!(!is_path_safe("folder\\..\\..\\secret"));
}
#[test]
fn test_n_tests_sequential_ids() {
let config = SecurityConfig::default();
let results = run_all_security_tests(&config);
for (i, result) in results.iter().enumerate() {
let expected_id = format!("N{}", i + 1);
assert_eq!(
result.id, expected_id,
"Expected {} but got {}",
expected_id, result.id
);
}
}
#[test]
fn test_escape_html_no_special_chars() {
let input = "Hello World 123";
assert_eq!(escape_html(input), input);
}
#[test]
fn test_escape_html_unicode() {
assert_eq!(escape_html("héllo wörld"), "héllo wörld");
assert_eq!(escape_html("日本語"), "日本語");
}
#[test]
fn test_security_config_debug_format() {
let config = SecurityConfig::default();
let debug = format!("{:?}", config);
assert!(debug.contains("SecurityConfig"));
assert!(debug.contains("fuzz_duration_secs"));
assert!(debug.contains("max_file_size"));
}
#[test]
fn test_security_result_debug_format() {
let result = SecurityResult::pass("N1", "Test", "Details");
let debug = format!("{:?}", result);
assert!(debug.contains("SecurityResult"));
assert!(debug.contains("passed"));
}
#[test]
fn test_is_path_safe_lowercase_c_drive() {
assert!(!is_path_safe("c:file.txt"));
assert!(!is_path_safe("c:\\Users\\test"));
}
#[test]
fn test_is_path_safe_uppercase_c_drive() {
assert!(!is_path_safe("C:file.txt"));
assert!(!is_path_safe("C:\\Users\\test"));
}
#[test]
fn test_escape_html_ampersand_only() {
assert_eq!(escape_html("&"), "&");
}
#[test]
fn test_escape_html_less_than_only() {
assert_eq!(escape_html("<"), "<");
}
#[test]
fn test_escape_html_greater_than_only() {
assert_eq!(escape_html(">"), ">");
}
#[test]
fn test_escape_html_double_quote_only() {
assert_eq!(escape_html("\""), """);
}
#[test]
fn test_escape_html_single_quote_only() {
assert_eq!(escape_html("'"), "'");
}
#[test]
fn test_security_config_wasm_memory_limit_custom() {
let config = SecurityConfig {
enable_fuzzing: false,
fuzz_duration_secs: 60,
enable_sanitizers: false,
max_file_size: 100 * 1024 * 1024,
wasm_memory_limit: 512 * 1024 * 1024, };
assert_eq!(config.wasm_memory_limit, 512 * 1024 * 1024);
}
#[test]
fn test_security_result_fail_all_fields() {
let result = SecurityResult::fail("N42", "Custom Fail", "Detailed error description");
assert!(!result.passed);
assert_eq!(result.id, "N42");
assert_eq!(result.name, "Custom Fail");
assert_eq!(result.details, "Detailed error description");
}
#[test]
fn test_path_traversal_blocked_returns_true() {
assert!(test_path_traversal_blocked());
}
#[test]
fn test_exponential_backoff_returns_true() {
assert!(test_exponential_backoff());
}
#[test]
fn test_wasm32_limit_returns_true() {
assert!(test_wasm32_limit());
}
#[test]
fn test_weight_validation_returns_true() {
assert!(test_weight_validation());
}
#[test]
fn test_oom_handling_returns_true() {
assert!(test_oom_handling());
}
#[test]
fn test_escape_html_consecutive_specials() {
assert_eq!(escape_html("<><>"), "<><>");
assert_eq!(escape_html("&&"), "&&");
assert_eq!(escape_html("\"\""), """");
}
#[test]
fn test_run_all_security_tests_with_custom_config() {
let config = SecurityConfig {
enable_fuzzing: true,
fuzz_duration_secs: 30,
enable_sanitizers: true,
max_file_size: 50 * 1024 * 1024,
wasm_memory_limit: 2 * 1024 * 1024 * 1024,
};
let results = run_all_security_tests(&config);
assert_eq!(results.len(), 20);
for r in &results {
assert!(r.passed, "Test {} should pass", r.id);
}
}