2019-06-27 18:36:51 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package uplink_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-01 12:14:09 +01:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-06-27 18:36:51 +01:00
|
|
|
|
|
|
|
"storj.io/storj/lib/uplink"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2019-06-27 18:36:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBucketExamples(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 1,
|
|
|
|
UplinkCount: 1},
|
|
|
|
func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
cfg := uplink.Config{}
|
2019-08-01 12:14:09 +01:00
|
|
|
cfg.Volatile.Log = zaptest.NewLogger(t)
|
2019-06-27 18:36:51 +01:00
|
|
|
cfg.Volatile.TLS.SkipPeerCAWhitelist = true
|
|
|
|
|
|
|
|
satelliteAddr := planet.Satellites[0].Local().Address.Address
|
2019-09-19 17:19:29 +01:00
|
|
|
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()].Serialize()
|
2019-06-27 18:36:51 +01:00
|
|
|
|
|
|
|
out := bytes.NewBuffer(nil)
|
|
|
|
err := ListBucketsExample(ctx, satelliteAddr, apiKey, &cfg, out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
|
|
|
err = CreateBucketExample(ctx, satelliteAddr, apiKey, &cfg, out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "success!\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
|
|
|
err = ListBucketsExample(ctx, satelliteAddr, apiKey, &cfg, out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "Bucket: testbucket\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
|
|
|
err = DeleteBucketExample(ctx, satelliteAddr, apiKey, &cfg, out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "success!\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
|
|
|
err = ListBucketsExample(ctx, satelliteAddr, apiKey, &cfg, out)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
2019-06-28 06:18:24 +01:00
|
|
|
access, err := CreateEncryptionKeyExampleByAdmin1(ctx, satelliteAddr, apiKey, &cfg, out)
|
2019-06-27 18:36:51 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "success!\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
2019-06-28 06:18:24 +01:00
|
|
|
err = CreateEncryptionKeyExampleByAdmin2(ctx, satelliteAddr, apiKey, access, &cfg, out)
|
2019-06-27 18:36:51 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "hello world\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
2019-07-02 16:45:23 +01:00
|
|
|
userScope, err := RestrictAccessExampleByAdmin(ctx, satelliteAddr, apiKey, access, &cfg, out)
|
2019-06-27 18:36:51 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "success!\n")
|
|
|
|
|
|
|
|
out = bytes.NewBuffer(nil)
|
2019-07-02 16:45:23 +01:00
|
|
|
err = RestrictAccessExampleByUser(ctx, userScope, &cfg, out)
|
2019-06-27 18:36:51 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, out.String(), "hello world\n")
|
|
|
|
})
|
|
|
|
}
|