d961437889
Since the Satellite now requires the order encryption functionality (since serial_number table is deprecated) to properly function, we can remove the config flag to turn on/off the feature. Change-Id: Ie973f72a9a05a81cef9e53dc9c99d22c940c2488
109 lines
3.3 KiB
Go
109 lines
3.3 KiB
Go
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package orders_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/common/memory"
|
|
"storj.io/common/storj"
|
|
"storj.io/common/testcontext"
|
|
"storj.io/common/testrand"
|
|
"storj.io/storj/private/testplanet"
|
|
"storj.io/storj/satellite"
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
|
"storj.io/storj/satellite/orders"
|
|
)
|
|
|
|
func TestSigner_EncryptedMetadata(t *testing.T) {
|
|
ekeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
|
|
ID: orders.EncryptionKeyID{1},
|
|
Key: storj.Key{1},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1,
|
|
Reconfigure: testplanet.Reconfigure{
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
testplanet.ReconfigureRS(1, 1, 1, 1)(log, index, config)
|
|
|
|
config.Orders.EncryptionKeys = *ekeys
|
|
},
|
|
},
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
satellite, uplink, storagenode := planet.Satellites[0], planet.Uplinks[0], planet.StorageNodes[0]
|
|
|
|
project, err := uplink.GetProject(ctx, satellite)
|
|
require.NoError(t, err)
|
|
bucketName := "testbucket"
|
|
bucketLocation := metabase.BucketLocation{
|
|
ProjectID: uplink.Projects[0].ID,
|
|
BucketName: bucketName,
|
|
}
|
|
|
|
_, err = project.EnsureBucket(ctx, bucketLocation.BucketName)
|
|
require.NoError(t, err)
|
|
|
|
root := testrand.PieceID()
|
|
orderCreation := time.Now()
|
|
|
|
signer, err := orders.NewSignerGet(satellite.Orders.Service, root, orderCreation, 1e6, bucketLocation)
|
|
require.NoError(t, err)
|
|
|
|
addressedLimit, err := signer.Sign(ctx, storj.NodeURL{
|
|
ID: storagenode.ID(),
|
|
Address: storagenode.Addr(),
|
|
}, 1)
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, addressedLimit.Limit.EncryptedMetadata)
|
|
require.NotEmpty(t, addressedLimit.Limit.EncryptedMetadataKeyId)
|
|
|
|
require.Equal(t, ekeys.Default.ID[:], addressedLimit.Limit.EncryptedMetadataKeyId)
|
|
|
|
metadata, err := ekeys.Default.DecryptMetadata(addressedLimit.Limit.SerialNumber, addressedLimit.Limit.EncryptedMetadata)
|
|
require.NoError(t, err)
|
|
|
|
bucketInfo, err := metabase.ParseBucketPrefix(metabase.BucketPrefix(metadata.ProjectBucketPrefix))
|
|
require.NoError(t, err)
|
|
require.Equal(t, bucketInfo.BucketName, bucketName)
|
|
require.Equal(t, bucketInfo.ProjectID, uplink.Projects[0].ID)
|
|
})
|
|
}
|
|
|
|
func TestSigner_EncryptedMetadata_UploadDownload(t *testing.T) {
|
|
ekeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
|
|
ID: orders.EncryptionKeyID{1},
|
|
Key: storj.Key{1},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1,
|
|
Reconfigure: testplanet.Reconfigure{
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
testplanet.ReconfigureRS(1, 1, 1, 1)(log, index, config)
|
|
|
|
config.Orders.EncryptionKeys = *ekeys
|
|
},
|
|
},
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
satellite, uplink := planet.Satellites[0], planet.Uplinks[0]
|
|
|
|
testdata := testrand.Bytes(8 * memory.KiB)
|
|
err := uplink.Upload(ctx, satellite, "testbucket", "data", testdata)
|
|
require.NoError(t, err)
|
|
|
|
downdata, err := uplink.Download(ctx, satellite, "testbucket", "data")
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, testdata, downdata)
|
|
})
|
|
}
|