satellite/metainfo: return default ciphers (path and encryption) for old
uplinks New libuplink is not storing encryption values in with bucket but old uplinks are using those values for configuration. If bucket was created with new libuplink we will send back satellite defaults. Change-Id: Ie1bf3682847e07b302270b4c4bf1a7219f4bf011
This commit is contained in:
parent
a7f927df96
commit
9f390f37da
@ -4,16 +4,21 @@
|
||||
package uplink_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/storj/lib/uplink"
|
||||
"storj.io/storj/private/testplanet"
|
||||
newuplink "storj.io/uplink"
|
||||
)
|
||||
|
||||
func TestProjectListBuckets(t *testing.T) {
|
||||
@ -89,3 +94,61 @@ func TestProjectListBuckets(t *testing.T) {
|
||||
require.False(t, result.More)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProjectOpenNewBucket(t *testing.T) {
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
satellite := planet.Satellites[0]
|
||||
apiKey := planet.Uplinks[0].APIKey[satellite.ID()]
|
||||
uplinkConfig := newuplink.Config{}
|
||||
access, err := uplinkConfig.RequestAccessWithPassphrase(ctx, satellite.URL().String(), apiKey.Serialize(), "mypassphrase")
|
||||
require.NoError(t, err)
|
||||
|
||||
project, err := uplinkConfig.OpenProject(ctx, access)
|
||||
require.NoError(t, err)
|
||||
|
||||
// create bucket and upload a file with new libuplink
|
||||
bucketName := "a-bucket"
|
||||
bucket, err := project.CreateBucket(ctx, bucketName)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, bucket)
|
||||
|
||||
upload, err := project.UploadObject(ctx, bucketName, "test-file.dat", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedData := testrand.Bytes(1 * memory.KiB)
|
||||
_, err = io.Copy(upload, bytes.NewBuffer(expectedData))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = upload.Commit()
|
||||
require.NoError(t, err)
|
||||
|
||||
serializedAccess, err := access.Serialize()
|
||||
require.NoError(t, err)
|
||||
|
||||
// download uploaded file with old libuplink
|
||||
oldUplink, err := planet.Uplinks[0].NewLibuplink(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
scope, err := uplink.ParseScope(serializedAccess)
|
||||
require.NoError(t, err)
|
||||
|
||||
oldProject, err := oldUplink.OpenProject(ctx, scope.SatelliteAddr, scope.APIKey)
|
||||
require.NoError(t, err)
|
||||
defer ctx.Check(oldProject.Close)
|
||||
|
||||
oldBucket, err := oldProject.OpenBucket(ctx, bucketName, scope.EncryptionAccess)
|
||||
require.NoError(t, err)
|
||||
defer ctx.Check(oldBucket.Close)
|
||||
|
||||
rc, err := oldBucket.Download(ctx, "test-file.dat")
|
||||
require.NoError(t, err)
|
||||
|
||||
var downloaded bytes.Buffer
|
||||
_, err = io.Copy(&downloaded, rc)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, expectedData, downloaded.Bytes())
|
||||
})
|
||||
}
|
||||
|
@ -1046,18 +1046,31 @@ func convertBucketToProto(ctx context.Context, bucket storj.Bucket, rs *pb.Redun
|
||||
if err != nil {
|
||||
return pbBucket, rpcstatus.Error(rpcstatus.Internal, "UUID marshal error")
|
||||
}
|
||||
return &pb.Bucket{
|
||||
|
||||
pbBucket = &pb.Bucket{
|
||||
Name: []byte(bucket.Name),
|
||||
PathCipher: pb.CipherSuite(int(bucket.PathCipher)),
|
||||
PathCipher: pb.CipherSuite(bucket.PathCipher),
|
||||
PartnerId: partnerID,
|
||||
CreatedAt: bucket.Created,
|
||||
DefaultSegmentSize: bucket.DefaultSegmentsSize,
|
||||
DefaultRedundancyScheme: rs,
|
||||
DefaultEncryptionParameters: &pb.EncryptionParameters{
|
||||
CipherSuite: pb.CipherSuite(int(bucket.DefaultEncryptionParameters.CipherSuite)),
|
||||
CipherSuite: pb.CipherSuite(bucket.DefaultEncryptionParameters.CipherSuite),
|
||||
BlockSize: int64(bucket.DefaultEncryptionParameters.BlockSize),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// this part is to provide default ciphers (path and encryption) for old uplinks
|
||||
// new uplinks are using ciphers from encryption access
|
||||
if pbBucket.PathCipher == pb.CipherSuite_ENC_UNSPECIFIED {
|
||||
pbBucket.PathCipher = pb.CipherSuite_ENC_AESGCM
|
||||
}
|
||||
if pbBucket.DefaultEncryptionParameters.CipherSuite == pb.CipherSuite_ENC_UNSPECIFIED {
|
||||
pbBucket.DefaultEncryptionParameters.CipherSuite = pb.CipherSuite_ENC_AESGCM
|
||||
pbBucket.DefaultEncryptionParameters.BlockSize = int64(rs.ErasureShareSize * rs.MinReq)
|
||||
}
|
||||
|
||||
return pbBucket, nil
|
||||
}
|
||||
|
||||
// BeginObject begins object
|
||||
|
Loading…
Reference in New Issue
Block a user