From 8dce2f9be63dc5499bbfa11aad752d7c093fa866 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 25 Nov 2026 13:27:35 +0800 Subject: [PATCH] test(object): replace legacy s3 test imports with gateway and s3-types Migrate the remaining storage_api::s3 test imports and compatibility shims in extract, get_response_test, head_response_test, internal_put, on_demand_migration_put, and shared directly to rustfs_gateway_types, rustfs_s3_types, rustfs_utils, rustfs_rio, and pinned expected wire values. --- rustfs/src/app/object/extract.rs | 7 +- rustfs/src/app/object/get_response_test.rs | 45 ++++++------ rustfs/src/app/object/head_response_test.rs | 40 ++++++----- rustfs/src/app/object/internal_put.rs | 9 +-- .../src/app/object/on_demand_migration_put.rs | 7 +- rustfs/src/app/object/shared.rs | 71 +++++++------------ 6 files changed, 79 insertions(+), 100 deletions(-) diff --git a/rustfs/src/app/object/extract.rs b/rustfs/src/app/object/extract.rs index 28c3de0841..791d4bb4b7 100644 --- a/rustfs/src/app/object/extract.rs +++ b/rustfs/src/app/object/extract.rs @@ -2857,10 +2857,9 @@ pub(super) mod post_archive_preflight; mod tests { use super::*; - use crate::app::storage_api::s3::StdError; - use crate::app::storage_api::s3::dto::ObjectLockRetentionMode; use http::{HeaderMap, HeaderName, HeaderValue}; use rustfs_gateway_stream::Body; + use rustfs_s3_types::StdError; use tokio::io::AsyncReadExt; use tokio_tar::{Builder, EntryType, Header}; @@ -4391,7 +4390,7 @@ mod tests { let mut entries = archive.entries().unwrap(); let mut entry = entries.next().await.unwrap().unwrap(); let mut metadata = HashMap::from([ - (AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), ObjectLockRetentionMode::COMPLIANCE.to_string()), + (AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), "COMPLIANCE".to_string()), (AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER.to_string(), "2030-01-01T00:00:00Z".to_string()), ]); let mut opts = ObjectOptions::default(); @@ -4580,7 +4579,7 @@ mod tests { let mut entries = archive.entries().unwrap(); let mut entry = entries.next().await.unwrap().unwrap(); let mut metadata = HashMap::from([ - (AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), ObjectLockRetentionMode::COMPLIANCE.to_string()), + (AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), "COMPLIANCE".to_string()), (AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER.to_string(), "2030-01-01T00:00:00Z".to_string()), ]); let mut opts = ObjectOptions::default(); diff --git a/rustfs/src/app/object/get_response_test.rs b/rustfs/src/app/object/get_response_test.rs index 0feb6ab78b..1974df9389 100644 --- a/rustfs/src/app/object/get_response_test.rs +++ b/rustfs/src/app/object/get_response_test.rs @@ -16,40 +16,35 @@ //! Expected responses were measured on a279b4b before the owned migration. use super::*; -use crate::app::storage_api::s3::dto::Range; use crate::app::storage_api::test::ReqInfo; use crate::app::test_seams::{get_envelope, get_http_body, get_object_gateway, get_object_input}; use http::Method; use http_body_util::BodyExt as _; -use rustfs_gateway_types::{BucketName, ObjectKey, RangeSpec, dto}; +use rustfs_gateway_types::{BucketName, ByteRange, ObjectKey, RangeSpec, dto}; use rustfs_s3_types::S3ErrorCode; #[test] fn website_and_object_lambda_ranges_match_the_legacy_wire_reader() { - for value in [ - "bytes=0-9", - "bytes=0-", - "bytes=-7", - "bytes=-0", - "bytes=-", - "bytes=-18446744073709551615", - "bytes=9223372036854775807-", - "bytes=9223372036854775808-", - "bytes=0-9223372036854775808", - "bytes=-18446744073709551616", - "bytes=10-5", - "bytes=1-2 ", - "bytes=1 -2", - "bytes=1-2,3-4", - "bytes=-+1", - "Bytes=1-2", - "bytes=", + // Answers measured on s3s 5761ddfe (`Range::parse`). + for (value, expected) in [ + ("bytes=0-9", Some(ByteRange::FromTo { first: 0, last: 9 })), + ("bytes=0-", Some(ByteRange::From { first: 0 })), + ("bytes=-7", Some(ByteRange::Suffix { length: 7 })), + ("bytes=-0", Some(ByteRange::Suffix { length: 0 })), + ("bytes=-", Some(ByteRange::Suffix { length: 0 })), + ("bytes=-18446744073709551615", Some(ByteRange::Suffix { length: u64::MAX })), + ("bytes=9223372036854775807-", Some(ByteRange::From { first: i64::MAX as u64 })), + ("bytes=9223372036854775808-", None), + ("bytes=0-9223372036854775808", None), + ("bytes=-18446744073709551616", None), + ("bytes=10-5", None), + ("bytes=1-2 ", None), + ("bytes=1 -2", None), + ("bytes=1-2,3-4", None), + ("bytes=-+1", None), + ("Bytes=1-2", None), + ("bytes=", None), ] { - let expected = Range::parse(value).ok().map(|range| match range { - Range::Int { first, last: Some(last) } => rustfs_gateway_types::ByteRange::FromTo { first, last }, - Range::Int { first, last: None } => rustfs_gateway_types::ByteRange::From { first }, - Range::Suffix { length } => rustfs_gateway_types::ByteRange::Suffix { length }, - }); assert_eq!(GetObjectFields::parse_range(value), expected, "{value}"); } } diff --git a/rustfs/src/app/object/head_response_test.rs b/rustfs/src/app/object/head_response_test.rs index 416a1df76d..2931b9c769 100644 --- a/rustfs/src/app/object/head_response_test.rs +++ b/rustfs/src/app/object/head_response_test.rs @@ -88,26 +88,30 @@ fn head_etag_http_projection_preserves_spelling() { #[test] fn head_proxy_etag_mapping_matches_the_legacy_parser() { - let mut inputs = vec![ - "abc".to_owned(), - String::new(), - "*".to_owned(), - " abc ".to_owned(), - "abc_def".to_owned(), - "W/\"\"".to_owned(), - "W/abc".to_owned(), - "w/\"abc\"".to_owned(), - "\"a\\b\"".to_owned(), - "\"a\tb\"".to_owned(), - "\"a\"b\"".to_owned(), + // Answers measured on s3s 5761ddfe (`ETag::from_str`). + let mut cases: Vec<(String, Option<(String, bool)>)> = vec![ + ("abc".to_owned(), Some(("abc".to_owned(), false))), + (String::new(), None), + ("*".to_owned(), None), + (" abc ".to_owned(), None), + ("abc_def".to_owned(), None), + ("W/\"\"".to_owned(), Some((String::new(), true))), + ("W/abc".to_owned(), None), + ("w/\"abc\"".to_owned(), None), + ("\"a\\b\"".to_owned(), Some(("a\\b".to_owned(), false))), + ("\"a\tb\"".to_owned(), Some(("a\tb".to_owned(), false))), + ("\"a\"b\"".to_owned(), Some(("a\"b".to_owned(), false))), ]; for byte in 0..=255u8 { - inputs.push(format!("\"a{}b\"", char::from(byte))); - inputs.push(format!("W/\"a{}b\"", char::from(byte))); - inputs.push(char::from(byte).to_string()); + let ch = char::from(byte); + let quoted_valid = byte == 0x09 || (0x20..=0x7e).contains(&byte); + let unquoted_valid = matches!(byte, b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'-'); + let inner = format!("a{ch}b"); + cases.push((format!("\"{inner}\""), quoted_valid.then(|| (inner.clone(), false)))); + cases.push((format!("W/\"{inner}\""), quoted_valid.then_some((inner, true)))); + cases.push((ch.to_string(), unquoted_valid.then(|| (ch.to_string(), false)))); } - for raw in inputs { - let expected = crate::app::storage_api::s3::dto::ETag::from_str(&raw).ok(); + for (raw, expected) in cases { let sdk = aws_sdk_s3::operation::head_object::HeadObjectOutput::builder() .e_tag(&raw) .build(); @@ -115,7 +119,7 @@ fn head_proxy_etag_mapping_matches_the_legacy_parser() { assert!(facts.dto.e_tag.is_none(), "ETag is carried as a response fact"); assert_eq!( facts.etag.as_ref().map(|tag| (tag.opaque.as_str(), tag.weak)), - expected.as_ref().map(|tag| (tag.value(), tag.as_weak().is_some())), + expected.as_ref().map(|(opaque, weak)| (opaque.as_str(), *weak)), "{raw:?}" ); } diff --git a/rustfs/src/app/object/internal_put.rs b/rustfs/src/app/object/internal_put.rs index 5c84c6c3bd..711754a0d6 100644 --- a/rustfs/src/app/object/internal_put.rs +++ b/rustfs/src/app/object/internal_put.rs @@ -813,12 +813,13 @@ impl DefaultObjectUsecase { #[cfg(test)] mod tests { use super::*; - use crate::app::storage_api::s3::{ - PersistedOptionalReplicationStatus, PersistedReplicationConfiguration, PersistedReplicationDestination, - PersistedReplicationFilter, PersistedReplicationRule, PersistedReplicationTag, Status, - }; use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, MakeBucketOptions}; use crate::app::storage_api::test::{get_global_bucket_metadata_sys, set_bucket_metadata}; + use rustfs_gateway_types::dto::Status; + use rustfs_gateway_types::persistence::{ + PersistedOptionalReplicationStatus, PersistedReplicationConfiguration, PersistedReplicationDestination, + PersistedReplicationFilter, PersistedReplicationRule, PersistedReplicationTag, + }; use rustfs_utils::http::{ MINIO_INTERNAL_PREFIX, RUSTFS_INTERNAL_PREFIX, SUFFIX_ODM_PULLED_AT, SUFFIX_ODM_SOURCE, SUFFIX_ODM_SOURCE_ETAG, SUFFIX_ODM_SOURCE_LAST_MODIFIED, SUFFIX_ODM_SOURCE_VERSION_ID, contains_key_str, get_consistent_str, get_str, diff --git a/rustfs/src/app/object/on_demand_migration_put.rs b/rustfs/src/app/object/on_demand_migration_put.rs index 2b3a69050f..1d6d8ab19a 100644 --- a/rustfs/src/app/object/on_demand_migration_put.rs +++ b/rustfs/src/app/object/on_demand_migration_put.rs @@ -299,18 +299,17 @@ impl OdmWriteBack for OnDemandMigrationWriteBack { mod tests { use super::*; use crate::app::storage_api::multipart_usecase::contract::multipart::MultipartOperations as _; - use crate::app::storage_api::s3::{ - PersistedOptionalReplicationStatus, PersistedReplicationConfiguration, PersistedReplicationDestination, - PersistedReplicationFilter, PersistedReplicationRule, PersistedReplicationTag, Status, - }; use crate::app::storage_api::test::bucket::utils::serialize; use crate::app::storage_api::test::contract::bucket::{BucketOperations as _, DeleteBucketOptions, MakeBucketOptions}; use crate::app::storage_api::test::{get_global_bucket_metadata_sys, set_bucket_metadata}; use crate::app::test_seams::{get_envelope, get_object_gateway, get_object_input, read_get_body}; use crate::on_demand_migration::{PullFailureReason, SourceSse}; + use rustfs_gateway_types::dto::Status; use rustfs_gateway_types::persistence::{ PersistedBucketEncryptionConfiguration as ServerSideEncryptionConfiguration, PersistedBucketEncryptionRule as ServerSideEncryptionRule, PersistedEncryptionByDefault as ServerSideEncryptionByDefault, + PersistedOptionalReplicationStatus, PersistedReplicationConfiguration, PersistedReplicationDestination, + PersistedReplicationFilter, PersistedReplicationRule, PersistedReplicationTag, }; use rustfs_utils::http::{MINIO_INTERNAL_PREFIX, RUSTFS_INTERNAL_PREFIX, contains_key_str, get_str}; use sha2::{Digest as Sha256Digest, Sha256}; diff --git a/rustfs/src/app/object/shared.rs b/rustfs/src/app/object/shared.rs index 754a7fb732..865d820302 100644 --- a/rustfs/src/app/object/shared.rs +++ b/rustfs/src/app/object/shared.rs @@ -17,10 +17,6 @@ use super::*; use crate::app::RequestEnvelope; use crate::app::storage_api::object_usecase::access::authorize_missing_object_disclosure; -#[cfg(test)] -use crate::app::storage_api::s3::dto::ObjectLockRetentionMode; -#[cfg(test)] -use crate::app::storage_api::s3::dto::{ObjectLockLegalHoldStatus, ObjectLockMode, Timestamp}; use crate::on_demand_migration::{OdmStateError, PolicyConfig, SourceErrorPolicy, SourceHead}; use rustfs_gateway_types::ChecksumAlgorithm; use rustfs_s3_client::constants::{X_AMZ_DELETE_MARKER, X_AMZ_VERSION_ID}; @@ -857,23 +853,6 @@ pub(super) fn response_storage_class_for_object_attributes( pub(crate) const ERR_OBJECT_LOCK_RETENTION_HEADERS_MUST_BE_PAIRED: &str = "x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied"; -#[cfg(test)] -fn build_put_like_object_lock_metadata( - bucket: &str, - object_lock_config_state: &metadata_sys::ObjectLockConfigState, - object_lock_legal_hold_status: Option, - object_lock_mode: Option, - object_lock_retain_until_date: Option, -) -> S3Result>> { - build_put_like_object_lock_metadata_native( - bucket, - object_lock_config_state, - object_lock_legal_hold_status.map(|value| value.as_str().to_owned()), - object_lock_mode.map(|value| value.as_str().to_owned()), - object_lock_retain_until_date.map(time::OffsetDateTime::from), - ) -} - pub(crate) fn build_put_like_object_lock_metadata_native( bucket: &str, object_lock_config_state: &metadata_sys::ObjectLockConfigState, @@ -1190,11 +1169,11 @@ pub(crate) fn reject_non_wildcard_write_if_none_match(specific_if_none_match: bo #[cfg(test)] mod tests { use super::*; - use crate::app::storage_api::s3::dto::ServerSideEncryption; use http::{HeaderMap, HeaderValue}; use rustfs_gateway_types::persistence::{ PersistedBucketEncryptionRule as ServerSideEncryptionRule, PersistedEncryptionByDefault as ServerSideEncryptionByDefault, }; + use rustfs_utils::http::headers::AMZ_ENCRYPTION_AES; use std::sync::Arc; #[test] @@ -1701,37 +1680,36 @@ mod tests { #[test] fn resolve_bucket_default_sse_prefers_the_request_over_the_bucket_default() { - let config = bucket_sse_config_with(ServerSideEncryption::AWS_KMS, Some("bucket-key")); + let config = bucket_sse_config_with(AMZ_ENCRYPTION_KMS, Some("bucket-key")); let (sse, kms_key_id) = resolve_bucket_default_sse( Some(&config), - Some(String::from(ServerSideEncryption::AES256)), + Some(String::from(AMZ_ENCRYPTION_AES)), Some("request-key".to_string()), false, ); - assert_eq!(sse.as_deref(), Some(ServerSideEncryption::AES256)); + assert_eq!(sse.as_deref(), Some(AMZ_ENCRYPTION_AES)); assert_eq!(kms_key_id.as_deref(), Some("request-key")); } #[test] fn resolve_bucket_default_sse_does_not_inherit_a_kms_key_for_an_explicit_sse_s3_request() { - let config = bucket_sse_config_with(ServerSideEncryption::AWS_KMS, Some("bucket-key")); + let config = bucket_sse_config_with(AMZ_ENCRYPTION_KMS, Some("bucket-key")); - let (sse, kms_key_id) = - resolve_bucket_default_sse(Some(&config), Some(String::from(ServerSideEncryption::AES256)), None, false); + let (sse, kms_key_id) = resolve_bucket_default_sse(Some(&config), Some(String::from(AMZ_ENCRYPTION_AES)), None, false); - assert_eq!(sse.as_deref(), Some(ServerSideEncryption::AES256)); + assert_eq!(sse.as_deref(), Some(AMZ_ENCRYPTION_AES)); assert!(kms_key_id.is_none(), "an SSE-S3 request must not inherit the bucket KMS key"); } #[test] fn resolve_bucket_default_sse_fills_gaps_from_the_bucket_default() { - let config = bucket_sse_config_with(ServerSideEncryption::AWS_KMS, Some("bucket-key")); + let config = bucket_sse_config_with(AMZ_ENCRYPTION_KMS, Some("bucket-key")); let (sse, kms_key_id) = resolve_bucket_default_sse(Some(&config), None, None, false); - assert_eq!(sse.as_deref(), Some(ServerSideEncryption::AWS_KMS)); + assert_eq!(sse.as_deref(), Some(AMZ_ENCRYPTION_KMS)); assert_eq!(kms_key_id.as_deref(), Some("bucket-key")); } @@ -1745,13 +1723,13 @@ mod tests { let (sse, kms_key_id) = resolve_bucket_default_sse(Some(&config), None, None, false); - assert_eq!(sse.as_deref(), Some(ServerSideEncryption::AES256)); + assert_eq!(sse.as_deref(), Some(AMZ_ENCRYPTION_AES)); assert!(kms_key_id.is_none()); } #[test] fn resolve_bucket_default_sse_suppresses_the_default_for_explicit_ssec() { - let config = bucket_sse_config_with(ServerSideEncryption::AES256, Some("bucket-key")); + let config = bucket_sse_config_with(AMZ_ENCRYPTION_AES, Some("bucket-key")); let (sse, kms_key_id) = resolve_bucket_default_sse(Some(&config), None, None, true); @@ -1769,11 +1747,11 @@ mod tests { #[test] fn build_put_like_object_lock_metadata_rejects_mode_without_retain_until_date() { - let err = build_put_like_object_lock_metadata( + let err = build_put_like_object_lock_metadata_native( "test-bucket", &metadata_sys::ObjectLockConfigState::ConfirmedAbsent, None, - Some(ObjectLockMode::from_static(ObjectLockMode::GOVERNANCE)), + Some("GOVERNANCE".to_owned()), None, ) .unwrap_err(); @@ -1801,8 +1779,8 @@ mod tests { #[test] fn build_put_like_object_lock_metadata_rejects_retain_until_date_without_mode() { - let retain_until = Timestamp::from(OffsetDateTime::now_utc() + time::Duration::days(1)); - let err = build_put_like_object_lock_metadata( + let retain_until = OffsetDateTime::now_utc() + time::Duration::days(1); + let err = build_put_like_object_lock_metadata_native( "test-bucket", &metadata_sys::ObjectLockConfigState::ConfirmedAbsent, None, @@ -1843,14 +1821,14 @@ mod tests { fn compliance_retained_object_info() -> ObjectInfo { let mut metadata = HashMap::new(); - metadata.insert(AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), ObjectLockRetentionMode::COMPLIANCE.to_string()); + metadata.insert(AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), "COMPLIANCE".to_string()); metadata.insert(AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER.to_string(), "2030-01-01T00:00:00Z".to_string()); object_info_with_lock_metadata(metadata) } fn legal_hold_object_info() -> ObjectInfo { let mut metadata = HashMap::new(); - metadata.insert(AMZ_OBJECT_LOCK_LEGAL_HOLD_LOWER.to_string(), ObjectLockLegalHoldStatus::ON.to_string()); + metadata.insert(AMZ_OBJECT_LOCK_LEGAL_HOLD_LOWER.to_string(), "ON".to_string()); object_info_with_lock_metadata(metadata) } @@ -1977,7 +1955,7 @@ mod tests { ..tagging_only.clone() }; - for mode in [ObjectLockRetentionMode::COMPLIANCE, ObjectLockRetentionMode::GOVERNANCE] { + for mode in ["COMPLIANCE", "GOVERNANCE"] { let state = bucket_default_retention_state(mode); let err = validate_existing_object_lock_for_write(&state, &default_protected, &tagging_only) .expect_err("bucket default retention must hold without a retention source timestamp"); @@ -2013,12 +1991,15 @@ mod tests { #[test] fn s3s_body_error_to_io_preserves_upload_stream_error_source() { - let error = s3s_body_error_to_io(Box::new(UploadStreamError::Sha256Mismatch)); + let error = s3s_body_error_to_io(Box::new(rustfs_rio::IncompleteBody { remaining: 7 })); - assert!(matches!( - error.get_ref().and_then(|source| source.downcast_ref::()), - Some(UploadStreamError::Sha256Mismatch) - )); + assert_eq!( + error + .get_ref() + .and_then(|source| source.downcast_ref::()) + .map(|err| err.remaining), + Some(7) + ); } #[test]