Fix panics after mock introduction #120

Merged
alexvanin merged 2 commits from alexvanin/frostfs-http-gw:fix/117 into master 2024-06-25 15:12:23 +00:00
7 changed files with 15 additions and 51 deletions

View file

@ -54,6 +54,7 @@ func TestIntegration(t *testing.T) {
versions := []string{ versions := []string{
"1.2.7", "1.2.7",
"1.3.0", "1.3.0",
"1.5.0",
} }
key, err := keys.NewPrivateKeyFromHex("1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb") key, err := keys.NewPrivateKeyFromHex("1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb")
require.NoError(t, err) require.NoError(t, err)

View file

@ -85,43 +85,16 @@ func (x *FrostFS) ReadObject(ctx context.Context, prm handler.PrmObjectRead) (*h
prmGet.UseBearer(*prm.BearerToken) prmGet.UseBearer(*prm.BearerToken)
} }
if prm.WithHeader { // The code below must be reworked. It was copied from frostfs-s3-gw
if prm.WithPayload { // to create similar mocks for unit and fuzzing tests.
res, err := x.pool.GetObject(ctx, prmGet) //
if err != nil { // However, this code was changed due to specific of expected responses
return nil, handleObjectError("init full object reading via connection pool", err) // 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() if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 {
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 {
res, err := x.pool.GetObject(ctx, prmGet) res, err := x.pool.GetObject(ctx, prmGet)
if err != nil { if err != nil {
return nil, handleObjectError("init full payload range reading via connection pool", err) 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{ return &handler.ObjectPart{
Payload: res.Payload, Payload: res.Payload,
Head: &res.Header,
}, nil }, nil
} }

View file

@ -158,8 +158,6 @@ func (h *Handler) zipObject(ctx context.Context, zipWriter *zip.Writer, addr oid
BearerToken: btoken, BearerToken: btoken,
}, },
Address: addr, Address: addr,
WithHeader: true,
WithPayload: true,
} }
resGet, err := h.frostfs.ReadObject(ctx, prm) resGet, err := h.frostfs.ReadObject(ctx, prm)

View file

@ -93,6 +93,7 @@ func (t *TestFrostFS) ReadObject(_ context.Context, prm PrmObjectRead) (*ObjectP
if prm.PayloadRange[0]+prm.PayloadRange[1] > 0 { if prm.PayloadRange[0]+prm.PayloadRange[1] > 0 {
off := prm.PayloadRange[0] off := prm.PayloadRange[0]
payload = payload[off : off+prm.PayloadRange[1]] payload = payload[off : off+prm.PayloadRange[1]]
obj = nil // GetRange does not return header values
} }
return &ObjectPart{ return &ObjectPart{

View file

@ -54,12 +54,6 @@ type PrmObjectRead struct {
// Address to read the object header from. // Address to read the object header from.
Address oid.Address 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. // Offset-length range of the object payload to be read.
PayloadRange [2]uint64 PayloadRange [2]uint64
} }

View file

@ -34,7 +34,6 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
BearerToken: btoken, BearerToken: btoken,
}, },
Address: objectAddress, Address: objectAddress,
WithHeader: true,
} }
obj, err := h.frostfs.ReadObject(ctx, prm) obj, err := h.frostfs.ReadObject(ctx, prm)
@ -80,7 +79,6 @@ func (h *Handler) headObject(ctx context.Context, req request, objectAddress oid
BearerToken: btoken, BearerToken: btoken,
}, },
Address: objectAddress, Address: objectAddress,
WithPayload: true,
PayloadRange: [2]uint64{0, sz}, PayloadRange: [2]uint64{0, sz},
} }

View file

@ -60,8 +60,6 @@ func (h *Handler) receiveFile(ctx context.Context, req request, objectAddress oi
BearerToken: bearerToken(ctx), BearerToken: bearerToken(ctx),
}, },
Address: objectAddress, Address: objectAddress,
WithHeader: true,
WithPayload: true,
} }
rObj, err := h.frostfs.ReadObject(ctx, prm) rObj, err := h.frostfs.ReadObject(ctx, prm)