mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
test(property): add path validator invariants (#3541)
test(property): add path validator invariants for #3525
This commit is contained in:
Generated
+1
@@ -10182,6 +10182,7 @@ dependencies = [
|
|||||||
"lz4",
|
"lz4",
|
||||||
"md-5 0.11.0",
|
"md-5 0.11.0",
|
||||||
"netif",
|
"netif",
|
||||||
|
"proptest",
|
||||||
"regex",
|
"regex",
|
||||||
"rustix 1.1.4",
|
"rustix 1.1.4",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -353,6 +353,7 @@ pub fn check_put_object_args(bucket: &str, object: &str) -> Result<()> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
// Test validation functions
|
// Test validation functions
|
||||||
#[test]
|
#[test]
|
||||||
@@ -526,4 +527,28 @@ mod tests {
|
|||||||
assert!(check_put_object_args("", "test-object").is_err());
|
assert!(check_put_object_args("", "test-object").is_err());
|
||||||
assert!(check_put_object_args("test-bucket", "").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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ zstd = { workspace = true, optional = true }
|
|||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
|
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
|
||||||
temp-env = { workspace = true }
|
temp-env = { workspace = true }
|
||||||
|
proptest = "1"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows = { workspace = true, optional = true, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
|
windows = { workspace = true, optional = true, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
|
||||||
|
|||||||
@@ -553,6 +553,7 @@ pub fn trim_etag(etag: &str) -> String {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_trim_etag() {
|
fn test_trim_etag() {
|
||||||
@@ -892,4 +893,29 @@ mod tests {
|
|||||||
assert_eq!(bucket, "s3-test-bucket");
|
assert_eq!(bucket, "s3-test-bucket");
|
||||||
assert_eq!(object, "中文/日本語/한글-9cd5599a-f8eb-4e24-9df7-32ecd8d8ad1f");
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user