fix(protocols): preserve HeadBucket storage root compatibility

Resolve empty-bucket requests through the existing storage lookup at the
legacy edge. Keep authorization, operation counting and nonempty bucket
conversion unchanged. No gateway bucket-name contract changes.

Add two tests covering two positive and two negative cases: protocol root,
ordinary bucket, missing bucket and uninitialized storage. Check response
status/headers and one count per request. Disabling the compatibility
branch makes both tests fail; restoring it passes both after recompilation.

Verified on 4182d55d1: focused tests, gateway Clippy, and a rebuilt binary
with libunftp 0.25 using FTP_TLS: login 230, root and ordinary CWD 250,
missing bucket 550. Default Clippy and script-tests passed on 925e5d0c0.
After integrating a279b4bb6, gateway Clippy and prepush-quick passed.
The wire probe and focused tests were not rerun after that integration.
This commit is contained in:
overtrue
2026-11-14 20:57:53 +08:00
parent a279b4bb63
commit da5414c345
3 changed files with 87 additions and 0 deletions
@@ -232,6 +232,18 @@ impl FS {
req: S3Request<HeadBucketInput>,
) -> S3Result<S3Response<HeadBucketOutput>> {
record_s3_op(S3Operation::HeadBucket);
if req.input.bucket.is_empty() {
// Protocol adapters use the empty bucket for the storage root.
let Some(store) = self.server_ctx.object_store() else {
return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string()));
};
store
.get_bucket_info(&req.input.bucket, &BucketOptions::default())
.await
.map_err(crate::error::ApiError::from)?;
return Ok(S3Response::new(HeadBucketOutput::default()));
}
let usecase = s3_api::bucket_usecase_for(self);
through_gateway_seam(req, head_bucket::input_from_s3s, head_bucket::output_to_s3s, |_, input| {
usecase.execute_head_bucket(input)
@@ -0,0 +1,74 @@
// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Legacy HeadBucket compatibility for protocol roots and ordinary buckets.
use super::build_request;
use crate::app::gating_test_env::{run_large_stack_test, shared_gating_ambient};
use crate::app::storage_api::test::contract::bucket::{BucketOperations, MakeBucketOptions};
use crate::runtime_sources::ServerContextSlot;
use crate::storage::ecfs::*;
use http::Method;
fn head_bucket_count() -> u64 {
rustfs_io_metrics::s3_op_metrics_snapshot()
.into_iter()
.find(|snapshot| snapshot.op == S3Operation::HeadBucket.as_str())
.map(|snapshot| snapshot.total)
.unwrap_or_default()
}
#[test]
#[serial_test::serial]
fn head_bucket_preserves_protocol_root_response() {
run_large_stack_test("head-bucket-protocol-root", || async {
let context = shared_gating_ambient().await;
let slot = ServerContextSlot::new();
assert!(slot.install(context));
let store = slot.object_store().expect("initialized store");
let bucket = format!("head-root-{}", uuid::Uuid::new_v4().simple());
store.make_bucket(&bucket, &MakeBucketOptions::default()).await.unwrap();
let fs = FS::with_server_ctx(slot);
for name in ["", bucket.as_str()] {
let input = HeadBucketInput::builder().bucket(name.to_owned()).build().unwrap();
let before = head_bucket_count();
let response = fs
.head_bucket(build_request(input, Method::HEAD))
.await
.expect("bucket exists");
assert!(response.status.is_none());
assert!(response.headers.is_empty());
assert_eq!(head_bucket_count(), before + 1);
}
let input = HeadBucketInput::builder()
.bucket(format!("missing-{bucket}"))
.build()
.unwrap();
let before = head_bucket_count();
let error = fs.head_bucket(build_request(input, Method::HEAD)).await.unwrap_err();
assert_eq!(error.code(), &S3ErrorCode::NoSuchBucket);
assert_eq!(head_bucket_count(), before + 1);
});
}
#[tokio::test]
async fn head_bucket_root_requires_initialized_store() {
let fs = FS::with_server_ctx(ServerContextSlot::new());
let input = HeadBucketInput::builder().bucket(String::new()).build().unwrap();
let before = head_bucket_count();
let error = fs.head_bucket(build_request(input, Method::HEAD)).await.unwrap_err();
assert_eq!(error.code(), &S3ErrorCode::InternalError);
assert_eq!(error.message(), Some("Not init"));
assert_eq!(head_bucket_count(), before + 1);
}
@@ -49,6 +49,7 @@ fn store_uninitialized_premise_holds() -> bool {
}
mod bucket_access;
mod bucket_core;
mod bucket_replication_lifecycle;
mod listing_multipart;
mod object_commit;