Fix access token handling in integration test
This commit is contained in:
@@ -116,10 +116,15 @@ func (h helper) secCtx() context.Context {
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitTestApp()
|
||||
|
||||
tkn, err := auth.DefaultJwtHandler.Generate(context.Background(), h.cUser)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
Handler(r).
|
||||
Intercept(helpers.ReqHeaderAuthBearer(h.cUser))
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(tkn))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -117,11 +117,15 @@ func (h helper) secCtx() context.Context {
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitTestApp()
|
||||
|
||||
tkn, err := auth.DefaultJwtHandler.Generate(context.Background(), h.cUser)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
Handler(r).
|
||||
Intercept(helpers.ReqHeaderAuthBearer(h.cUser))
|
||||
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(tkn))
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*rbac.Rule) {
|
||||
|
||||
@@ -99,13 +99,17 @@ func (h helper) secCtx() context.Context {
|
||||
|
||||
// apitest basics, initialize, set handler, add auth
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
// InitTestApp()
|
||||
InitTestApp()
|
||||
|
||||
tkn, err := auth.DefaultJwtHandler.Generate(context.Background(), h.cUser)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
Handler(r).
|
||||
Intercept(helpers.ReqHeaderAuthBearer(h.cUser))
|
||||
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(tkn))
|
||||
}
|
||||
|
||||
// Unwraps error before it passes it to the tester
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/steinfletcher/apitest"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
)
|
||||
|
||||
func BindAuthMiddleware(r chi.Router) {
|
||||
@@ -17,16 +16,6 @@ func BindAuthMiddleware(r chi.Router) {
|
||||
)
|
||||
}
|
||||
|
||||
func ReqHeaderAuthBearer(user *types.User) apitest.Intercept {
|
||||
return func(req *http.Request) {
|
||||
if user == nil {
|
||||
req.Header.Del("Authorization")
|
||||
} else {
|
||||
req.Header.Set("Authorization", "Bearer "+auth.DefaultJwtHandler.Encode(user))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ReqHeaderRawAuthBearer(token string) apitest.Intercept {
|
||||
return func(req *http.Request) {
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -139,13 +139,16 @@ func (h helper) secCtx() context.Context {
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitTestApp()
|
||||
|
||||
tkn, err := auth.DefaultJwtHandler.Generate(context.Background(), h.cUser)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
Handler(r).
|
||||
Intercept(helpers.ReqHeaderAuthBearer(h.cUser))
|
||||
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(tkn))
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*rbac.Rule) {
|
||||
h.noError(rbac.Global().Grant(
|
||||
// TestService we use does not have any backend storage,
|
||||
|
||||
@@ -150,11 +150,15 @@ func (h helper) secCtx() context.Context {
|
||||
func (h helper) apiInit() *apitest.APITest {
|
||||
InitTestApp()
|
||||
|
||||
tkn, err := auth.DefaultJwtHandler.Generate(context.Background(), h.cUser)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return apitest.
|
||||
New().
|
||||
Handler(r).
|
||||
Intercept(helpers.ReqHeaderAuthBearer(h.cUser))
|
||||
|
||||
Intercept(helpers.ReqHeaderRawAuthBearer(tkn))
|
||||
}
|
||||
|
||||
func (h helper) mockPermissions(rules ...*rbac.Rule) {
|
||||
|
||||
Reference in New Issue
Block a user