test(property): add path validator invariants (#3541)

test(property): add path validator invariants for #3525
This commit is contained in:
houseme
2026-06-18 02:14:24 +08:00
committed by GitHub
parent bc769948ab
commit 87a3d107d6
4 changed files with 53 additions and 0 deletions
Generated
+1
View File
@@ -10182,6 +10182,7 @@ dependencies = [
"lz4",
"md-5 0.11.0",
"netif",
"proptest",
"regex",
"rustix 1.1.4",
"serde",
+25
View File
@@ -353,6 +353,7 @@ pub fn check_put_object_args(bucket: &str, object: &str) -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
// Test validation functions
#[test]
@@ -526,4 +527,28 @@ mod tests {
assert!(check_put_object_args("", "test-object").is_err());
assert!(check_put_object_args("test-bucket", "").is_err());
}
proptest! {
#[test]
fn valid_object_prefixes_preserve_prefix_invariants(input in any::<String>()) {
if is_valid_object_prefix(&input) {
prop_assert!(!has_bad_path_component(&input));
prop_assert!(!input.contains("//"));
prop_assert!(!input.contains('\0'));
}
}
#[test]
fn valid_object_names_preserve_name_invariants(input in any::<String>()) {
if is_valid_object_name(&input) {
prop_assert!(!input.is_empty());
prop_assert!(is_valid_object_prefix(&input));
}
}
#[test]
fn object_name_validity_matches_prefix_validity_plus_non_empty(input in any::<String>()) {
prop_assert_eq!(is_valid_object_name(&input), !input.is_empty() && is_valid_object_prefix(&input));
}
}
}
+1
View File
@@ -60,6 +60,7 @@ zstd = { workspace = true, optional = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
temp-env = { workspace = true }
proptest = "1"
[target.'cfg(windows)'.dependencies]
windows = { workspace = true, optional = true, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
+26
View File
@@ -553,6 +553,7 @@ pub fn trim_etag(etag: &str) -> String {
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
#[test]
fn test_trim_etag() {
@@ -892,4 +893,29 @@ mod tests {
assert_eq!(bucket, "s3-test-bucket");
assert_eq!(object, "中文/日本語/한글-9cd5599a-f8eb-4e24-9df7-32ecd8d8ad1f");
}
proptest! {
#[test]
fn clean_is_idempotent(input in any::<String>()) {
let once = clean(&input);
let twice = clean(&once);
prop_assert_eq!(twice, once);
}
#[test]
fn clean_output_has_no_redundant_current_dir_or_empty_segments(input in any::<String>()) {
let cleaned = clean(&input);
prop_assert!(!cleaned.contains("//"), "clean output should not contain doubled separators");
prop_assert!(!cleaned.contains("/./"), "clean output should not contain embedded current-dir segments");
prop_assert!(!cleaned.ends_with("/."), "clean output should not end with a current-dir segment");
if cleaned != "/" {
prop_assert!(
!cleaned.ends_with('/') || cleaned.is_empty(),
"clean output should not preserve a trailing slash"
);
}
}
}
}