2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-13 08:27:42 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
package satellitedb_test
|
2018-11-13 08:27:42 +00:00
|
|
|
|
|
|
|
import (
|
2022-09-13 13:45:18 +01:00
|
|
|
"crypto/sha256"
|
2018-11-13 08:27:42 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-11-29 18:39:27 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2018-11-13 08:27:42 +00:00
|
|
|
)
|
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
func TestProjectsGetByPublicID(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
projects := db.Console().Projects()
|
2020-01-08 11:42:11 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
prj, err := projects.Insert(ctx, &console.Project{
|
|
|
|
Name: "ProjectName",
|
|
|
|
Description: "projects description",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, prj)
|
2018-11-13 08:27:42 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
pubID := prj.PublicID
|
|
|
|
require.NotNil(t, pubID)
|
|
|
|
require.False(t, pubID.IsZero())
|
2018-11-13 08:27:42 +00:00
|
|
|
|
2022-06-27 22:20:59 +01:00
|
|
|
prj, err = projects.GetByPublicID(ctx, pubID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, pubID, prj.PublicID)
|
2018-11-13 08:27:42 +00:00
|
|
|
})
|
|
|
|
}
|
2022-09-13 13:45:18 +01:00
|
|
|
|
|
|
|
func TestProjectsGetSalt(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
projects := db.Console().Projects()
|
|
|
|
|
|
|
|
prj, err := projects.Insert(ctx, &console.Project{
|
|
|
|
Name: "ProjectName",
|
|
|
|
Description: "projects description",
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, prj)
|
|
|
|
|
|
|
|
salt, err := projects.GetSalt(ctx, prj.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
hash := sha256.Sum256(prj.ID[:])
|
|
|
|
require.Equal(t, hash[:], salt)
|
|
|
|
})
|
|
|
|
}
|