satellite/metainfo: ListUploads returns incorrect UploadID
ListUploads returns incorrect UploadID if Expires was set in BeginUpload. DB is truncating expiration date to microseconds precision so we need to do this also in code. Change-Id: Iee0cf45cb705342f6bb9a2f745acca91cce6ff52
This commit is contained in:
parent
65e3cfb9c6
commit
b1d4a159a6
@ -182,6 +182,16 @@ func (endpoint *Endpoint) RevokeAPIKey(ctx context.Context, req *pb.RevokeAPIKey
|
||||
func (endpoint *Endpoint) packStreamID(ctx context.Context, satStreamID *internalpb.StreamID) (streamID storj.StreamID, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if satStreamID == nil {
|
||||
return nil, rpcstatus.Error(rpcstatus.Internal, "unable to create stream id")
|
||||
}
|
||||
|
||||
if !satStreamID.ExpirationDate.IsZero() {
|
||||
// DB can only preserve microseconds precision and nano seconds will be cut.
|
||||
// To have stable StreamID/UploadID we need to always truncate it.
|
||||
satStreamID.ExpirationDate = satStreamID.ExpirationDate.Truncate(time.Microsecond)
|
||||
}
|
||||
|
||||
signedStreamID, err := SignStreamID(ctx, endpoint.satellite, satStreamID)
|
||||
if err != nil {
|
||||
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
|
||||
@ -202,6 +212,10 @@ func (endpoint *Endpoint) packStreamID(ctx context.Context, satStreamID *interna
|
||||
func (endpoint *Endpoint) packSegmentID(ctx context.Context, satSegmentID *internalpb.SegmentID) (segmentID storj.SegmentID, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if satSegmentID == nil {
|
||||
return nil, rpcstatus.Error(rpcstatus.Internal, "unable to create segment id")
|
||||
}
|
||||
|
||||
signedSegmentID, err := SignSegmentID(ctx, endpoint.satellite, satSegmentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -612,17 +612,46 @@ func TestEndpoint_Object_No_StorageNodes(t *testing.T) {
|
||||
_, err = project.CreateBucket(ctx, bucketName)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, options := range []uplink.ListUploadsOptions{
|
||||
{System: false, Custom: false},
|
||||
{System: true, Custom: false},
|
||||
{System: true, Custom: true},
|
||||
{System: false, Custom: true},
|
||||
for _, tt := range []struct {
|
||||
expires time.Time
|
||||
options uplink.ListUploadsOptions
|
||||
}{
|
||||
{
|
||||
options: uplink.ListUploadsOptions{System: false, Custom: false},
|
||||
},
|
||||
{
|
||||
options: uplink.ListUploadsOptions{System: true, Custom: false},
|
||||
},
|
||||
{
|
||||
options: uplink.ListUploadsOptions{System: true, Custom: true},
|
||||
},
|
||||
{
|
||||
options: uplink.ListUploadsOptions{System: false, Custom: true},
|
||||
},
|
||||
{
|
||||
expires: time.Now().Add(24 * time.Hour),
|
||||
options: uplink.ListUploadsOptions{System: false, Custom: false},
|
||||
},
|
||||
{
|
||||
expires: time.Now().Add(24 * time.Hour),
|
||||
options: uplink.ListUploadsOptions{System: true, Custom: false},
|
||||
},
|
||||
{
|
||||
expires: time.Now().Add(24 * time.Hour),
|
||||
options: uplink.ListUploadsOptions{System: true, Custom: true},
|
||||
},
|
||||
{
|
||||
expires: time.Now().Add(24 * time.Hour),
|
||||
options: uplink.ListUploadsOptions{System: false, Custom: true},
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("system:%v;custom:%v", options.System, options.Custom), func(t *testing.T) {
|
||||
uploadInfo, err := project.BeginUpload(ctx, bucketName, "multipart-object", nil)
|
||||
t.Run(fmt.Sprintf("expires:%v;system:%v;custom:%v", !tt.expires.IsZero(), tt.options.System, tt.options.Custom), func(t *testing.T) {
|
||||
uploadInfo, err := project.BeginUpload(ctx, bucketName, "multipart-object", &uplink.UploadOptions{
|
||||
Expires: tt.expires,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
iterator := project.ListUploads(ctx, bucketName, &options)
|
||||
iterator := project.ListUploads(ctx, bucketName, &tt.options)
|
||||
require.True(t, iterator.Next())
|
||||
require.Equal(t, uploadInfo.UploadID, iterator.Item().UploadID)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user