forked from TrueCloudLab/frostfs-s3-gw
[#583] Fix list-buckets vhs routing
The problem is that with VHS requests, the list-buckets operation does not work because the request is filtered on list-objects-v1. Since list-buckets can also have query parameters, in the end it is necessary to distinguish list-buckets from list-objects-v1 only by the presence of the bucket name in the URL (provided that the request is in VHS style). Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
f2274b2786
commit
09412d8f20
4 changed files with 126 additions and 35 deletions
|
@ -903,6 +903,78 @@ func TestRouterListObjectsV2Domains(t *testing.T) {
|
|||
require.Equal(t, s3middleware.ListObjectsV2Operation, resp.Method)
|
||||
}
|
||||
|
||||
func TestRouterListingVHS(t *testing.T) {
|
||||
baseDomain := "domain.com"
|
||||
baseDomainWithBkt := "bucket.domain.com"
|
||||
chiRouter := prepareRouter(t, enableVHSDomains(baseDomain))
|
||||
chiRouter.handler.buckets["bucket"] = &data.BucketInfo{}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
host string
|
||||
queries string
|
||||
expectedOperation string
|
||||
notSupported bool
|
||||
}{
|
||||
{
|
||||
name: "list-object-v1 without query params",
|
||||
host: baseDomainWithBkt,
|
||||
expectedOperation: s3middleware.ListObjectsV1Operation,
|
||||
},
|
||||
{
|
||||
name: "list-buckets without query params",
|
||||
host: baseDomain,
|
||||
expectedOperation: s3middleware.ListBucketsOperation,
|
||||
},
|
||||
{
|
||||
name: "list-objects-v1 with prefix param",
|
||||
host: baseDomainWithBkt,
|
||||
queries: func() string {
|
||||
query := make(url.Values)
|
||||
query.Set(s3middleware.QueryPrefix, "prefix")
|
||||
return query.Encode()
|
||||
}(),
|
||||
expectedOperation: s3middleware.ListObjectsV1Operation,
|
||||
},
|
||||
{
|
||||
name: "list-buckets with prefix param",
|
||||
host: baseDomain,
|
||||
queries: func() string {
|
||||
query := make(url.Values)
|
||||
query.Set(s3middleware.QueryPrefix, "prefix")
|
||||
return query.Encode()
|
||||
}(),
|
||||
expectedOperation: s3middleware.ListBucketsOperation,
|
||||
},
|
||||
{
|
||||
name: "not supported operation",
|
||||
host: baseDomain,
|
||||
queries: func() string {
|
||||
query := make(url.Values)
|
||||
query.Set("invalid", "invalid")
|
||||
return query.Encode()
|
||||
}(),
|
||||
notSupported: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
r.URL.RawQuery = tc.queries
|
||||
r.Host = tc.host
|
||||
chiRouter.ServeHTTP(w, r)
|
||||
|
||||
if tc.notSupported {
|
||||
assertAPIError(t, w, apierr.ErrNotSupported)
|
||||
return
|
||||
}
|
||||
|
||||
resp := readResponse(t, w)
|
||||
require.Equal(t, tc.expectedOperation, resp.Method)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func enableVHSDomains(domains ...string) option {
|
||||
return func(cfg *Config) {
|
||||
setting := cfg.MiddlewareSettings.(*middlewareSettingsMock)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue