grafana/pkg/services/store/system_users_test.go
Tania 76372a240c
Storage: Add system users service (#57767)
* Storage: Add access for reporting

* reporting upload user per org

* add some basic comments

* Move reporting storage to enterprise

* add comments

Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>
2022-11-24 15:15:32 +01:00

64 lines
1.4 KiB
Go

package store
import (
"testing"
"github.com/grafana/grafana/pkg/infra/filestorage"
"github.com/grafana/grafana/pkg/services/user"
"github.com/stretchr/testify/require"
)
const admin SystemUserType = "storageAdmin"
func TestRetrievalOfNotInitializedOrg(t *testing.T) {
service := setupSystemUsers()
orgID := int64(1)
user, err := service.GetUser(admin, orgID)
require.NoError(t, err)
require.Equal(t, string(admin), user.Login)
require.Equal(t, orgID, user.OrgID)
userFromSubsequentCall, err := service.GetUser(admin, orgID)
require.NoError(t, err)
require.Same(t, user, userFromSubsequentCall)
}
func TestRetrievalOfFilterForInitializedUser(t *testing.T) {
service := setupSystemUsers()
orgID := int64(1)
reportsAdminUser, err := service.GetUser(admin, orgID)
require.NoError(t, err)
filter, err := service.GetFilter(reportsAdminUser)
require.NoError(t, err)
require.NotNil(t, filter)
}
func TestRetrievalOfFilterForNotInitializedUser(t *testing.T) {
service := setupSystemUsers()
orgID := int64(1)
filter, err := service.GetFilter(&user.SignedInUser{
OrgID: orgID,
Login: string(admin),
})
require.Error(t, err)
require.Nil(t, filter)
}
func setupSystemUsers() SystemUsers {
service := ProvideSystemUsersService()
service.RegisterUser(admin, func() map[string]filestorage.PathFilter {
return map[string]filestorage.PathFilter{
ActionFilesRead: denyAllPathFilter,
}
})
return service
}