Compare commits

...

7 Commits

Author SHA1 Message Date
overtrue 357e78c523 test(admin): build runtime-context probes on the owned envelope
The router production path is unchanged. A test-only caller builds the empty request.
2026-11-21 15:02:19 +08:00
overtrue 411caa97d7 test(storage): build object-lock helpers on the owned types
The fixtures keep the same Enabled, COMPLIANCE, GOVERNANCE, ON, and OFF spellings.
2026-11-21 14:22:24 +08:00
overtrue 317e895096 test(admin): pin the lifecycle staleness axis to the fixture instant
ExpiryUpdatedAt stays 2026-07-07T15:58:57.337315Z, the text in the fixture.
2026-11-21 13:40:35 +08:00
overtrue 7c55e265dd test(object): pin get-object condition answers to the legacy reader
The accepted and rejected header values are the answers of s3s 5761ddfe.
2026-11-21 13:07:23 +08:00
overtrue f858a65f41 refactor(bucket): serialize admission errors through the owned type
The admission test still checks the status, the retry header, and the body.
2026-11-21 12:32:03 +08:00
overtrue f96c324734 refactor(s3-types): serialize select errors through the owned type 2026-11-21 11:55:10 +08:00
overtrue 7e5b3e4137 refactor(object-meta): serialize retention dates on the owned timestamp 2026-11-21 10:55:08 +08:00
9 changed files with 156 additions and 186 deletions
+10
View File
@@ -133,6 +133,16 @@ impl From<S3Error> for legacy_s3s::S3Error {
}
}
impl S3Error {
/// The pinned legacy serializer's XML response. Call sites stay on this type.
/// DELETE BY T4.2 with the rest of this file.
pub fn to_http_response(self) -> Result<http::Response<crate::Body>, Self> {
let response = legacy_s3s::S3Error::from(self).to_http_response().map_err(Self::from)?;
let (parts, body) = response.into_parts();
Ok(http::Response::from_parts(parts, crate::Body::from(body)))
}
}
impl From<legacy_s3s::S3Error> for S3Error {
fn from(error: legacy_s3s::S3Error) -> Self {
let code: S3ErrorCode = error.code().clone().into();
@@ -13921,18 +13921,18 @@ mod tests {
env!("CARGO_MANIFEST_DIR"),
"/../crates/ecstore/tests/fixtures/bucket-config-goldens/lifecycle/minio.in.xml"
));
let mut old_reader = s3s::xml::Deserializer::new(raw);
let old: s3s::dto::BucketLifecycleConfiguration =
s3s::xml::Deserialize::deserialize(&mut old_reader).expect("read the actual old lifecycle expiry axis");
old_reader.expect_eof().expect("the old expiry reader consumes the document");
let old_axis = OffsetDateTime::from(old.expiry_updated_at.expect("the old config contains its expiry axis"));
// Answer of s3s 5761ddfe (`Timestamp::parse(DateTime)` on this document's
// ExpiryUpdatedAt). The owned axis must keep that instant.
let legacy_axis =
parse_lifecycle_date("2026-07-07T15:58:57.337315Z").expect("the legacy expiry axis is the minio.in.xml value");
let new = deserialize(raw).expect("read the persisted lifecycle expiry axis");
let new_axis = local_lifecycle_staleness_axis(Some(&new), OffsetDateTime::UNIX_EPOCH)
.expect("the parsed lifecycle axis is readable");
let incoming = parse_lifecycle_date("2026-07-07T15:58:57.337100Z").expect("the incoming expiry axis is valid");
assert_eq!(new_axis, legacy_axis, "the parsed axis must keep the legacy submillisecond instant");
assert_eq!(
is_stale_update(new_axis, Some(incoming)),
is_stale_update(old_axis, Some(incoming)),
is_stale_update(legacy_axis, Some(incoming)),
"a peer update older than the full-precision local axis must remain stale"
);
}
+27
View File
@@ -1021,6 +1021,33 @@ impl<T> S3Router<T> {
}
}
#[cfg(test)]
impl<T: OwnedOperation> S3Router<T> {
/// Dispatches one legacy admin request. Callers keep their assertions and do not name s3s.
pub(crate) async fn call_legacy(
&self,
method: Method,
uri: &str,
extensions: http::Extensions,
) -> s3s::S3Result<S3Response<Body>> {
S3Route::call(
self,
S3Request {
input: Body::empty(),
method,
uri: uri.parse().expect("test URI"),
headers: HeaderMap::new(),
extensions,
credentials: None,
region: None,
service: None,
trailing_headers: None,
},
)
.await
}
}
impl<T> Default for S3Router<T> {
fn default() -> Self {
Self::new(false)
+14 -20
View File
@@ -142,14 +142,12 @@ mod tests {
};
use crate::admin::operation::{AdminRequest, AdminResponse, Operation};
use crate::admin::router::S3Router;
use crate::app::RequestEnvelope;
use crate::app::{RequestEnvelope, RequestHead};
use hyper::{Method, StatusCode};
use matchit::Params;
use rustfs_iam::{store::object::ObjectStore, sys::IamSys};
use rustfs_kms::KmsServiceManager;
use rustfs_s3_types::{S3ErrorCode, s3_error};
use s3s::route::S3Route;
use s3s::{Body, S3Request};
use std::sync::Arc;
struct UnreadyIam;
@@ -192,22 +190,18 @@ mod tests {
Arc::new(AppContext::new(context.object_store(), Arc::new(UnreadyIam), Arc::new(TestKms)))
}
fn request(extensions: http::Extensions) -> S3Request<Body> {
S3Request {
input: Body::empty(),
method: Method::GET,
uri: "/context-probe".parse().expect("test URI"),
headers: http::HeaderMap::new(),
extensions,
credentials: None,
region: None,
service: None,
trailing_headers: None,
}
}
fn envelope(extensions: http::Extensions) -> RequestEnvelope {
RequestEnvelope::from_s3s(&request(extensions))
RequestEnvelope::from_parts(
RequestHead {
method: Method::GET,
uri: "/context-probe".parse().expect("test URI"),
headers: http::HeaderMap::new(),
credentials: None,
region: None,
service: None,
},
extensions,
)
}
#[tokio::test]
@@ -330,14 +324,14 @@ mod tests {
.expect("register test route");
let err = router
.call(request(http::Extensions::new()))
.call_legacy(Method::GET, "/context-probe", http::Extensions::new())
.await
.expect_err("empty slot must fail closed");
assert_eq!(err.code(), &S3ErrorCode::ServiceUnavailable.into());
assert!(slot.install(distinct_context(&ambient)));
let response = router
.call(request(http::Extensions::new()))
.call_legacy(Method::GET, "/context-probe", http::Extensions::new())
.await
.expect("installed slot must serve request");
assert_eq!(response.status, Some(StatusCode::NO_CONTENT));
+1 -3
View File
@@ -906,9 +906,7 @@ mod tests {
.expect_err("full queue rejects immediately");
assert_eq!(error.code(), &S3ErrorCode::SlowDown);
assert_eq!(error.headers().expect("retry headers")[http::header::RETRY_AFTER], "1");
let response = s3s::S3Error::from(error)
.to_http_response()
.expect("serialize admission error");
let response = error.to_http_response().expect("serialize admission error");
assert_eq!(response.status(), http::StatusCode::SERVICE_UNAVAILABLE);
assert_eq!(response.headers()[http::header::RETRY_AFTER], "1");
use http_body_util::BodyExt as _;
+22 -29
View File
@@ -52,38 +52,31 @@ fn website_and_object_lambda_ranges_match_the_legacy_wire_reader() {
#[test]
fn website_and_object_lambda_conditions_match_the_legacy_wire_reader() {
use s3s::dto::{ETagCondition, Timestamp, TimestampFormat};
for value in [
b"*".as_slice(),
b"abc-2",
b"\"\"",
b"W/\"x\"",
b"\"a \tb\"",
b"\"a\"b\"",
b"",
b"bad etag",
b"w/\"x\"",
b"\"\xff\"",
b"\"\x7f\"",
b"\"x",
// Answers measured on s3s 5761ddfe (`ETagCondition::parse_http_header` and
// `Timestamp::parse(HttpDate)`). The owned checks must keep those answers.
for (value, accepted) in [
(b"*".as_slice(), true),
(b"abc-2", true),
(b"\"\"", true),
(b"W/\"x\"", true),
(b"\"a \tb\"", true),
(b"\"a\"b\"", true),
(b"", false),
(b"bad etag", false),
(b"w/\"x\"", false),
(b"\"\xff\"", false),
(b"\"\x7f\"", false),
(b"\"x", false),
] {
assert_eq!(
GetObjectFields::valid_etag_condition(value),
ETagCondition::parse_http_header(value).is_ok(),
"{value:?}"
);
assert_eq!(GetObjectFields::valid_etag_condition(value), accepted, "{value:?}");
}
for value in [
"Sun, 06 Nov 1994 08:49:37 GMT",
"Sunday, 06-Nov-94 08:49:37 GMT",
"2025-01-01",
"Sun, 32 Nov 1994 08:49:37 GMT",
for (value, accepted) in [
("Sun, 06 Nov 1994 08:49:37 GMT", true),
("Sunday, 06-Nov-94 08:49:37 GMT", false),
("2025-01-01", false),
("Sun, 32 Nov 1994 08:49:37 GMT", false),
] {
assert_eq!(
GetObjectFields::valid_date_condition(value),
Timestamp::parse(TimestampFormat::HttpDate, value).is_ok(),
"{value}"
);
assert_eq!(GetObjectFields::valid_date_condition(value), accepted, "{value}");
}
}
+17 -12
View File
@@ -265,22 +265,27 @@ mod tests {
] {
let retention = stored_retention(&stored(value)).expect("representable retention instant");
assert_eq!(retention.mode.as_ref().expect("mode").as_str(), "COMPLIANCE");
// The response codec writes RetainUntilDate as ISO 8601.
let serialized = retention
.retain_until_date
.expect("stored retention date")
.render(rustfs_gateway_types::TimestampFormat::Iso8601)
.expect("serialize the response timestamp");
let returned = OffsetDateTime::parse(&serialized, &Rfc3339).expect("parse wire timestamp");
let stored_at = OffsetDateTime::parse(value, &Rfc3339).expect("parse stored timestamp");
assert_eq!(returned.unix_timestamp(), stored_at.unix_timestamp(), "stored date {value}");
let output = get_object_retention::output_to_s3s(GetObjectRetentionOutput {
retention: Some(retention),
})
.expect("convert the response");
let mut serialized = Vec::new();
output
.retention
.expect("retention")
.retain_until_date
.expect("stored retention date")
.format(s3s::dto::TimestampFormat::DateTime, &mut serialized)
.expect("serialize the response timestamp");
let serialized = String::from_utf8(serialized).expect("UTF-8 timestamp");
let returned = OffsetDateTime::parse(&serialized, &Rfc3339).expect("parse wire timestamp");
let stored = OffsetDateTime::parse(value, &Rfc3339).expect("parse stored timestamp");
assert_eq!(returned.unix_timestamp(), stored.unix_timestamp(), "stored date {value}");
let seam = OffsetDateTime::from(
output
.retention
.expect("retention")
.retain_until_date
.expect("stored retention date"),
);
assert_eq!(seam.unix_timestamp(), stored_at.unix_timestamp(), "stored date {value}");
}
}
+1 -3
View File
@@ -1727,9 +1727,7 @@ mod tests {
}
async fn http_xml_error(error: S3Error) -> (StatusCode, String) {
let response = s3s::S3Error::from(error)
.to_http_response()
.expect("S3 error should serialize to HTTP");
let response = error.to_http_response().expect("S3 error should serialize to HTTP");
let status = response.status();
let body = http_body_util::BodyExt::collect(response.into_body())
.await
+58 -113
View File
@@ -55,32 +55,41 @@ mod tests {
use http::{HeaderMap, HeaderValue, StatusCode};
use rustfs_config::MI_B;
use rustfs_gateway_types::persistence::{
PersistedFilterRule, PersistedLambdaFunctionConfiguration, PersistedNotificationConfigurationFilter,
PersistedDefaultRetention, PersistedFilterRule, PersistedLambdaFunctionConfiguration,
PersistedNotificationConfigurationFilter, PersistedObjectLockConfiguration, PersistedObjectLockRule,
PersistedQueueConfiguration, PersistedS3KeyFilter, PersistedTopicConfiguration,
};
use rustfs_s3_types::{S3ErrorCode, S3Result};
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result, s3_error};
use rustfs_utils::http::{
AMZ_OBJECT_LOCK_LEGAL_HOLD_LOWER, AMZ_OBJECT_LOCK_MODE_LOWER, AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER,
MINIO_INTERNAL_PREFIX, RUSTFS_INTERNAL_PREFIX, SUFFIX_OBJECTLOCK_LEGALHOLD_TIMESTAMP,
SUFFIX_OBJECTLOCK_RETENTION_TIMESTAMP, contains_key_str, get_str, insert_str,
};
use rustfs_zip::CompressionFormat;
use s3s::dto::{
DefaultRetention, ObjectLockConfiguration, ObjectLockEnabled, ObjectLockLegalHold, ObjectLockLegalHoldStatus,
ObjectLockRetention, ObjectLockRetentionMode, ObjectLockRule,
};
use std::collections::HashMap;
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
fn parse_object_lock_retention(retention: Option<ObjectLockRetention>) -> S3Result<HashMap<String, String>> {
parse_object_lock_retention_native(retention.map(|r| RequestedObjectLockRetention {
mode: r.mode.map(|m| m.as_str().to_owned()),
retain_until: r.retain_until_date.map(OffsetDateTime::from),
}))
fn parse_object_lock_retention(retention: Option<RequestedObjectLockRetention>) -> S3Result<HashMap<String, String>> {
parse_object_lock_retention_native(retention)
}
fn parse_object_lock_legal_hold(legal_hold: Option<ObjectLockLegalHold>) -> S3Result<HashMap<String, String>> {
parse_object_lock_legal_hold_native(legal_hold.map(|h| RequestedObjectLegalHold(h.status.map(|s| s.as_str().to_owned()))))
fn parse_object_lock_legal_hold(legal_hold: Option<RequestedObjectLegalHold>) -> S3Result<HashMap<String, String>> {
parse_object_lock_legal_hold_native(legal_hold)
}
/// Bucket default retention already stored, the shape `apply_default_lock_retention_metadata` reads.
/// `Enabled` / `COMPLIANCE` / `GOVERNANCE` are the spellings s3s 5761ddfe wrote for these fixtures.
fn enabled_lock(retention: Option<(&str, i32)>) -> PersistedObjectLockConfiguration {
PersistedObjectLockConfiguration {
object_lock_enabled: Some("Enabled".to_owned()),
rule: retention.map(|(mode, days)| PersistedObjectLockRule {
default_retention: Some(PersistedDefaultRetention {
mode: Some(mode.to_owned()),
days: Some(days),
years: None,
}),
}),
}
}
#[test]
@@ -155,8 +164,6 @@ mod tests {
#[test]
fn test_s3_error_scenarios() {
use s3s::{S3Error, S3ErrorCode, s3_error};
// Test that we can create expected S3 errors for common validation cases
// Test incomplete body error
@@ -185,27 +192,12 @@ mod tests {
assert_eq!(gz_format.extension(), "gz");
}
/// The bucket default retention path reads the persisted shape; the request
/// literals in these tests stay on the wire DTO and convert once here.
fn persisted_lock(cfg: &ObjectLockConfiguration) -> rustfs_gateway_types::persistence::PersistedObjectLockConfiguration {
crate::storage::persisted_from_s3s(cfg).expect("the test configuration converts")
}
#[test]
fn test_apply_default_lock_retention_metadata_applies_bucket_default() {
let cfg = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: Some(ObjectLockRule {
default_retention: Some(DefaultRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
days: Some(1),
years: None,
}),
}),
};
let cfg = enabled_lock(Some(("COMPLIANCE", 1)));
let mut metadata = std::collections::HashMap::new();
assert!(apply_default_lock_retention_metadata(Some(&persisted_lock(&cfg)), &mut metadata));
assert!(apply_default_lock_retention_metadata(Some(&cfg), &mut metadata));
assert_eq!(metadata.get(AMZ_OBJECT_LOCK_MODE_LOWER), Some(&"COMPLIANCE".to_string()));
let retain_until = metadata
.get(AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER)
@@ -224,22 +216,13 @@ mod tests {
fn test_apply_default_lock_retention_metadata_preserves_explicit_retention() {
use std::collections::HashMap;
let cfg = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: Some(ObjectLockRule {
default_retention: Some(DefaultRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
days: Some(1),
years: None,
}),
}),
};
let cfg = enabled_lock(Some(("COMPLIANCE", 1)));
let mut metadata = HashMap::from([
(AMZ_OBJECT_LOCK_MODE_LOWER.to_string(), "GOVERNANCE".to_string()),
(AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER.to_string(), "2030-01-01T00:00:00Z".to_string()),
]);
assert!(!apply_default_lock_retention_metadata(Some(&persisted_lock(&cfg)), &mut metadata));
assert!(!apply_default_lock_retention_metadata(Some(&cfg), &mut metadata));
assert_eq!(metadata.get(AMZ_OBJECT_LOCK_MODE_LOWER), Some(&"GOVERNANCE".to_string()));
assert_eq!(
metadata.get(AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER),
@@ -249,30 +232,17 @@ mod tests {
#[test]
fn test_apply_default_lock_retention_metadata_ignores_bucket_without_default() {
let cfg = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: None,
};
let cfg = enabled_lock(None);
let mut metadata = std::collections::HashMap::new();
assert!(!apply_default_lock_retention_metadata(Some(&persisted_lock(&cfg)), &mut metadata));
assert!(!apply_default_lock_retention_metadata(Some(&cfg), &mut metadata));
assert!(metadata.is_empty());
}
#[test]
fn test_apply_bucket_default_lock_retention_applies_authoritative_default() {
let config = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: Some(ObjectLockRule {
default_retention: Some(DefaultRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::GOVERNANCE)),
days: Some(1),
years: None,
}),
}),
};
let state = ObjectLockConfigState::Configured {
config: persisted_lock(&config),
config: enabled_lock(Some(("GOVERNANCE", 1))),
updated_at: OffsetDateTime::now_utc(),
};
let mut metadata = std::collections::HashMap::new();
@@ -286,19 +256,10 @@ mod tests {
#[test]
fn empty_retention_metadata_does_not_suppress_bucket_default() {
let config = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: Some(ObjectLockRule {
default_retention: Some(DefaultRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::GOVERNANCE)),
days: Some(1),
years: None,
}),
}),
};
let config = enabled_lock(Some(("GOVERNANCE", 1)));
for name in [AMZ_OBJECT_LOCK_MODE_LOWER, AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER] {
let mut metadata = HashMap::from([(name.to_string(), String::new())]);
assert!(apply_default_lock_retention_metadata(Some(&persisted_lock(&config)), &mut metadata));
assert!(apply_default_lock_retention_metadata(Some(&config), &mut metadata));
assert_eq!(metadata.get(AMZ_OBJECT_LOCK_MODE_LOWER).map(String::as_str), Some("GOVERNANCE"));
assert!(!metadata[AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER].is_empty());
}
@@ -306,18 +267,8 @@ mod tests {
#[test]
fn test_apply_bucket_default_lock_retention_preserves_explicit_retention_path() {
let config = ObjectLockConfiguration {
object_lock_enabled: Some(ObjectLockEnabled::from_static(ObjectLockEnabled::ENABLED)),
rule: Some(ObjectLockRule {
default_retention: Some(DefaultRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
days: Some(1),
years: None,
}),
}),
};
let state = ObjectLockConfigState::Configured {
config: persisted_lock(&config),
config: enabled_lock(Some(("COMPLIANCE", 1))),
updated_at: OffsetDateTime::now_utc(),
};
let mut metadata = HashMap::new();
@@ -655,15 +606,15 @@ mod tests {
// [1] Normal case: No retention specified (empty metadata)
assert!(parse_object_lock_retention(None).is_ok());
assert!(parse_object_lock_retention(None).unwrap().is_empty());
let cleared = parse_object_lock_retention(Some(ObjectLockRetention::default())).unwrap();
let cleared = parse_object_lock_retention(Some(RequestedObjectLockRetention::default())).unwrap();
assert_eq!(cleared.get(AMZ_OBJECT_LOCK_MODE_LOWER).map(String::as_str), Some(""));
assert_eq!(cleared.get(AMZ_OBJECT_LOCK_RETAIN_UNTIL_DATE_LOWER).map(String::as_str), Some(""));
assert!(contains_key_str(&cleared, SUFFIX_OBJECTLOCK_RETENTION_TIMESTAMP));
// [2] Normal case: Retention with valid COMPLIANCE mode (future date)
let valid_compliance_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
retain_until_date: Some(datetime!(2030-01-01 00:00:00 UTC).into()),
let valid_compliance_retention = RequestedObjectLockRetention {
mode: Some("COMPLIANCE".to_owned()),
retain_until: Some(datetime!(2030-01-01 00:00:00 UTC)),
};
let compliance_metadata = parse_object_lock_retention(Some(valid_compliance_retention)).unwrap();
assert_eq!(compliance_metadata.get(AMZ_OBJECT_LOCK_MODE_LOWER).unwrap(), "COMPLIANCE");
@@ -678,26 +629,26 @@ mod tests {
assert!(retention_timestamp <= OffsetDateTime::now_utc());
// [3] Normal case: Retention with valid GOVERNANCE mode (future date)
let valid_governance_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::GOVERNANCE)),
retain_until_date: Some(datetime!(2030-01-01 00:00:00 UTC).into()),
let valid_governance_retention = RequestedObjectLockRetention {
mode: Some("GOVERNANCE".to_owned()),
retain_until: Some(datetime!(2030-01-01 00:00:00 UTC)),
};
let governance_metadata = parse_object_lock_retention(Some(valid_governance_retention)).unwrap();
assert_eq!(governance_metadata.get(AMZ_OBJECT_LOCK_MODE_LOWER).unwrap(), "GOVERNANCE");
// A retention update is either empty or has both fields.
let none_mode_retention = ObjectLockRetention {
let none_mode_retention = RequestedObjectLockRetention {
mode: None,
retain_until_date: Some(datetime!(2030-01-01 00:00:00 UTC).into()),
retain_until: Some(datetime!(2030-01-01 00:00:00 UTC)),
};
assert_eq!(
parse_object_lock_retention(Some(none_mode_retention)).unwrap_err().code(),
&S3ErrorCode::MalformedXML
);
let none_date_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
retain_until_date: None,
let none_date_retention = RequestedObjectLockRetention {
mode: Some("COMPLIANCE".to_owned()),
retain_until: None,
};
assert_eq!(
parse_object_lock_retention(Some(none_date_retention)).unwrap_err().code(),
@@ -705,9 +656,9 @@ mod tests {
);
// [6] Error case: Retention with invalid mode (non COMPLIANCE/GOVERNANCE)
let invalid_mode_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static("INVALID_MODE")),
retain_until_date: Some(datetime!(2030-01-01 00:00:00 UTC).into()),
let invalid_mode_retention = RequestedObjectLockRetention {
mode: Some("INVALID_MODE".to_owned()),
retain_until: Some(datetime!(2030-01-01 00:00:00 UTC)),
};
let err = parse_object_lock_retention(Some(invalid_mode_retention)).unwrap_err();
assert_eq!(err.code().as_str(), S3ErrorCode::MalformedXML.as_str());
@@ -717,9 +668,9 @@ mod tests {
);
// [7] Error case: Retention with past date should fail
let past_date_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
retain_until_date: Some(datetime!(2020-01-01 00:00:00 UTC).into()),
let past_date_retention = RequestedObjectLockRetention {
mode: Some("COMPLIANCE".to_owned()),
retain_until: Some(datetime!(2020-01-01 00:00:00 UTC)),
};
let err = parse_object_lock_retention(Some(past_date_retention)).unwrap_err();
assert_eq!(err.code().as_str(), S3ErrorCode::InvalidArgument.as_str());
@@ -730,9 +681,9 @@ mod tests {
.to_offset(UtcOffset::from_hms(5, 30, 45).expect("offset with seconds should be constructible"));
assert!(unsupported_rfc3339_date > OffsetDateTime::now_utc());
let unsupported_date_retention = ObjectLockRetention {
mode: Some(ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::COMPLIANCE)),
retain_until_date: Some(unsupported_rfc3339_date.into()),
let unsupported_date_retention = RequestedObjectLockRetention {
mode: Some("COMPLIANCE".to_owned()),
retain_until: Some(unsupported_rfc3339_date),
};
let err = parse_object_lock_retention(Some(unsupported_date_retention)).unwrap_err();
assert_eq!(err.code().as_str(), S3ErrorCode::InvalidArgument.as_str());
@@ -746,9 +697,7 @@ mod tests {
assert!(parse_object_lock_legal_hold(None).unwrap().is_empty());
// [2] Normal case: Legal hold with valid ON status
let valid_on_legal_hold = ObjectLockLegalHold {
status: Some(ObjectLockLegalHoldStatus::from_static(ObjectLockLegalHoldStatus::ON)),
};
let valid_on_legal_hold = RequestedObjectLegalHold(Some("ON".to_owned()));
let on_metadata = parse_object_lock_legal_hold(Some(valid_on_legal_hold)).unwrap();
assert_eq!(on_metadata.get(AMZ_OBJECT_LOCK_LEGAL_HOLD_LOWER).unwrap(), "ON");
let legal_hold_timestamp = get_str(&on_metadata, SUFFIX_OBJECTLOCK_LEGALHOLD_TIMESTAMP)
@@ -757,20 +706,16 @@ mod tests {
assert!(legal_hold_timestamp <= OffsetDateTime::now_utc());
// [3] Normal case: Legal hold with valid OFF status
let valid_off_legal_hold = ObjectLockLegalHold {
status: Some(ObjectLockLegalHoldStatus::from_static(ObjectLockLegalHoldStatus::OFF)),
};
let valid_off_legal_hold = RequestedObjectLegalHold(Some("OFF".to_owned()));
let off_metadata = parse_object_lock_legal_hold(Some(valid_off_legal_hold)).unwrap();
assert_eq!(off_metadata.get(AMZ_OBJECT_LOCK_LEGAL_HOLD_LOWER).unwrap(), "OFF");
let none_status_legal_hold = ObjectLockLegalHold { status: None };
let none_status_legal_hold = RequestedObjectLegalHold(None);
let err = parse_object_lock_legal_hold(Some(none_status_legal_hold)).expect_err("Status is required");
assert_eq!(err.code().as_str(), S3ErrorCode::MalformedXML.as_str());
// [5] Error case: Legal hold with invalid status (non ON/OFF)
let invalid_status_legal_hold = ObjectLockLegalHold {
status: Some(ObjectLockLegalHoldStatus::from_static("INVALID_STATUS")),
};
let invalid_status_legal_hold = RequestedObjectLegalHold(Some("INVALID_STATUS".to_owned()));
let err = parse_object_lock_legal_hold(Some(invalid_status_legal_hold)).unwrap_err();
assert_eq!(err.code().as_str(), S3ErrorCode::MalformedXML.as_str());
assert_eq!(
@@ -1094,7 +1039,7 @@ mod tests {
.source()
.is_some_and(|cause| cause.is::<http::header::InvalidHeaderValue>())
);
let wire = s3s::S3Error::from(error);
let wire = crate::app::storage_api::s3::S3Error::from(error);
assert_eq!(wire.status_code(), Some(StatusCode::INTERNAL_SERVER_ERROR));
assert!(
wire.source()