From 04a79596d1faea2cdc0bb2a12b589a40e9eb8d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Thu, 29 Jul 2021 11:57:13 +0200 Subject: [PATCH] Fix report testing facility due to RBAC changes --- tests/reporter/loading_test.go | 10 +++++++++- tests/reporter/main_test.go | 34 ++-------------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/tests/reporter/loading_test.go b/tests/reporter/loading_test.go index 5ece694c1..fc64b49e6 100644 --- a/tests/reporter/loading_test.go +++ b/tests/reporter/loading_test.go @@ -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) diff --git a/tests/reporter/main_test.go b/tests/reporter/main_test.go index 0c4cbcf6c..1ad925ac3 100644 --- a/tests/reporter/main_test.go +++ b/tests/reporter/main_test.go @@ -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 {