storj/satellite/satellitedb/projects_test.go
Cameron f8917c49aa satellite/satellitedb: generate random salt for new projects
Change-Id: I52970e1f32c6d4e9840d741c9ce4fbe61ac52b29
2022-12-02 01:24:14 +00:00

57 lines
1.4 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package satellitedb_test
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/common/uuid"
"storj.io/storj/satellite"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestProjectsGetByPublicID(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)
pubID := prj.PublicID
require.NotNil(t, pubID)
require.False(t, pubID.IsZero())
prj, err = projects.GetByPublicID(ctx, pubID)
require.NoError(t, err)
require.Equal(t, pubID, prj.PublicID)
})
}
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)
_, err = uuid.FromBytes(salt)
require.NoError(t, err)
})
}