Fix report testing facility due to RBAC changes
This commit is contained in:
parent
9872d92c95
commit
04a79596d1
@ -8,8 +8,10 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/compose/service"
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/pkg/id"
|
||||
"github.com/cortezaproject/corteza-server/pkg/report"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
)
|
||||
|
||||
func TestReporterLoading(t *testing.T) {
|
||||
@ -252,7 +254,13 @@ func TestReporterLoading(t *testing.T) {
|
||||
func prepare(t *testing.T, report string) (context.Context, helper, store.Storer, *auxReport) {
|
||||
h := newHelper(t)
|
||||
s := service.DefaultStore
|
||||
ctx := auth.SetSuperUserContext(context.Background())
|
||||
|
||||
u := &sysTypes.User{
|
||||
ID: id.Next(),
|
||||
}
|
||||
u.SetRoles(auth.BypassRoles().IDs()...)
|
||||
|
||||
ctx := auth.SetIdentityToContext(context.Background(), u)
|
||||
|
||||
err := bmReporterPrepareDM(ctx, h, s, "integration")
|
||||
h.a.NoError(err)
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/id"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/objstore/plain"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rbac"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
"github.com/go-chi/chi"
|
||||
@ -24,7 +23,6 @@ import (
|
||||
"github.com/spf13/afero"
|
||||
"github.com/steinfletcher/apitest"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -54,7 +52,6 @@ func InitTestApp() {
|
||||
|
||||
testApp = helpers.NewIntegrationTestApp(ctx, func(app *app.CortezaApp) (err error) {
|
||||
service.DefaultStore = app.Store
|
||||
rbac.SetGlobal(rbac.NewTestService(zap.NewNop(), app.Store))
|
||||
service.DefaultObjectStore, err = plain.NewWithAfero(afero.NewMemMapFs(), "test")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -89,10 +86,8 @@ func newHelper(t *testing.T) helper {
|
||||
},
|
||||
}
|
||||
|
||||
h.cUser.SetRoles([]uint64{h.roleID})
|
||||
|
||||
rbac.Global().(*rbac.TestService).ClearGrants()
|
||||
h.mockPermissionsWithAccess()
|
||||
h.cUser.SetRoles(h.roleID)
|
||||
helpers.UpdateRBAC(h.roleID)
|
||||
|
||||
return h
|
||||
}
|
||||
@ -113,31 +108,6 @@ func (h helper) apiInit() *apitest.APITest {
|
||||
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*rbac.Rule) {
|
||||
h.noError(rbac.Global().Grant(
|
||||
// TestService we use does not have any backend storage,
|
||||
context.Background(),
|
||||
// We want to make sure we did not make a mistake with any of the mocked resources or actions
|
||||
service.DefaultAccessControl.Whitelist(),
|
||||
rules...,
|
||||
))
|
||||
}
|
||||
|
||||
// Prepends allow access rule for compose service for everyone
|
||||
func (h helper) mockPermissionsWithAccess(rules ...*rbac.Rule) {
|
||||
h.mockPermissions(rules...)
|
||||
}
|
||||
|
||||
// Set allow permision for test role
|
||||
func (h helper) allow(r rbac.Resource, o rbac.Operation) {
|
||||
h.mockPermissions(rbac.AllowRule(h.roleID, r, o))
|
||||
}
|
||||
|
||||
// set deny permission for test role
|
||||
func (h helper) deny(r rbac.Resource, o rbac.Operation) {
|
||||
h.mockPermissions(rbac.DenyRule(h.roleID, r, o))
|
||||
}
|
||||
|
||||
// Unwraps error before it passes it to the tester
|
||||
func (h helper) noError(err error) {
|
||||
for errors.Unwrap(err) != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user