From dd2343a0b5b21fccb220e21cbaf6e1d08912c12a Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Thu, 12 Oct 2023 15:27:09 +0400 Subject: [PATCH 1/2] layer: Return unsupported error if meta parameter is empty Closes #846. Signed-off-by: Evgenii Baidakov --- CHANGELOG.md | 3 +++ api/handler/util.go | 4 ++++ api/layer/neofs.go | 3 +++ api/layer/object.go | 6 ++++++ docs/aws_s3_compat.md | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d93ddff6..c0f35c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This document outlines major changes between releases. ## [Unreleased] +### Added +- Passing an empty meta parameter value raises "Your metadata headers are not supported." error. + ## [0.29.0] - 2023-09-28 ### Added diff --git a/api/handler/util.go b/api/handler/util.go index 9ae3e7c6..be4eccc3 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -39,6 +39,10 @@ func transformToS3Error(err error) error { return s3errors.GetAPIError(s3errors.ErrAccessDenied) } + if errorsStd.Is(err, layer.ErrMetaEmptyParameterValue) { + return s3errors.GetAPIError(s3errors.ErrUnsupportedMetadata) + } + return s3errors.GetAPIError(s3errors.ErrInternalError) } diff --git a/api/layer/neofs.go b/api/layer/neofs.go index 5a7dcd78..c06481d2 100644 --- a/api/layer/neofs.go +++ b/api/layer/neofs.go @@ -127,6 +127,9 @@ type PrmObjectDelete struct { // ErrAccessDenied is returned from NeoFS in case of access violation. var ErrAccessDenied = errors.New("access denied") +// ErrMetaEmptyParameterValue describes situation when meta parameter was passed but with empty value. +var ErrMetaEmptyParameterValue = errors.New("meta empty parameter value") + // NeoFS represents virtual connection to NeoFS network. type NeoFS interface { // CreateContainer creates and saves parameterized container in NeoFS. diff --git a/api/layer/object.go b/api/layer/object.go index c272be4a..173d9188 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -183,6 +183,8 @@ func ParseCompletedPartHeader(hdr string) (*Part, error) { } // PutObject stores object into NeoFS, took payload from io.Reader. +// +// Returns [ErrMetaEmptyParameterValue] error if any attribute parameter is empty. func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.ExtendedObjectInfo, error) { owner := n.Owner(ctx) @@ -240,6 +242,10 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Extend prm.Attributes = make([][2]string, 0, len(p.Header)) for k, v := range p.Header { + if v == "" { + return nil, ErrMetaEmptyParameterValue + } + prm.Attributes = append(prm.Attributes, [2]string{k, v}) } diff --git a/docs/aws_s3_compat.md b/docs/aws_s3_compat.md index e7712c46..a67c2f86 100644 --- a/docs/aws_s3_compat.md +++ b/docs/aws_s3_compat.md @@ -255,3 +255,9 @@ See also `GetObject` and other method parameters. | 🔵 | DeleteBucketWebsite | | | 🔵 | GetBucketWebsite | | | 🔵 | PutBucketWebsite | | + + +## Metadata + +Each meta parameter value must be non-empty. If any parameter value is an empty, +then "Your metadata headers are not supported." error will be returned on the object put operation. From 4e5a06acfb0d43bf976916e6a4a614d58a1b3e05 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Thu, 12 Oct 2023 15:27:52 +0400 Subject: [PATCH 2/2] handler: Remove unnecessary prefix for system package Signed-off-by: Evgenii Baidakov --- api/handler/util.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/handler/util.go b/api/handler/util.go index be4eccc3..4c75beff 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -2,7 +2,7 @@ package handler import ( "context" - errorsStd "errors" + "errors" "net/http" "strconv" "strings" @@ -34,12 +34,12 @@ func transformToS3Error(err error) error { return err } - if errorsStd.Is(err, layer.ErrAccessDenied) || - errorsStd.Is(err, layer.ErrNodeAccessDenied) { + if errors.Is(err, layer.ErrAccessDenied) || + errors.Is(err, layer.ErrNodeAccessDenied) { return s3errors.GetAPIError(s3errors.ErrAccessDenied) } - if errorsStd.Is(err, layer.ErrMetaEmptyParameterValue) { + if errors.Is(err, layer.ErrMetaEmptyParameterValue) { return s3errors.GetAPIError(s3errors.ErrUnsupportedMetadata) }