test(e2e): require exact retention errors (#6535)

This commit is contained in:
Zhengchao An
2026-08-25 04:31:29 +08:00
committed by GitHub
parent 4d43f1ea8a
commit d63ca1f5f5
2 changed files with 6 additions and 11 deletions
+4 -6
View File
@@ -23,6 +23,7 @@
use aws_sdk_s3::Client; use aws_sdk_s3::Client;
use aws_sdk_s3::error::SdkError; use aws_sdk_s3::error::SdkError;
use aws_sdk_s3::operation::delete_object::DeleteObjectError; use aws_sdk_s3::operation::delete_object::DeleteObjectError;
use aws_sdk_s3::operation::put_object_retention::PutObjectRetentionError;
use aws_sdk_s3::primitives::ByteStream; use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::types::{ use aws_sdk_s3::types::{
DefaultRetention, ObjectLockConfiguration, ObjectLockEnabled, ObjectLockLegalHold, ObjectLockLegalHoldStatus, ObjectLockMode, DefaultRetention, ObjectLockConfiguration, ObjectLockEnabled, ObjectLockLegalHold, ObjectLockLegalHoldStatus, ObjectLockMode,
@@ -182,11 +183,8 @@ pub async fn put_object_retention(
mode: ObjectLockRetentionMode, mode: ObjectLockRetentionMode,
retain_until: DateTime<Utc>, retain_until: DateTime<Utc>,
bypass_governance: bool, bypass_governance: bool,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(), Box<SdkError<PutObjectRetentionError>>> {
// AWS SDK requires UTC time without timezone offset (e.g., "2026-01-24T11:20:14Z") let retain_until_datetime = aws_sdk_s3::primitives::DateTime::from_secs(retain_until.timestamp());
let retain_until_str = retain_until.format("%Y-%m-%dT%H:%M:%SZ").to_string();
let retain_until_datetime =
aws_sdk_s3::primitives::DateTime::from_str(&retain_until_str, aws_sdk_s3::primitives::DateTimeFormat::DateTime)?;
let retention = ObjectLockRetention::builder() let retention = ObjectLockRetention::builder()
.mode(mode.clone()) .mode(mode.clone())
@@ -204,7 +202,7 @@ pub async fn put_object_retention(
request = request.version_id(vid); request = request.version_id(vid);
} }
request.send().await?; request.send().await.map_err(Box::new)?;
info!("Put object retention on {} with mode {:?}", key, mode); info!("Put object retention on {} with mode {:?}", key, mode);
Ok(()) Ok(())
} }
@@ -1475,7 +1475,7 @@ async fn test_put_retention_compliance_cannot_shorten() {
) )
.await; .await;
assert!(shorten_result.is_err(), "Shortening COMPLIANCE retention should fail"); assert_access_denied(shorten_result, "Shortening COMPLIANCE retention should fail");
info!("✅ Test passed: Cannot shorten COMPLIANCE retention"); info!("✅ Test passed: Cannot shorten COMPLIANCE retention");
} }
@@ -1598,10 +1598,7 @@ async fn test_put_retention_governance_shorten_requires_bypass() {
) )
.await; .await;
assert!( assert_access_denied(shorten_without_bypass, "Shortening GOVERNANCE retention without bypass should fail");
shorten_without_bypass.is_err(),
"Shortening GOVERNANCE retention without bypass should fail"
);
// Shorten with bypass - should succeed // Shorten with bypass - should succeed
let shorten_with_bypass = put_object_retention( let shorten_with_bypass = put_object_retention(