mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 04:52:36 +00:00
fix(gateway): preserve object retention date offsets
Use the validated request offset and full timestamp precision when projecting PutObject and PutObjectRetention dates into authorization and storage.
Signed requests verify exact stored dates and version isolation for positive and negative offsets and UTC. Policy tests cover denied dates and the typed date supplied by PutObject authorization.
On b2b4f0c4, 175 focused tests and six raw xl.meta checks passed. The UTC-only control and five targeted mutations failed at their intended assertions. Both Clippy feature configurations passed.
This commit is contained in:
Generated
+11
-11
@@ -10266,8 +10266,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustfs-gateway"
|
||||
version = "0.64.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
version = "0.66.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"bytes",
|
||||
@@ -10313,8 +10313,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustfs-gateway-core"
|
||||
version = "0.61.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
version = "0.63.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
@@ -10335,7 +10335,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustfs-gateway-http"
|
||||
version = "0.1.4"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"hmac 0.13.0",
|
||||
"http 1.5.0",
|
||||
@@ -10353,7 +10353,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustfs-gateway-macros"
|
||||
version = "0.1.4"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -10363,7 +10363,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustfs-gateway-sig"
|
||||
version = "0.15.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"hmac 0.13.0",
|
||||
"http 1.5.0",
|
||||
@@ -10378,7 +10378,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustfs-gateway-stream"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytes",
|
||||
@@ -10388,8 +10388,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustfs-gateway-types"
|
||||
version = "0.41.0+aws.2026-10-02"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
version = "0.42.0+aws.2026-10-02"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"crc-fast",
|
||||
@@ -10412,7 +10412,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustfs-gateway-xml"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=75757292b9617080cbb1bb7f880db8da9b34912c#75757292b9617080cbb1bb7f880db8da9b34912c"
|
||||
source = "git+https://github.com/rustfs/gateway.git?rev=44f9a2422d745ffba952347ec91b0332ef2667a4#44f9a2422d745ffba952347ec91b0332ef2667a4"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
]
|
||||
|
||||
+4
-4
@@ -151,14 +151,14 @@ rustfs-zip = { path = "./crates/zip", version = "1.0.5" }
|
||||
# engine crates move onto from s3s (rustfs/backlog#2745). The one pin of the
|
||||
# gateway in this workspace; no crate may enable a `compat-s3s*` feature except
|
||||
# the s3s-facing edge of the rustfs binary.
|
||||
rustfs-gateway-types = { git = "https://github.com/rustfs/gateway.git", rev = "75757292b9617080cbb1bb7f880db8da9b34912c", version = "0.41.0", default-features = false }
|
||||
rustfs-gateway-stream = { git = "https://github.com/rustfs/gateway.git", rev = "75757292b9617080cbb1bb7f880db8da9b34912c", version = "0.2.0", default-features = false }
|
||||
rustfs-gateway-types = { git = "https://github.com/rustfs/gateway.git", rev = "44f9a2422d745ffba952347ec91b0332ef2667a4", version = "0.42.0", default-features = false }
|
||||
rustfs-gateway-stream = { git = "https://github.com/rustfs/gateway.git", rev = "44f9a2422d745ffba952347ec91b0332ef2667a4", version = "0.2.0", default-features = false }
|
||||
# The gateway framework itself, consumed for its extension traits by the ring-2
|
||||
# adapter. `default-features = false` keeps the `server` feature, and with it the
|
||||
# server crate, out of the build.
|
||||
rustfs-gateway = { git = "https://github.com/rustfs/gateway.git", rev = "75757292b9617080cbb1bb7f880db8da9b34912c", version = "0.64.0", default-features = false }
|
||||
rustfs-gateway = { git = "https://github.com/rustfs/gateway.git", rev = "44f9a2422d745ffba952347ec91b0332ef2667a4", version = "0.66.0", default-features = false }
|
||||
# Test-only: builds the `EffectiveHost` a host-resolution test queries with.
|
||||
rustfs-gateway-http = { git = "https://github.com/rustfs/gateway.git", rev = "75757292b9617080cbb1bb7f880db8da9b34912c", default-features = false }
|
||||
rustfs-gateway-http = { git = "https://github.com/rustfs/gateway.git", rev = "44f9a2422d745ffba952347ec91b0332ef2667a4", default-features = false }
|
||||
|
||||
# Async Runtime and Networking
|
||||
async-channel = "2.5.0"
|
||||
|
||||
@@ -240,10 +240,14 @@ impl Served for dto::PutObjectLegalHold {
|
||||
}
|
||||
}
|
||||
|
||||
fn retention_fields(retention: &dto::ObjectLockRetention) -> S3Result<RequestedObjectLockRetention> {
|
||||
fn retention_fields(request: &Req<dto::PutObjectRetention>) -> S3Result<RequestedObjectLockRetention> {
|
||||
let retention = &request.input().retention;
|
||||
Ok(RequestedObjectLockRetention {
|
||||
mode: retention.mode.as_ref().map(|mode| mode.as_str().to_owned()),
|
||||
retain_until: super::object_write::retain_until(retention.retain_until_date.as_ref())?,
|
||||
retain_until: super::object_write::retain_until_with_offset(
|
||||
retention.retain_until_date.as_ref(),
|
||||
request.context().object_lock_retain_until_offset_seconds(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -262,21 +266,16 @@ impl Served for dto::PutObjectRetention {
|
||||
input.bucket.as_str(),
|
||||
input.key.as_str(),
|
||||
input.version_id.as_deref(),
|
||||
retention_fields(&input.retention)?,
|
||||
retention_fields(request)?,
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
|
||||
async fn execute(context: Option<Arc<AppContext>>, envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
|
||||
let retention = retention_fields(&request)?;
|
||||
let input = request.into_input();
|
||||
ObjectMetaUsecase::with_context(context)
|
||||
.put_object_retention_fields(
|
||||
envelope,
|
||||
input.bucket.as_str(),
|
||||
input.key.as_str(),
|
||||
input.version_id,
|
||||
Some(retention_fields(&input.retention)?),
|
||||
)
|
||||
.put_object_retention_fields(envelope, input.bucket.as_str(), input.key.as_str(), input.version_id, Some(retention))
|
||||
.await
|
||||
.map(Resp::new)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl Served for dto::PutObject {
|
||||
let input = request.input();
|
||||
let bucket = input.bucket.as_str().to_owned();
|
||||
let key = input.key.as_str().to_owned();
|
||||
let retain_until = retain_until(input.object_lock_retain_until_date.as_ref());
|
||||
let retain_until = put_object_retain_until(request);
|
||||
let version_id = request_version_id(envelope);
|
||||
let specific_etag = input.if_match.as_deref().is_some_and(|value| value.trim() != "*");
|
||||
let legal_hold = input.object_lock_legal_hold_status.is_some();
|
||||
@@ -63,7 +63,8 @@ impl Served for dto::PutObject {
|
||||
}
|
||||
|
||||
async fn execute(context: Option<Arc<AppContext>>, envelope: RequestEnvelope, request: Req<Self>) -> S3Result<Resp<Self>> {
|
||||
let mut input = native_input(request.into_input())?;
|
||||
let retain_until = put_object_retain_until(&request)?;
|
||||
let mut input = native_input(request.into_input(), retain_until);
|
||||
input.version_id = request_version_id(&envelope);
|
||||
if let Some(algorithm) = trailer_checksum_algorithm(&envelope)? {
|
||||
input.checksum_algorithm = Some(algorithm.wire_name().to_owned());
|
||||
@@ -187,18 +188,38 @@ pub(super) fn request_version_id(envelope: &RequestEnvelope) -> Option<String> {
|
||||
.map(|(_, value)| value.into_owned())
|
||||
}
|
||||
|
||||
fn put_object_retain_until(request: &Req<dto::PutObject>) -> S3Result<Option<time::OffsetDateTime>> {
|
||||
retain_until_with_offset(
|
||||
request.input().object_lock_retain_until_date.as_ref(),
|
||||
request.context().object_lock_retain_until_offset_seconds(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn retain_until(value: Option<&Timestamp>) -> S3Result<Option<time::OffsetDateTime>> {
|
||||
retain_until_with_offset(value, None)
|
||||
}
|
||||
|
||||
pub(super) fn retain_until_with_offset(
|
||||
value: Option<&Timestamp>,
|
||||
offset_seconds: Option<i32>,
|
||||
) -> S3Result<Option<time::OffsetDateTime>> {
|
||||
value
|
||||
.map(|value| {
|
||||
time::OffsetDateTime::from_unix_timestamp_nanos(
|
||||
let invalid_date = || s3_error!(InvalidArgument, "Invalid retain-until date");
|
||||
let instant = time::OffsetDateTime::from_unix_timestamp_nanos(
|
||||
i128::from(value.secs()) * 1_000_000_000 + i128::from(value.subsec_nanos()),
|
||||
)
|
||||
.map_err(|_| s3_error!(InvalidArgument, "Invalid retain-until date"))
|
||||
.map_err(|_| invalid_date())?;
|
||||
let Some(seconds) = offset_seconds else {
|
||||
return Ok(instant);
|
||||
};
|
||||
let offset = time::UtcOffset::from_whole_seconds(seconds).map_err(|_| invalid_date())?;
|
||||
instant.checked_to_offset(offset).ok_or_else(invalid_date)
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn native_input(input: dto::PutObjectInput) -> S3Result<PutObjectWriteInput> {
|
||||
fn native_input(input: dto::PutObjectInput, retain_until: Option<time::OffsetDateTime>) -> PutObjectWriteInput {
|
||||
let checksum = |algorithm| {
|
||||
input
|
||||
.checksum_spec
|
||||
@@ -206,7 +227,7 @@ fn native_input(input: dto::PutObjectInput) -> S3Result<PutObjectWriteInput> {
|
||||
.filter(|value| value.algorithm() == algorithm)
|
||||
.map(|value| value.render_base64().to_owned())
|
||||
};
|
||||
Ok(PutObjectWriteInput {
|
||||
PutObjectWriteInput {
|
||||
checksum_crc32: checksum(ChecksumAlgorithm::Crc32),
|
||||
checksum_crc32c: checksum(ChecksumAlgorithm::Crc32c),
|
||||
checksum_sha1: checksum(ChecksumAlgorithm::Sha1),
|
||||
@@ -220,7 +241,7 @@ fn native_input(input: dto::PutObjectInput) -> S3Result<PutObjectWriteInput> {
|
||||
content_length: Some(input.content_length),
|
||||
metadata: Some(input.metadata.into_iter().collect()),
|
||||
specific_if_none_match: input.if_none_match.as_deref().is_some_and(|value| value.trim() != "*"),
|
||||
object_lock_retain_until_date: retain_until(input.object_lock_retain_until_date.as_ref())?,
|
||||
object_lock_retain_until_date: retain_until,
|
||||
cache_control: input.cache_control,
|
||||
content_disposition: input.content_disposition,
|
||||
content_encoding: input.content_encoding,
|
||||
@@ -240,7 +261,7 @@ fn native_input(input: dto::PutObjectInput) -> S3Result<PutObjectWriteInput> {
|
||||
storage_class: input.storage_class.map(|value| value.as_str().to_owned()),
|
||||
website_redirect_location: input.website_redirect_location,
|
||||
checksum_algorithm: input.checksum_algorithm.map(|value| value.as_str().to_owned()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn native_output(output: PutObjectWriteOutput) -> S3Result<Resp<dto::PutObject>> {
|
||||
|
||||
@@ -239,6 +239,67 @@ async fn put_authorization_honors_request_object_tag_policy_on_both_edges() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn put_authorization_installs_the_decoded_retention_date() {
|
||||
use crate::server::gateway_handlers::error::handler_error;
|
||||
use rustfs_gateway::{Handler, HandlerResult, RegionSet, ServiceBuilder, SigV4Authenticator, StaticCredentials, allow_when};
|
||||
|
||||
const DATE: &str = "2099-01-02T08:00:00.123456789+08:00";
|
||||
struct Probe(Arc<ServerContextSlot>);
|
||||
|
||||
impl Handler<dto::PutObject> for Probe {
|
||||
async fn call(&self, request: Req<dto::PutObject>) -> HandlerResult<dto::PutObject> {
|
||||
let mut envelope = envelope(&self.0, HeaderMap::new());
|
||||
<dto::PutObject as Served>::authorize(&mut envelope, &request)
|
||||
.await
|
||||
.map_err(handler_error)?;
|
||||
let date = AuthorizationRequest::requested_retain_until(&envelope)
|
||||
.expect("authorized date")
|
||||
.0;
|
||||
assert_eq!(date.format(&time::format_description::well_known::Rfc3339).unwrap(), DATE);
|
||||
Ok(Resp::new(dto::PutObjectOutput::default()))
|
||||
}
|
||||
}
|
||||
|
||||
let (server, bucket) = fixture(&[]).await;
|
||||
set_policy(
|
||||
&bucket,
|
||||
serde_json::json!({
|
||||
"Effect": "Allow",
|
||||
"Principal": {"AWS": "*"},
|
||||
"Action": ["s3:PutObject", "s3:PutObjectRetention"],
|
||||
"Resource": format!("arn:aws:s3:::{bucket}/allowed"),
|
||||
"Condition": {"NumericGreaterThanEquals": {"s3:object-lock-remaining-retention-days": "1"}},
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
let authenticator =
|
||||
SigV4Authenticator::new(Arc::new(StaticCredentials::new()), RegionSet::new(["us-east-1"]).unwrap()).rustfs_profile();
|
||||
let service = ServiceBuilder::new()
|
||||
.rustfs_profile()
|
||||
.authenticator(authenticator)
|
||||
.authorizer(allow_when(|_| true))
|
||||
.register::<dto::PutObject, _>(Arc::new(Probe(server)))
|
||||
.build()
|
||||
.unwrap();
|
||||
let write = |date: Option<&str>| {
|
||||
let mut request = http::Request::builder()
|
||||
.method(Method::PUT)
|
||||
.uri(format!("/{bucket}/allowed"))
|
||||
.header("host", "localhost")
|
||||
.header("content-length", "0");
|
||||
if let Some(date) = date {
|
||||
request = request
|
||||
.header("x-amz-object-lock-mode", "GOVERNANCE")
|
||||
.header("x-amz-object-lock-retain-until-date", date);
|
||||
}
|
||||
request.body(http_body_util::Empty::<Bytes>::new()).unwrap()
|
||||
};
|
||||
assert_eq!(service.call(write(None)).await.status(), http::StatusCode::FORBIDDEN);
|
||||
assert_eq!(service.call(write(Some(DATE))).await.status(), http::StatusCode::OK);
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("fixture producer failure")]
|
||||
struct FixtureProducerFailure;
|
||||
@@ -419,7 +480,7 @@ fn native_put_projection_preserves_unvalidated_write_fields() {
|
||||
checksum_spec: Some(rustfs_gateway_types::ChecksumSpec::parse_header("x-amz-checksum-crc32", "NSRBwg==").unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
let input = native_input(input).unwrap();
|
||||
let input = native_input(input, None);
|
||||
assert_eq!(input.storage_class.as_deref(), Some("INVALID"));
|
||||
assert_eq!(input.server_side_encryption.as_deref(), Some("INVALID"));
|
||||
assert_eq!(input.object_lock_mode.as_deref(), Some("INVALID"));
|
||||
|
||||
@@ -1039,3 +1039,138 @@ fn gateway_put_object_retention_edits_only_the_authorized_version() {
|
||||
fn legacy_put_object_retention_edits_only_the_authorized_version() {
|
||||
put_retention_on_an_explicit_version(LEGACY);
|
||||
}
|
||||
|
||||
const RETAIN_UNTIL_HEADER: &str = "x-amz-object-lock-retain-until-date";
|
||||
const RETENTION_DATES: [&str; 3] = [
|
||||
"2099-01-02T08:00:00.123456789+08:00",
|
||||
"2099-01-03T16:30:00.987654321-07:30",
|
||||
"2099-01-05T00:00:00.000000001Z",
|
||||
];
|
||||
|
||||
async fn write_retention_xml(
|
||||
client: &super::object_write::WireClient<'_>,
|
||||
path: &str,
|
||||
xml: &str,
|
||||
) -> super::object_write::WireAnswer {
|
||||
use md5::Digest as _;
|
||||
|
||||
let md5 = base64_simd::STANDARD.encode_to_string(md5::Md5::digest(xml.as_bytes()));
|
||||
client
|
||||
.request(
|
||||
"PUT",
|
||||
path,
|
||||
xml.as_bytes(),
|
||||
&[("content-type", "application/xml"), ("content-md5", &md5)],
|
||||
Some(xml.len()),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gateway_put_object_retention_preserves_the_authorized_date_on_disk() {
|
||||
use super::object_write::WireClient;
|
||||
|
||||
temp_env::with_var(super::ENV_S3_STACK, GATEWAY, || {
|
||||
super::common::run_embedded_test(|| async {
|
||||
let volume = tempfile::tempdir().unwrap();
|
||||
let (server, bucket, old, latest) = lock_write_fixture(volume.path()).await;
|
||||
let endpoint = server.endpoint();
|
||||
let root = WireClient {
|
||||
endpoint: &endpoint,
|
||||
access_key: server.access_key(),
|
||||
secret_key: server.secret_key(),
|
||||
};
|
||||
let writer = WireClient {
|
||||
endpoint: &endpoint,
|
||||
access_key: "retention-date-writer",
|
||||
secret_key: USER_SECRET_KEY,
|
||||
};
|
||||
attach_tagging_policy(
|
||||
writer.access_key,
|
||||
"s3:PutObjectRetention",
|
||||
&format!("arn:aws:s3:::{bucket}/{KEY}"),
|
||||
serde_json::json!({"StringEquals": {
|
||||
"s3:VersionId": old,
|
||||
"s3:object-lock-retain-until-date": RETENTION_DATES[0]
|
||||
}}),
|
||||
)
|
||||
.await;
|
||||
|
||||
let path = format!("/{bucket}/{KEY}?retention&versionId={old}");
|
||||
let metadata_path = volume.path().join(&bucket).join(KEY).join("xl.meta");
|
||||
let initial = std::fs::read(&metadata_path).unwrap();
|
||||
let latest_initial = lock_disk_version(volume.path(), &bucket, &latest);
|
||||
let xml = |date| format!("<Retention><Mode>GOVERNANCE</Mode><RetainUntilDate>{date}</RetainUntilDate></Retention>");
|
||||
|
||||
for (actor, body, status, code) in [
|
||||
(&writer, xml("2099-01-02T00:00:00.123456789Z"), 403, "<Code>AccessDenied</Code>"),
|
||||
(&writer, "<Retention/>".to_owned(), 403, "<Code>AccessDenied</Code>"),
|
||||
(&root, xml("invalid-date"), 400, "<Code>MalformedXML</Code>"),
|
||||
] {
|
||||
let answer = write_retention_xml(actor, &path, &body).await;
|
||||
assert_eq!(answer.status, status, "{}", answer.body);
|
||||
assert!(answer.body.contains(code), "{}", answer.body);
|
||||
assert_eq!(std::fs::read(&metadata_path).unwrap(), initial);
|
||||
}
|
||||
|
||||
for (actor, date) in [
|
||||
(&writer, RETENTION_DATES[0]),
|
||||
(&root, RETENTION_DATES[1]),
|
||||
(&root, RETENTION_DATES[2]),
|
||||
] {
|
||||
let answer = write_retention_xml(actor, &path, &xml(date)).await;
|
||||
assert_eq!(answer.status, 200, "retain until {date}: {}", answer.body);
|
||||
let changed = lock_disk_version(volume.path(), &bucket, &old);
|
||||
assert_eq!(changed.metadata.get(RETAIN_UNTIL_HEADER).map(String::as_str), Some(date));
|
||||
assert_eq!(lock_disk_version(volume.path(), &bucket, &latest), latest_initial);
|
||||
}
|
||||
server.shutdown().await;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gateway_put_object_preserves_retention_header_date_on_disk() {
|
||||
use super::object_write::WireClient;
|
||||
|
||||
temp_env::with_var(super::ENV_S3_STACK, GATEWAY, || {
|
||||
super::common::run_embedded_test(|| async {
|
||||
let volume = tempfile::tempdir().unwrap();
|
||||
let (server, bucket, old, latest) = lock_write_fixture(volume.path()).await;
|
||||
let endpoint = server.endpoint();
|
||||
let client = WireClient {
|
||||
endpoint: &endpoint,
|
||||
access_key: server.access_key(),
|
||||
secret_key: server.secret_key(),
|
||||
};
|
||||
let path = format!("/{bucket}/{KEY}");
|
||||
let metadata_path = volume.path().join(&bucket).join(KEY).join("xl.meta");
|
||||
let initial = std::fs::read(&metadata_path).unwrap();
|
||||
let old_initial = lock_disk_version(volume.path(), &bucket, &old).metadata;
|
||||
let latest_initial = lock_disk_version(volume.path(), &bucket, &latest).metadata;
|
||||
let mode = ("x-amz-object-lock-mode", "GOVERNANCE");
|
||||
|
||||
for headers in [vec![mode], vec![mode, (RETAIN_UNTIL_HEADER, "invalid-date")]] {
|
||||
let answer = client.request("PUT", &path, b"object", &headers, Some(6)).await;
|
||||
assert_eq!(answer.status, 400, "{}", answer.body);
|
||||
assert_eq!(std::fs::read(&metadata_path).unwrap(), initial);
|
||||
}
|
||||
|
||||
for date in [
|
||||
None,
|
||||
Some(RETENTION_DATES[0]),
|
||||
Some(RETENTION_DATES[1]),
|
||||
Some(RETENTION_DATES[2]),
|
||||
] {
|
||||
let headers = date.map_or_else(Vec::new, |date| vec![mode, (RETAIN_UNTIL_HEADER, date)]);
|
||||
let answer = client.request("PUT", &path, b"object", &headers, Some(6)).await;
|
||||
assert_eq!(answer.status, 200, "retain until {date:?}: {}", answer.body);
|
||||
let written = lock_disk_version(volume.path(), &bucket, &answer.headers["x-amz-version-id"]);
|
||||
assert_eq!(written.metadata.get(RETAIN_UNTIL_HEADER).map(String::as_str), date);
|
||||
assert_eq!(lock_disk_version(volume.path(), &bucket, &old).metadata, old_initial);
|
||||
assert_eq!(lock_disk_version(volume.path(), &bucket, &latest).metadata, latest_initial);
|
||||
}
|
||||
server.shutdown().await;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -66,16 +66,16 @@ use sha2::{Digest, Sha256};
|
||||
use std::collections::BTreeMap;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
struct WireClient<'a> {
|
||||
endpoint: &'a str,
|
||||
access_key: &'a str,
|
||||
secret_key: &'a str,
|
||||
pub(super) struct WireClient<'a> {
|
||||
pub(super) endpoint: &'a str,
|
||||
pub(super) access_key: &'a str,
|
||||
pub(super) secret_key: &'a str,
|
||||
}
|
||||
|
||||
struct WireAnswer {
|
||||
status: u16,
|
||||
headers: BTreeMap<String, String>,
|
||||
body: String,
|
||||
pub(super) struct WireAnswer {
|
||||
pub(super) status: u16,
|
||||
pub(super) headers: BTreeMap<String, String>,
|
||||
pub(super) body: String,
|
||||
}
|
||||
|
||||
fn hex(bytes: &[u8]) -> String {
|
||||
@@ -164,7 +164,7 @@ impl WireClient<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn request(
|
||||
pub(super) async fn request(
|
||||
&self,
|
||||
method: &str,
|
||||
path: &str,
|
||||
|
||||
Reference in New Issue
Block a user