Fix integration tests
This commit is contained in:
@@ -86,7 +86,5 @@ func NewTestService(ctx context.Context, logger *zap.Logger, db *factory.DB, tbl
|
||||
},
|
||||
}
|
||||
|
||||
svc.Reload(ctx)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
+41
-60
@@ -12,18 +12,17 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/compose"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest"
|
||||
"github.com/cortezaproject/corteza-server/compose/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/corteza"
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/app"
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
"github.com/cortezaproject/corteza-server/pkg/store/plain"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
@@ -37,74 +36,56 @@ type (
|
||||
cUser *sysTypes.User
|
||||
roleID uint64
|
||||
}
|
||||
|
||||
TestApp struct {
|
||||
helpers.TestApp
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
inited bool
|
||||
app = &compose.App{}
|
||||
r chi.Router
|
||||
p = &permissions.TestService{}
|
||||
testApp app.Runnable
|
||||
r chi.Router
|
||||
)
|
||||
|
||||
func db() *factory.DB {
|
||||
return factory.Database.MustGet("compose", "default").With(context.Background())
|
||||
}
|
||||
|
||||
// random string, 10 chars long by default
|
||||
func rs(a ...int) string {
|
||||
var l = 10
|
||||
if len(a) > 0 {
|
||||
l = a[0]
|
||||
}
|
||||
|
||||
return string(rand.Bytes(l))
|
||||
}
|
||||
|
||||
func InitConfig() {
|
||||
var err error
|
||||
|
||||
if inited {
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
helpers.RecursiveDotEnvLoad()
|
||||
|
||||
ctx := context.Background()
|
||||
log, _ := zap.NewDevelopment()
|
||||
logger.SetDefault(log)
|
||||
|
||||
cli.HandleError(app.Connect(ctx))
|
||||
auth.SetupDefault(rs(32), 10)
|
||||
cli.HandleError(app.ProvisionMigrateDatabase(ctx))
|
||||
|
||||
p = permissions.NewTestService(ctx, log, db(), "compose_permission_rules")
|
||||
|
||||
logger.SetDefault(log)
|
||||
service.DefaultPermissions = p
|
||||
if service.DefaultStore, err = plain.NewWithAfero(afero.NewMemMapFs(), "test"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cli.HandleError(app.Initialize(ctx))
|
||||
inited = true
|
||||
}
|
||||
|
||||
func InitApp() {
|
||||
InitConfig()
|
||||
helpers.InitAuth()
|
||||
func db() *factory.DB {
|
||||
return factory.Database.MustGet(compose.SERVICE, "default").With(context.Background())
|
||||
}
|
||||
|
||||
if r != nil {
|
||||
return
|
||||
func (app *TestApp) Initialize(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions = permissions.NewTestService(ctx, app.Log, db(), "compose_permission_rules")
|
||||
service.DefaultStore, err = plain.NewWithAfero(afero.NewMemMapFs(), "test")
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Activate(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions.(*permissions.TestService).Reload(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
func InitTestApp() {
|
||||
if testApp == nil {
|
||||
testApp = helpers.NewIntegrationTestApp(
|
||||
compose.SERVICE,
|
||||
&corteza.App{},
|
||||
&TestApp{},
|
||||
&compose.App{},
|
||||
)
|
||||
}
|
||||
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
if r == nil {
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -120,7 +101,7 @@ func newHelper(t *testing.T) helper {
|
||||
|
||||
h.cUser.SetRoles([]uint64{h.roleID})
|
||||
|
||||
p.ClearGrants()
|
||||
service.DefaultPermissions.(*permissions.TestService).ClearGrants()
|
||||
h.mockPermissionsWithAccess()
|
||||
|
||||
return h
|
||||
@@ -133,7 +114,7 @@ func (h helper) secCtx() context.Context {
|
||||
|
||||
// apitest basics, initialize, set handler, add auth
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
@@ -143,7 +124,7 @@ func (h helper) apiInit() *apitest.APITest {
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*permissions.Rule) {
|
||||
h.a.NoError(p.Grant(
|
||||
h.a.NoError(service.DefaultPermissions.(*permissions.TestService).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
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/compose/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
func TestPermissionsDelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
p := service.DefaultPermissions
|
||||
|
||||
// Make sure our user can grant
|
||||
h.allow(types.ComposePermissionResource, "grant")
|
||||
@@ -19,7 +21,7 @@ func TestPermissionsDelete(t *testing.T) {
|
||||
// New role.
|
||||
permDelRole := h.roleID + 1
|
||||
|
||||
h.a.Len(p.FindRulesByRoleID(permDelRole), 0)
|
||||
h.a.Len(service.DefaultPermissions.FindRulesByRoleID(permDelRole), 0)
|
||||
|
||||
// Setup a few fake rules for new roke
|
||||
h.mockPermissions(
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/app"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
)
|
||||
|
||||
type (
|
||||
TestApp struct {
|
||||
Opt *app.Options
|
||||
Log *zap.Logger
|
||||
}
|
||||
)
|
||||
|
||||
var _ app.Runnable = &TestApp{}
|
||||
|
||||
func NewIntegrationTestApp(service string, parts ...app.Runnable) app.Runnable {
|
||||
opt := app.NewOptions(service)
|
||||
|
||||
// When running integration tests, we want to upgrade the db. Always.
|
||||
opt.Upgrade.Always = true
|
||||
|
||||
// Create a new JWT secret (to prevent any security weirdness)
|
||||
opt.JWT.Secret = string(rand.Bytes(32))
|
||||
opt.JWT.Expiry = time.Minute
|
||||
|
||||
logger.DefaultLevel.SetLevel(zap.DebugLevel)
|
||||
log := logger.MakeDebugLogger()
|
||||
|
||||
testApp := app.New(parts...)
|
||||
|
||||
cli.HandleError(testApp.Setup(log, opt))
|
||||
cli.HandleError(testApp.Activate(cli.Context()))
|
||||
return testApp
|
||||
}
|
||||
|
||||
func (app *TestApp) Setup(log *zap.Logger, opt *app.Options) (err error) {
|
||||
app.Log = log
|
||||
app.Opt = opt
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Initialize(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Upgrade(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Activate(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Provision(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
+3
-20
@@ -7,35 +7,18 @@ import (
|
||||
"github.com/steinfletcher/apitest"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
)
|
||||
|
||||
var (
|
||||
jwtHandler auth.TokenHandler
|
||||
)
|
||||
|
||||
func InitAuth() {
|
||||
if jwtHandler != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
jwtHandler, err = auth.JWT(string(rand.Bytes(32)), 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func BindAuthMiddleware(r chi.Router) {
|
||||
r.Use(
|
||||
jwtHandler.HttpVerifier(),
|
||||
jwtHandler.HttpAuthenticator(),
|
||||
auth.DefaultJwtHandler.HttpVerifier(),
|
||||
auth.DefaultJwtHandler.HttpAuthenticator(),
|
||||
)
|
||||
}
|
||||
|
||||
func ReqHeaderAuthBearer(user *types.User) apitest.Intercept {
|
||||
return func(req *http.Request) {
|
||||
req.Header.Set("Authorization", "Bearer "+jwtHandler.Encode(user))
|
||||
req.Header.Set("Authorization", "Bearer "+auth.DefaultJwtHandler.Encode(user))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/messaging/service"
|
||||
"github.com/cortezaproject/corteza-server/messaging/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
func TestChannelAlterState(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
p := service.DefaultPermissions.(*permissions.TestService)
|
||||
ch := h.repoMakePublicCh()
|
||||
|
||||
stateUrl := fmt.Sprintf("/channels/%d/state", ch.ID)
|
||||
|
||||
@@ -12,18 +12,17 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/corteza"
|
||||
"github.com/cortezaproject/corteza-server/messaging"
|
||||
"github.com/cortezaproject/corteza-server/messaging/rest"
|
||||
"github.com/cortezaproject/corteza-server/messaging/service"
|
||||
"github.com/cortezaproject/corteza-server/messaging/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/app"
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
"github.com/cortezaproject/corteza-server/pkg/store/plain"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
@@ -37,74 +36,56 @@ type (
|
||||
cUser *sysTypes.User
|
||||
roleID uint64
|
||||
}
|
||||
|
||||
TestApp struct {
|
||||
helpers.TestApp
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
inited bool
|
||||
app = &messaging.App{}
|
||||
r chi.Router
|
||||
p = &permissions.TestService{}
|
||||
testApp app.Runnable
|
||||
r chi.Router
|
||||
)
|
||||
|
||||
func db() *factory.DB {
|
||||
return factory.Database.MustGet("messaging", "default").With(context.Background())
|
||||
}
|
||||
|
||||
// random string, 10 chars long by default
|
||||
func rs(a ...int) string {
|
||||
var l = 10
|
||||
if len(a) > 0 {
|
||||
l = a[0]
|
||||
}
|
||||
|
||||
return string(rand.Bytes(l))
|
||||
}
|
||||
|
||||
func InitConfig() {
|
||||
var err error
|
||||
|
||||
if inited {
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
helpers.RecursiveDotEnvLoad()
|
||||
|
||||
ctx := context.Background()
|
||||
log, _ := zap.NewDevelopment()
|
||||
logger.SetDefault(log)
|
||||
|
||||
cli.HandleError(app.Connect(ctx))
|
||||
auth.SetupDefault(rs(32), 10)
|
||||
cli.HandleError(app.ProvisionMigrateDatabase(ctx))
|
||||
|
||||
p = permissions.NewTestService(ctx, log, db(), "messaging_permission_rules")
|
||||
|
||||
logger.SetDefault(log)
|
||||
service.DefaultPermissions = p
|
||||
if service.DefaultStore, err = plain.NewWithAfero(afero.NewMemMapFs(), "test"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cli.HandleError(app.Initialize(ctx))
|
||||
inited = true
|
||||
}
|
||||
|
||||
func InitApp() {
|
||||
InitConfig()
|
||||
helpers.InitAuth()
|
||||
func db() *factory.DB {
|
||||
return factory.Database.MustGet(messaging.SERVICE, "default").With(context.Background())
|
||||
}
|
||||
|
||||
if r != nil {
|
||||
return
|
||||
func (app *TestApp) Initialize(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions = permissions.NewTestService(ctx, app.Log, db(), "messaging_permission_rules")
|
||||
service.DefaultStore, err = plain.NewWithAfero(afero.NewMemMapFs(), "test")
|
||||
return
|
||||
}
|
||||
|
||||
func (app *TestApp) Activate(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions.(*permissions.TestService).Reload(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
func InitTestApp() {
|
||||
if testApp == nil {
|
||||
testApp = helpers.NewIntegrationTestApp(
|
||||
messaging.SERVICE,
|
||||
&corteza.App{},
|
||||
&TestApp{},
|
||||
&messaging.App{},
|
||||
)
|
||||
}
|
||||
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
if r == nil {
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -120,7 +101,7 @@ func newHelper(t *testing.T) helper {
|
||||
|
||||
h.cUser.SetRoles([]uint64{h.roleID})
|
||||
|
||||
p.ClearGrants()
|
||||
service.DefaultPermissions.(*permissions.TestService).ClearGrants()
|
||||
h.mockPermissionsWithAccess()
|
||||
|
||||
return h
|
||||
@@ -133,7 +114,7 @@ func (h helper) secCtx() context.Context {
|
||||
|
||||
// apitest basics, initialize, set handler, add auth
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
@@ -142,7 +123,7 @@ func (h helper) apiInit() *apitest.APITest {
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*permissions.Rule) {
|
||||
h.a.NoError(p.Grant(
|
||||
h.a.NoError(service.DefaultPermissions.(*permissions.TestService).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
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
@@ -13,12 +14,14 @@ func TestMessageSearch(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
ch := h.repoMakePublicCh()
|
||||
|
||||
h.repoMakeMessage("searchTestMessageA", ch, h.cUser)
|
||||
h.repoMakeMessage("searchTestMessageB", ch, h.cUser)
|
||||
pf := time.Now().String()
|
||||
|
||||
h.repoMakeMessage(pf+"searchTestMessageA", ch, h.cUser)
|
||||
h.repoMakeMessage(pf+"searchTestMessageB", ch, h.cUser)
|
||||
|
||||
h.apiInit().
|
||||
Get("/search/messages").
|
||||
Query("query", "searchTestMessageA").
|
||||
Query("query", pf+"searchTestMessageA").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/messaging/service"
|
||||
"github.com/cortezaproject/corteza-server/messaging/types"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
func TestPermissionsDelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
p := service.DefaultPermissions
|
||||
|
||||
// Make sure our user can grant
|
||||
h.allow(types.MessagingPermissionResource, "grant")
|
||||
|
||||
+39
-44
@@ -5,17 +5,16 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/steinfletcher/apitest"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/corteza"
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/app"
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
@@ -34,15 +33,21 @@ type (
|
||||
cUser *types.User
|
||||
roleID uint64
|
||||
}
|
||||
|
||||
TestApp struct {
|
||||
helpers.TestApp
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
inited bool
|
||||
app = &system.App{}
|
||||
r chi.Router
|
||||
p = &permissions.TestService{}
|
||||
testApp app.Runnable
|
||||
r chi.Router
|
||||
)
|
||||
|
||||
func init() {
|
||||
helpers.RecursiveDotEnvLoad()
|
||||
}
|
||||
|
||||
// random string, 10 chars long by default
|
||||
func rs(a ...int) string {
|
||||
var l = 10
|
||||
@@ -54,49 +59,39 @@ func rs(a ...int) string {
|
||||
}
|
||||
|
||||
func db() *factory.DB {
|
||||
return factory.Database.MustGet("system", "default").With(context.Background())
|
||||
return factory.Database.MustGet(system.SERVICE, "default").With(context.Background())
|
||||
}
|
||||
|
||||
func InitConfig() {
|
||||
if inited {
|
||||
return
|
||||
}
|
||||
|
||||
helpers.RecursiveDotEnvLoad()
|
||||
|
||||
ctx := context.Background()
|
||||
log, _ := zap.NewDevelopment()
|
||||
logger.SetDefault(log)
|
||||
|
||||
cli.HandleError(app.Connect(ctx))
|
||||
auth.SetupDefault(rs(32), 10)
|
||||
cli.HandleError(app.ProvisionMigrateDatabase(ctx))
|
||||
|
||||
p = permissions.NewTestService(ctx, log, db(), "sys_permission_rules")
|
||||
|
||||
logger.SetDefault(log)
|
||||
service.DefaultPermissions = p
|
||||
|
||||
cli.HandleError(app.Initialize(ctx))
|
||||
inited = true
|
||||
func (app *TestApp) Initialize(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions = permissions.NewTestService(ctx, app.Log, db(), "compose_permission_rules")
|
||||
return
|
||||
}
|
||||
|
||||
func InitApp() {
|
||||
InitConfig()
|
||||
helpers.InitAuth()
|
||||
func (app *TestApp) Activate(ctx context.Context) (err error) {
|
||||
service.DefaultPermissions.(*permissions.TestService).Reload(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
if r != nil {
|
||||
return
|
||||
func InitTestApp() {
|
||||
if testApp == nil {
|
||||
testApp = helpers.NewIntegrationTestApp(
|
||||
system.SERVICE,
|
||||
&corteza.App{},
|
||||
&TestApp{},
|
||||
&system.App{},
|
||||
)
|
||||
}
|
||||
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
if r == nil {
|
||||
r = chi.NewRouter()
|
||||
r.Use(api.BaseMiddleware(logger.Default())...)
|
||||
helpers.BindAuthMiddleware(r)
|
||||
rest.MountRoutes(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -112,7 +107,7 @@ func newHelper(t *testing.T) helper {
|
||||
|
||||
h.cUser.SetRoles([]uint64{h.roleID})
|
||||
|
||||
p.ClearGrants()
|
||||
service.DefaultPermissions.(*permissions.TestService).ClearGrants()
|
||||
h.mockPermissionsWithAccess()
|
||||
|
||||
return h
|
||||
@@ -125,7 +120,7 @@ func (h helper) secCtx() context.Context {
|
||||
|
||||
// apitest basics, initialize, set handler, add auth
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitApp()
|
||||
InitTestApp()
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
@@ -134,7 +129,7 @@ func (h helper) apiInit() *apitest.APITest {
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*permissions.Rule) {
|
||||
h.a.NoError(p.Grant(
|
||||
h.a.NoError(service.DefaultPermissions.(*permissions.TestService).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
|
||||
|
||||
@@ -6,12 +6,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/cortezaproject/corteza-server/tests/helpers"
|
||||
)
|
||||
|
||||
func TestPermissionsDelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
p := service.DefaultPermissions
|
||||
|
||||
// Make sure our user can grant
|
||||
h.allow(types.SystemPermissionResource, "grant")
|
||||
|
||||
Reference in New Issue
Block a user