mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
76372a240c
* 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>
64 lines
1.4 KiB
Go
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
|
|
}
|