2019-07-12 18:59:19 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-02-19 14:42:10 +00:00
|
|
|
package console_test
|
2019-07-12 18:59:19 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2021-11-12 20:47:41 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2023-04-13 13:04:07 +01:00
|
|
|
"storj.io/storj/satellite/buckets"
|
2019-07-12 18:59:19 +01:00
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUsers(t *testing.T) {
|
2021-11-12 20:47:41 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{SatelliteCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
2023-04-13 13:04:07 +01:00
|
|
|
bucketService := sat.API.Buckets.Service
|
2021-11-12 20:47:41 +00:00
|
|
|
db := sat.DB
|
2019-07-12 18:59:19 +01:00
|
|
|
consoleDB := db.Console()
|
|
|
|
|
|
|
|
// create user
|
|
|
|
userPassHash := testrand.Bytes(8)
|
|
|
|
|
|
|
|
// create an user with no partnerID
|
2023-01-27 21:07:32 +00:00
|
|
|
_, err := consoleDB.Users().Insert(ctx, &console.User{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-12 18:59:19 +01:00
|
|
|
FullName: "John Doe",
|
|
|
|
Email: "john@mail.test",
|
|
|
|
PasswordHash: userPassHash,
|
|
|
|
Status: console.Active,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// create a project with partnerID
|
|
|
|
_, err = consoleDB.Projects().Insert(ctx, &console.Project{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-12 18:59:19 +01:00
|
|
|
Name: "John Doe",
|
|
|
|
Description: "some description",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// create a project with no partnerID
|
|
|
|
proj, err := consoleDB.Projects().Insert(ctx, &console.Project{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-12 18:59:19 +01:00
|
|
|
Name: "John Doe",
|
|
|
|
Description: "some description",
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// create a APIKey with no partnerID
|
|
|
|
_, err = consoleDB.APIKeys().Create(ctx, testrand.Bytes(8), console.APIKeyInfo{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-12 18:59:19 +01:00
|
|
|
ProjectID: proj.ID,
|
|
|
|
Name: "John Doe",
|
|
|
|
Secret: []byte("xyz"),
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// create a bucket with no partnerID
|
2023-04-13 13:04:07 +01:00
|
|
|
_, err = bucketService.CreateBucket(ctx, buckets.Bucket{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-12 18:59:19 +01:00
|
|
|
Name: "testbucket",
|
2020-04-02 15:18:08 +01:00
|
|
|
ProjectID: proj.ID,
|
2019-07-12 18:59:19 +01:00
|
|
|
Created: time.Now(),
|
|
|
|
PathCipher: storj.EncAESGCM,
|
|
|
|
DefaultSegmentsSize: int64(100),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2019-07-19 16:17:34 +01:00
|
|
|
|
|
|
|
// update a bucket with partnerID
|
2023-04-13 13:04:07 +01:00
|
|
|
bucket, err := bucketService.UpdateBucket(ctx, buckets.Bucket{
|
2020-04-02 15:18:08 +01:00
|
|
|
ID: testrand.UUID(),
|
2019-07-19 16:17:34 +01:00
|
|
|
Name: "testbucket",
|
2020-04-02 15:18:08 +01:00
|
|
|
ProjectID: proj.ID,
|
|
|
|
PartnerID: proj.ID,
|
2019-07-19 16:17:34 +01:00
|
|
|
Created: time.Now(),
|
|
|
|
PathCipher: storj.EncAESGCM,
|
|
|
|
DefaultSegmentsSize: int64(100),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2021-05-14 16:05:42 +01:00
|
|
|
require.Equal(t, proj.ID, bucket.PartnerID)
|
|
|
|
|
2023-04-13 13:04:07 +01:00
|
|
|
bucket, err = bucketService.GetBucket(ctx, []byte("testbucket"), proj.ID)
|
2019-07-19 16:17:34 +01:00
|
|
|
require.NoError(t, err)
|
2020-04-02 15:18:08 +01:00
|
|
|
require.Equal(t, proj.ID, bucket.PartnerID)
|
2019-07-12 18:59:19 +01:00
|
|
|
})
|
|
|
|
}
|