diff --git a/private/testplanet/reconfigure.go b/private/testplanet/reconfigure.go index e6dff3a62..3c6e506f6 100644 --- a/private/testplanet/reconfigure.go +++ b/private/testplanet/reconfigure.go @@ -23,6 +23,7 @@ type Reconfigure struct { SatelliteDB func(log *zap.Logger, index int, db satellite.DB) (satellite.DB, error) SatelliteMetabaseDB func(log *zap.Logger, index int, db *metabase.DB) (*metabase.DB, error) Satellite func(log *zap.Logger, index int, config *satellite.Config) + Uplink func(log *zap.Logger, index int, config *UplinkConfig) StorageNodeDB func(index int, db storagenode.DB, log *zap.Logger) (storagenode.DB, error) StorageNode func(index int, config *storagenode.Config) diff --git a/private/testplanet/run.go b/private/testplanet/run.go index 0a4457c6c..312e5b523 100644 --- a/private/testplanet/run.go +++ b/private/testplanet/run.go @@ -12,8 +12,6 @@ import ( "go.uber.org/zap" "storj.io/common/context2" - "storj.io/common/grant" - "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/private/dbutil" "storj.io/private/dbutil/pgtest" @@ -21,7 +19,6 @@ import ( "storj.io/private/tagsql" "storj.io/storj/private/testmonkit" "storj.io/storj/satellite/satellitedb/satellitedbtest" - "storj.io/uplink" ) // Run runs testplanet in multiple configurations. @@ -70,7 +67,6 @@ func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.C defer ctx.Check(planet.Shutdown) planet.Start(ctx) - provisionUplinks(ctx, t, planet) var rawDB tagsql.DB var queriesBefore []string @@ -144,40 +140,9 @@ func Bench(b *testing.B, config Config, bench func(b *testing.B, ctx *testcontex defer ctx.Check(planet.Shutdown) planet.Start(ctx) - provisionUplinks(ctx, b, planet) bench(b, ctx, planet) }) }) } } - -func provisionUplinks(ctx context.Context, t testing.TB, planet *Planet) { - for _, planetUplink := range planet.Uplinks { - for _, satellite := range planet.Satellites { - apiKey := planetUplink.APIKey[satellite.ID()] - - // create access grant manually to avoid dialing satellite for - // project id and deriving key with argon2.IDKey method - encAccess := grant.NewEncryptionAccessWithDefaultKey(&storj.Key{}) - encAccess.SetDefaultPathCipher(storj.EncAESGCM) - - grantAccess := grant.Access{ - SatelliteAddress: satellite.URL(), - APIKey: apiKey, - EncAccess: encAccess, - } - - serializedAccess, err := grantAccess.Serialize() - if err != nil { - t.Fatalf("%+v", err) - } - access, err := uplink.ParseAccess(serializedAccess) - if err != nil { - t.Fatalf("%+v", err) - } - - planetUplink.Access[satellite.ID()] = access - } - } -} diff --git a/private/testplanet/uplink.go b/private/testplanet/uplink.go index f9e0f0bf7..e0c508814 100644 --- a/private/testplanet/uplink.go +++ b/private/testplanet/uplink.go @@ -15,6 +15,7 @@ import ( "github.com/zeebo/errs" "go.uber.org/zap" + "storj.io/common/grant" "storj.io/common/identity" "storj.io/common/macaroon" "storj.io/common/peertls/tlsopts" @@ -28,6 +29,11 @@ import ( "storj.io/uplink/private/testuplink" ) +// UplinkConfig testplanet configuration for uplink. +type UplinkConfig struct { + DefaultPathCipher storj.CipherSuite +} + // Uplink is a registered user on all satellites, // which contains the necessary accesses and project info. type Uplink struct { @@ -82,10 +88,13 @@ func (planet *Planet) newUplinks(ctx context.Context, prefix string, count int) var xs []*Uplink for i := 0; i < count; i++ { name := prefix + strconv.Itoa(i) + + log := planet.log.Named(name) + var uplink *Uplink var err error pprof.Do(ctx, pprof.Labels("peer", name), func(ctx context.Context) { - uplink, err = planet.newUplink(ctx, name) + uplink, err = planet.newUplink(ctx, i, log, name) }) if err != nil { return nil, errs.Wrap(err) @@ -97,7 +106,7 @@ func (planet *Planet) newUplinks(ctx context.Context, prefix string, count int) } // newUplink creates a new uplink. -func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, err error) { +func (planet *Planet) newUplink(ctx context.Context, index int, log *zap.Logger, name string) (_ *Uplink, err error) { defer mon.Task()(&ctx)(&err) identity, err := planet.NewIdentity() @@ -171,6 +180,38 @@ func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, er RawAPIKey: apiKey, }) + + var config UplinkConfig + if planet.config.Reconfigure.Uplink != nil { + planet.config.Reconfigure.Uplink(log, index, &config) + } + + // create access grant manually to avoid dialing satellite for + // project id and deriving key with argon2.IDKey method + encAccess := grant.NewEncryptionAccessWithDefaultKey(&storj.Key{}) + if config.DefaultPathCipher == storj.EncUnspecified { + encAccess.SetDefaultPathCipher(storj.EncAESGCM) + } else { + encAccess.SetDefaultPathCipher(config.DefaultPathCipher) + } + + grantAccess := grant.Access{ + SatelliteAddress: satellite.URL(), + APIKey: apiKey, + EncAccess: encAccess, + } + + serializedAccess, err := grantAccess.Serialize() + if err != nil { + return nil, errs.Wrap(err) + } + + access, err := uplink.ParseAccess(serializedAccess) + if err != nil { + return nil, errs.Wrap(err) + } + + planetUplink.Access[satellite.ID()] = access } planet.Uplinks = append(planet.Uplinks, planetUplink) diff --git a/private/testplanet/uplink_test.go b/private/testplanet/uplink_test.go index a83b8d8d2..dcb051c0b 100644 --- a/private/testplanet/uplink_test.go +++ b/private/testplanet/uplink_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zeebo/errs" + "go.uber.org/zap" "golang.org/x/sync/errgroup" "storj.io/common/memory" @@ -271,3 +272,23 @@ func TestUplinkOpenProject(t *testing.T) { require.NoError(t, err) }) } + +func TestUplinkDifferentPathCipher(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, UplinkCount: 1, + Reconfigure: testplanet.Reconfigure{ + Uplink: func(log *zap.Logger, index int, config *testplanet.UplinkConfig) { + config.DefaultPathCipher = storj.EncNull + }, + }, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "object-name", []byte("data")) + require.NoError(t, err) + + objects, err := planet.Satellites[0].Metabase.DB.TestingAllObjects(ctx) + require.NoError(t, err) + require.Len(t, objects, 1) + + require.EqualValues(t, "object-name", objects[0].ObjectKey) + }) +}