From e4d55df625675030e10e77085cc44a13c79072cf Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 25 Jun 2024 15:31:46 +0300 Subject: [PATCH 1/2] [#117] Fix FrostFS interface usage HTTP Gateway expects io.Reader to work with payload, however `WithPayload` flag reads whole payload into header object. Signed-off-by: Alex Vanin --- internal/frostfs/frostfs.go | 46 ++++++++---------------------------- internal/handler/download.go | 4 +--- internal/handler/handler.go | 6 ----- internal/handler/head.go | 4 +--- internal/handler/reader.go | 4 +--- 5 files changed, 13 insertions(+), 51 deletions(-) diff --git a/internal/frostfs/frostfs.go b/internal/frostfs/frostfs.go index dde560b..fc41420 100644 --- a/internal/frostfs/frostfs.go +++ b/internal/frostfs/frostfs.go @@ -85,43 +85,16 @@ func (x *FrostFS) ReadObject(ctx context.Context, prm handler.PrmObjectRead) (*h prmGet.UseBearer(*prm.BearerToken) } - if prm.WithHeader { - if prm.WithPayload { - res, err := x.pool.GetObject(ctx, prmGet) - if err != nil { - return nil, handleObjectError("init full object reading via connection pool", err) - } + // The code below must be reworked. It was copied from frostfs-s3-gw + // to create similar mocks for unit and fuzzing tests. + // + // However, this code was changed due to specific of expected responses + // from HTTP gateway. HTTP Gateway requires two types of responses: + // * payload as io.Reader + HEAD request + // * only payload as io.Reader + // Therefore all unused params were deleted and code was simplified. - defer res.Payload.Close() - - payload, err := io.ReadAll(res.Payload) - if err != nil { - return nil, handleObjectError("read full object payload", err) - } - - res.Header.SetPayload(payload) - - return &handler.ObjectPart{ - Head: &res.Header, - }, nil - } - - var prmHead pool.PrmObjectHead - prmHead.SetAddress(prm.Address) - - if prm.BearerToken != nil { - prmHead.UseBearer(*prm.BearerToken) - } - - hdr, err := x.pool.HeadObject(ctx, prmHead) - if err != nil { - return nil, handleObjectError("read object header via connection pool", err) - } - - return &handler.ObjectPart{ - Head: &hdr, - }, nil - } else if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 { + if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 { res, err := x.pool.GetObject(ctx, prmGet) if err != nil { return nil, handleObjectError("init full payload range reading via connection pool", err) @@ -129,6 +102,7 @@ func (x *FrostFS) ReadObject(ctx context.Context, prm handler.PrmObjectRead) (*h return &handler.ObjectPart{ Payload: res.Payload, + Head: &res.Header, }, nil } diff --git a/internal/handler/download.go b/internal/handler/download.go index 07fe3e9..480254c 100644 --- a/internal/handler/download.go +++ b/internal/handler/download.go @@ -157,9 +157,7 @@ func (h *Handler) zipObject(ctx context.Context, zipWriter *zip.Writer, addr oid PrmAuth: PrmAuth{ BearerToken: btoken, }, - Address: addr, - WithHeader: true, - WithPayload: true, + Address: addr, } resGet, err := h.frostfs.ReadObject(ctx, prm) diff --git a/internal/handler/handler.go b/internal/handler/handler.go index c87551e..197649e 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -54,12 +54,6 @@ type PrmObjectRead struct { // Address to read the object header from. Address oid.Address - // Flag to read object header. - WithHeader bool - - // Flag to read object payload. False overlaps payload range. - WithPayload bool - // Offset-length range of the object payload to be read. PayloadRange [2]uint64 } diff --git a/internal/handler/head.go b/internal/handler/head.go index 2a17f64..96d1f49 100644 --- a/internal/handler/head.go +++ b/internal/handler/head.go @@ -33,8 +33,7 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid PrmAuth: PrmAuth{ BearerToken: btoken, }, - Address: objectAddress, - WithHeader: true, + Address: objectAddress, } obj, err := h.frostfs.ReadObject(ctx, prm) @@ -80,7 +79,6 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid BearerToken: btoken, }, Address: objectAddress, - WithPayload: true, PayloadRange: [2]uint64{0, sz}, } diff --git a/internal/handler/reader.go b/internal/handler/reader.go index b48ac6d..81694bc 100644 --- a/internal/handler/reader.go +++ b/internal/handler/reader.go @@ -59,9 +59,7 @@ func (h *Handler) receiveFile(ctx context.Context, req request, objectAddress oi PrmAuth: PrmAuth{ BearerToken: bearerToken(ctx), }, - Address: objectAddress, - WithHeader: true, - WithPayload: true, + Address: objectAddress, } rObj, err := h.frostfs.ReadObject(ctx, prm) -- 2.45.2 From a62c8f0f5aebf897c430fc2727d207da4c779af5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 25 Jun 2024 16:12:30 +0300 Subject: [PATCH 2/2] [#117] Update tests Signed-off-by: Alex Vanin --- cmd/http-gw/integration_test.go | 1 + internal/handler/frostfs_mock.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/http-gw/integration_test.go b/cmd/http-gw/integration_test.go index cae40a5..e888ed6 100644 --- a/cmd/http-gw/integration_test.go +++ b/cmd/http-gw/integration_test.go @@ -54,6 +54,7 @@ func TestIntegration(t *testing.T) { versions := []string{ "1.2.7", "1.3.0", + "1.5.0", } key, err := keys.NewPrivateKeyFromHex("1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb") require.NoError(t, err) diff --git a/internal/handler/frostfs_mock.go b/internal/handler/frostfs_mock.go index 85ae874..eb59fb6 100644 --- a/internal/handler/frostfs_mock.go +++ b/internal/handler/frostfs_mock.go @@ -93,6 +93,7 @@ func (t *TestFrostFS) ReadObject(_ context.Context, prm PrmObjectRead) (*ObjectP if prm.PayloadRange[0]+prm.PayloadRange[1] > 0 { off := prm.PayloadRange[0] payload = payload[off : off+prm.PayloadRange[1]] + obj = nil // GetRange does not return header values } return &ObjectPart{ -- 2.45.2