2020-07-24 18:13:15 +01:00
|
|
|
// 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"
|
2023-01-02 16:10:47 +00:00
|
|
|
"storj.io/common/pb"
|
2020-07-24 18:13:15 +01:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2020-07-24 18:13:15 +01:00
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSigner_EncryptedMetadata(t *testing.T) {
|
2020-11-20 19:16:31 +00:00
|
|
|
ekeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
|
2020-07-24 18:13:15 +01:00
|
|
|
ID: orders.EncryptionKeyID{1},
|
|
|
|
Key: storj.Key{1},
|
2020-11-20 19:16:31 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2020-07-24 18:13:15 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-11-20 19:16:31 +00:00
|
|
|
config.Orders.EncryptionKeys = *ekeys
|
2020-07-24 18:13:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, 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)
|
2021-01-08 16:04:46 +00:00
|
|
|
bucketName := "123456789012345678901234567890123456789012345678901234567890123"
|
2020-07-24 18:13:15 +01:00
|
|
|
bucketLocation := metabase.BucketLocation{
|
|
|
|
ProjectID: uplink.Projects[0].ID,
|
2020-11-18 21:39:13 +00:00
|
|
|
BucketName: bucketName,
|
2020-07-24 18:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_, 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)
|
|
|
|
|
2023-01-02 16:10:47 +00:00
|
|
|
addressedLimit, err := signer.Sign(ctx, &pb.Node{
|
|
|
|
Id: storagenode.ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Address: storagenode.Addr(),
|
|
|
|
NoiseInfo: &pb.NoiseInfo{
|
|
|
|
PublicKey: []byte("testpublickey"),
|
|
|
|
},
|
|
|
|
},
|
2020-07-24 18:13:15 +01:00
|
|
|
}, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NotEmpty(t, addressedLimit.Limit.EncryptedMetadata)
|
|
|
|
require.NotEmpty(t, addressedLimit.Limit.EncryptedMetadataKeyId)
|
|
|
|
|
2020-11-20 19:16:31 +00:00
|
|
|
require.Equal(t, ekeys.Default.ID[:], addressedLimit.Limit.EncryptedMetadataKeyId)
|
2023-01-02 16:10:47 +00:00
|
|
|
require.Equal(t, addressedLimit.StorageNodeAddress.NoiseInfo.PublicKey, []byte("testpublickey"))
|
2020-07-24 18:13:15 +01:00
|
|
|
|
2020-11-20 19:16:31 +00:00
|
|
|
metadata, err := ekeys.Default.DecryptMetadata(addressedLimit.Limit.SerialNumber, addressedLimit.Limit.EncryptedMetadata)
|
2020-07-24 18:13:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-08 16:04:46 +00:00
|
|
|
bucketInfo, err := metabase.ParseCompactBucketPrefix(metadata.CompactProjectBucketPrefix)
|
2020-07-24 18:13:15 +01:00
|
|
|
require.NoError(t, err)
|
2020-11-18 21:39:13 +00:00
|
|
|
require.Equal(t, bucketInfo.BucketName, bucketName)
|
|
|
|
require.Equal(t, bucketInfo.ProjectID, uplink.Projects[0].ID)
|
2020-07-24 18:13:15 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSigner_EncryptedMetadata_UploadDownload(t *testing.T) {
|
2020-11-20 19:16:31 +00:00
|
|
|
ekeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
|
2020-07-24 18:13:15 +01:00
|
|
|
ID: orders.EncryptionKeyID{1},
|
|
|
|
Key: storj.Key{1},
|
2020-11-20 19:16:31 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2020-07-24 18:13:15 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-11-20 19:16:31 +00:00
|
|
|
config.Orders.EncryptionKeys = *ekeys
|
2020-07-24 18:13:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite, uplink := planet.Satellites[0], planet.Uplinks[0]
|
|
|
|
|
2021-01-08 16:04:46 +00:00
|
|
|
const bucket = "123456789012345678901234567890123456789012345678901234567890123"
|
|
|
|
|
2020-07-24 18:13:15 +01:00
|
|
|
testdata := testrand.Bytes(8 * memory.KiB)
|
2021-01-08 16:04:46 +00:00
|
|
|
err := uplink.Upload(ctx, satellite, bucket, "data", testdata)
|
2020-07-24 18:13:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-08 16:04:46 +00:00
|
|
|
downdata, err := uplink.Download(ctx, satellite, bucket, "data")
|
2020-07-24 18:13:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, testdata, downdata)
|
|
|
|
})
|
|
|
|
}
|