2020-11-11 13:45:03 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-12-14 16:33:33 +00:00
|
|
|
package consolewasm_test
|
2020-11-11 13:45:03 +00:00
|
|
|
|
|
|
|
import (
|
2022-09-13 14:12:14 +01:00
|
|
|
"encoding/json"
|
2021-05-12 11:21:15 +01:00
|
|
|
"errors"
|
2022-09-13 14:12:14 +01:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2020-11-11 13:45:03 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2021-05-28 11:11:10 +01:00
|
|
|
"storj.io/storj/satellite/console/consolewasm"
|
2020-11-11 13:45:03 +00:00
|
|
|
"storj.io/uplink"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetPermissionWithBuckets(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-05-28 11:11:10 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
|
2020-11-11 13:45:03 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellitePeer := planet.Satellites[0]
|
|
|
|
satelliteNodeURL := satellitePeer.NodeURL().String()
|
|
|
|
uplinkPeer := planet.Uplinks[0]
|
|
|
|
APIKey := uplinkPeer.APIKey[satellitePeer.ID()]
|
|
|
|
apiKeyString := APIKey.Serialize()
|
2022-09-13 14:12:14 +01:00
|
|
|
projectID := uplinkPeer.Projects[0].ID
|
2020-11-11 13:45:03 +00:00
|
|
|
require.Equal(t, 1, len(uplinkPeer.Projects))
|
|
|
|
passphrase := "supersecretpassphrase"
|
|
|
|
|
|
|
|
// Create an access grant with the uplink API key. With that access grant, create 2 buckets and upload an object.
|
|
|
|
uplinkAccess, err := uplinkPeer.Config.RequestAccessWithPassphrase(ctx, satelliteNodeURL, apiKeyString, passphrase)
|
|
|
|
require.NoError(t, err)
|
|
|
|
uplinkPeer.Access[satellitePeer.ID()] = uplinkAccess
|
|
|
|
testbucket1 := "buckettest1"
|
|
|
|
testbucket2 := "buckettest2"
|
|
|
|
testfilename := "file.txt"
|
|
|
|
testdata := []byte("fun data")
|
|
|
|
require.NoError(t, uplinkPeer.CreateBucket(ctx, satellitePeer, testbucket1))
|
|
|
|
require.NoError(t, uplinkPeer.CreateBucket(ctx, satellitePeer, testbucket2))
|
|
|
|
require.NoError(t, uplinkPeer.Upload(ctx, satellitePeer, testbucket1, testfilename, testdata))
|
|
|
|
require.NoError(t, uplinkPeer.Upload(ctx, satellitePeer, testbucket2, testfilename, testdata))
|
|
|
|
data, err := uplinkPeer.Download(ctx, satellitePeer, testbucket1, testfilename)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, data, testdata)
|
|
|
|
|
|
|
|
buckets := []string{testbucket1}
|
|
|
|
|
|
|
|
// Restrict the uplink access grant with read only permissions and only allows actions for 1 bucket.
|
|
|
|
var sharePrefixes []uplink.SharePrefix
|
|
|
|
for _, path := range buckets {
|
|
|
|
sharePrefixes = append(sharePrefixes, uplink.SharePrefix{
|
|
|
|
Bucket: path,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
restrictedUplinkAccess, err := uplinkAccess.Share(uplink.ReadOnlyPermission(), sharePrefixes...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Expect that we can download the object with the restricted access for the 1 allowed bucket.
|
|
|
|
uplinkPeer.Access[satellitePeer.ID()] = restrictedUplinkAccess
|
|
|
|
uplinkPeer.APIKey[satellitePeer.ID()] = APIKey
|
|
|
|
data, err = uplinkPeer.Download(ctx, satellitePeer, testbucket1, testfilename)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, data, testdata)
|
|
|
|
err = uplinkPeer.Upload(ctx, satellitePeer, testbucket1, "file2", testdata)
|
2021-05-12 11:21:15 +01:00
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2020-11-11 13:45:03 +00:00
|
|
|
_, err = uplinkPeer.Download(ctx, satellitePeer, testbucket2, testfilename)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// Create restricted access with the console access grant code that allows full access to only 1 bucket.
|
2021-05-28 11:11:10 +01:00
|
|
|
readOnlyPermission := consolewasm.Permission{
|
2020-11-11 13:45:03 +00:00
|
|
|
AllowDownload: true,
|
|
|
|
AllowUpload: false,
|
|
|
|
AllowList: true,
|
|
|
|
AllowDelete: false,
|
|
|
|
NotBefore: time.Now().Add(-24 * time.Hour),
|
|
|
|
NotAfter: time.Now().Add(48 * time.Hour),
|
|
|
|
}
|
2021-05-28 11:11:10 +01:00
|
|
|
restrictedKey, err := consolewasm.SetPermission(apiKeyString, buckets, readOnlyPermission)
|
2020-11-11 13:45:03 +00:00
|
|
|
require.NoError(t, err)
|
2022-09-13 14:12:14 +01:00
|
|
|
|
|
|
|
client := newTestClient(t, ctx, planet)
|
|
|
|
user := client.defaultUser()
|
|
|
|
client.login(user.email, user.password)
|
|
|
|
|
|
|
|
resp, bodyString := client.request(http.MethodGet, fmt.Sprintf("/projects/%s/salt", projectID.String()), nil)
|
|
|
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
var b64Salt string
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(bodyString), &b64Salt))
|
|
|
|
|
|
|
|
restrictedAccessGrant, err := consolewasm.GenAccessGrant(satelliteNodeURL, restrictedKey.Serialize(), passphrase, b64Salt)
|
2020-11-11 13:45:03 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
restrictedAccess, err := uplink.ParseAccess(restrictedAccessGrant)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Expect that we can download the object with the restricted access for the 1 allowed bucket.
|
|
|
|
uplinkPeer.APIKey[satellitePeer.ID()] = restrictedKey
|
|
|
|
uplinkPeer.Access[satellitePeer.ID()] = restrictedAccess
|
|
|
|
data, err = uplinkPeer.Download(ctx, satellitePeer, testbucket1, testfilename)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, data, testdata)
|
|
|
|
err = uplinkPeer.Upload(ctx, satellitePeer, testbucket1, "file2", testdata)
|
2021-05-12 11:21:15 +01:00
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2020-11-11 13:45:03 +00:00
|
|
|
_, err = uplinkPeer.Download(ctx, satellitePeer, testbucket2, testfilename)
|
2021-02-03 15:36:56 +00:00
|
|
|
require.Error(t, err)
|
2020-11-11 13:45:03 +00:00
|
|
|
})
|
|
|
|
}
|
2021-01-05 22:24:46 +00:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
func TestSetPermission_Uplink(t *testing.T) {
|
2021-01-05 22:24:46 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-05-28 11:11:10 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
|
2021-01-05 22:24:46 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellitePeer := planet.Satellites[0]
|
|
|
|
satelliteNodeURL := satellitePeer.NodeURL().String()
|
|
|
|
uplinkPeer := planet.Uplinks[0]
|
|
|
|
APIKey := uplinkPeer.APIKey[satellitePeer.ID()]
|
|
|
|
apiKeyString := APIKey.Serialize()
|
|
|
|
require.Equal(t, 1, len(uplinkPeer.Projects))
|
|
|
|
passphrase := "supersecretpassphrase"
|
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
// Create an access grant with the uplink API key. With that access grant, create 2 bucket and upload files to them
|
|
|
|
uplinkAccess, err := uplinkPeer.Config.RequestAccessWithPassphrase(ctx, satelliteNodeURL, apiKeyString, passphrase)
|
|
|
|
require.NoError(t, err)
|
|
|
|
uplinkPeer.Access[satellitePeer.ID()] = uplinkAccess
|
2021-01-05 22:24:46 +00:00
|
|
|
testbucket1 := "buckettest1"
|
2021-05-28 11:11:10 +01:00
|
|
|
testbucket2 := "buckettest2"
|
|
|
|
testbucket3 := "buckettest3"
|
|
|
|
testfilename1 := "file1.txt"
|
|
|
|
testfilename2 := "file2.txt"
|
2021-01-05 22:24:46 +00:00
|
|
|
testdata := []byte("fun data")
|
|
|
|
require.NoError(t, uplinkPeer.CreateBucket(ctx, satellitePeer, testbucket1))
|
2021-05-28 11:11:10 +01:00
|
|
|
require.NoError(t, uplinkPeer.CreateBucket(ctx, satellitePeer, testbucket2))
|
|
|
|
require.NoError(t, uplinkPeer.Upload(ctx, satellitePeer, testbucket1, testfilename1, testdata))
|
|
|
|
require.NoError(t, uplinkPeer.Upload(ctx, satellitePeer, testbucket2, testfilename1, testdata))
|
|
|
|
require.NoError(t, uplinkPeer.Upload(ctx, satellitePeer, testbucket2, testfilename2, testdata))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
client := newTestClient(t, ctx, planet)
|
|
|
|
user := client.defaultUser()
|
|
|
|
client.login(user.email, user.password)
|
|
|
|
|
|
|
|
resp, bodyString := client.request(http.MethodGet, fmt.Sprintf("/projects/%s/salt", uplinkPeer.Projects[0].ID.String()), nil)
|
|
|
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
var b64Salt string
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(bodyString), &b64Salt))
|
|
|
|
|
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "only delete", []string{}, consolewasm.Permission{AllowDelete: true}, func(t *testing.T, project *uplink.Project) {
|
2021-05-28 11:11:10 +01:00
|
|
|
// All operation except delete should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
upload, err := project.UploadObject(ctx, testbucket2, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DownloadObject(ctx, testbucket2, testfilename1, nil)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
// We can see buckets names, but not the files inside
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 2, len(buckets))
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 0, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Current implementation needs also permission to Download/Read/List so having
|
|
|
|
// only Delete permission for DeleteBucketWithObjects won't work
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket2)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "only list", []string{testbucket1}, consolewasm.Permission{AllowList: true}, func(t *testing.T, project *uplink.Project) {
|
2021-05-28 11:11:10 +01:00
|
|
|
// All operation except list inside testbucket1 should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
upload, err := project.UploadObject(ctx, testbucket1, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DownloadObject(ctx, testbucket1, testfilename1, nil)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
// Only one bucket should be visible
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 1, len(buckets))
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 1, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
})
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "only upload", []string{testbucket1}, consolewasm.Permission{AllowUpload: true}, func(t *testing.T, project *uplink.Project) {
|
2021-05-28 11:11:10 +01:00
|
|
|
// All operation except upload to the testbucket1 should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
upload, err := project.UploadObject(ctx, testbucket1, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = project.DownloadObject(ctx, testbucket1, testfilename1, nil)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
// Only one bucket should be visible
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 1, len(buckets))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 0, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
})
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "only download", []string{testbucket1}, consolewasm.Permission{AllowDownload: true}, func(t *testing.T, project *uplink.Project) {
|
2021-05-28 11:11:10 +01:00
|
|
|
// All operation except download from testbucket1 should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
upload, err := project.UploadObject(ctx, testbucket1, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2023-06-26 13:13:31 +01:00
|
|
|
|
|
|
|
download, err := project.DownloadObject(ctx, testbucket1, testfilename1, nil)
|
2021-05-28 11:11:10 +01:00
|
|
|
require.NoError(t, err)
|
2023-06-26 13:13:31 +01:00
|
|
|
require.NoError(t, download.Close())
|
2021-05-28 11:11:10 +01:00
|
|
|
|
|
|
|
// Only one bucket should be visible
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 1, len(buckets))
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 0, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
})
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "not after", []string{}, consolewasm.Permission{
|
2021-05-12 11:21:15 +01:00
|
|
|
AllowDownload: true,
|
|
|
|
AllowUpload: true,
|
|
|
|
AllowList: true,
|
|
|
|
AllowDelete: true,
|
|
|
|
NotAfter: time.Now().Add(-2 * time.Hour),
|
2021-05-28 11:11:10 +01:00
|
|
|
}, func(t *testing.T, project *uplink.Project) {
|
|
|
|
// All operation should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
upload, err := project.UploadObject(ctx, testbucket1, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
_, err = project.DownloadObject(ctx, testbucket1, testfilename1, nil)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 0, len(buckets))
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 0, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
})
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "not before", []string{}, consolewasm.Permission{
|
2021-05-12 11:21:15 +01:00
|
|
|
AllowDownload: true,
|
|
|
|
AllowUpload: true,
|
|
|
|
AllowList: true,
|
|
|
|
AllowDelete: true,
|
|
|
|
NotBefore: time.Now().Add(2 * time.Hour),
|
2021-05-28 11:11:10 +01:00
|
|
|
}, func(t *testing.T, project *uplink.Project) {
|
|
|
|
// All operation should be restricted
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
upload, err := project.UploadObject(ctx, testbucket2, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DownloadObject(ctx, testbucket1, testfilename1, nil)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket2)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 0, len(buckets))
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket1)
|
|
|
|
require.Equal(t, 0, len(objects))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.True(t, errors.Is(err, uplink.ErrPermissionDenied))
|
|
|
|
})
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
withAccessKey(ctx, t, planet, passphrase, b64Salt, "all", []string{}, consolewasm.Permission{
|
2021-05-28 11:11:10 +01:00
|
|
|
AllowDownload: true,
|
|
|
|
AllowUpload: true,
|
|
|
|
AllowList: true,
|
|
|
|
AllowDelete: true,
|
|
|
|
NotBefore: time.Now().Add(-24 * time.Hour),
|
|
|
|
NotAfter: time.Now().Add(24 * time.Hour),
|
|
|
|
}, func(t *testing.T, project *uplink.Project) {
|
|
|
|
// All operation allowed
|
|
|
|
_, err = project.CreateBucket(ctx, testbucket3)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
upload, err := project.UploadObject(ctx, testbucket3, testfilename2, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = upload.Write(testdata)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = upload.Commit()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
objects := getAllObjects(ctx, project, testbucket3)
|
|
|
|
require.Equal(t, 1, len(objects))
|
|
|
|
|
2023-06-26 13:13:31 +01:00
|
|
|
download, err := project.DownloadObject(ctx, testbucket3, testfilename2, nil)
|
2021-05-28 11:11:10 +01:00
|
|
|
require.NoError(t, err)
|
2023-06-26 13:13:31 +01:00
|
|
|
require.NoError(t, download.Close())
|
2021-05-28 11:11:10 +01:00
|
|
|
|
|
|
|
_, err = project.DeleteBucketWithObjects(ctx, testbucket3)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
buckets := getAllBuckets(ctx, project)
|
|
|
|
require.Equal(t, 2, len(buckets))
|
|
|
|
|
|
|
|
_, err = project.DeleteObject(ctx, testbucket1, testfilename1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAllObjects(ctx *testcontext.Context, project *uplink.Project, bucket string) []*uplink.Object {
|
|
|
|
var objects = []*uplink.Object{}
|
|
|
|
iter := project.ListObjects(ctx, bucket, nil)
|
|
|
|
for iter.Next() {
|
|
|
|
objects = append(objects, iter.Item())
|
|
|
|
}
|
|
|
|
return objects
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAllBuckets(ctx *testcontext.Context, project *uplink.Project) []*uplink.Bucket {
|
|
|
|
var buckets = []*uplink.Bucket{}
|
|
|
|
iter := project.ListBuckets(ctx, nil)
|
|
|
|
for iter.Next() {
|
|
|
|
buckets = append(buckets, iter.Item())
|
|
|
|
}
|
|
|
|
return buckets
|
|
|
|
}
|
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
func withAccessKey(ctx *testcontext.Context, t *testing.T, planet *testplanet.Planet, passphrase, salt, testname string, bucket []string, permissions consolewasm.Permission, fn func(t *testing.T, uplink *uplink.Project)) {
|
2021-05-28 11:11:10 +01:00
|
|
|
t.Run(testname, func(t *testing.T) {
|
|
|
|
upl := planet.Uplinks[0]
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
|
|
|
|
apikey := upl.APIKey[sat.ID()]
|
|
|
|
restrictedKey, err := consolewasm.SetPermission(apikey.Serialize(), bucket, permissions)
|
2021-05-12 11:21:15 +01:00
|
|
|
require.NoError(t, err)
|
2021-05-28 11:11:10 +01:00
|
|
|
|
2022-09-13 14:12:14 +01:00
|
|
|
restrictedGrant, err := consolewasm.GenAccessGrant(sat.NodeURL().String(), restrictedKey.Serialize(), passphrase, salt)
|
2021-05-12 11:21:15 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
access, err := uplink.ParseAccess(restrictedGrant)
|
|
|
|
require.NoError(t, err)
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
project, err := uplink.OpenProject(ctx, access)
|
|
|
|
require.NoError(t, err)
|
2021-05-12 11:21:15 +01:00
|
|
|
|
2021-05-28 11:11:10 +01:00
|
|
|
defer func() { require.NoError(t, project.Close()) }()
|
|
|
|
fn(t, project)
|
2021-05-12 11:21:15 +01:00
|
|
|
})
|
|
|
|
}
|