APIGw updates

- Fixes filter status update
- Updates search route API param for status
- Updates envoy marshaling for filter
- Fixes/Updated test for route and filter
This commit is contained in:
Vivek Patel
2021-10-05 11:57:36 +05:30
parent 03beda0e5d
commit a22083573c
28 changed files with 265 additions and 50 deletions
+2
View File
@@ -18,6 +18,7 @@ func Test_pl(t *testing.T) {
tf struct {
name string
method string
endpoint string
expError string
expStatus int
handler *types.MockHandler
@@ -91,6 +92,7 @@ func Test_pl(t *testing.T) {
route := &route{
method: tc.method,
endpoint: tc.endpoint,
log: zap.NewNop(),
opts: options.Apigw(),
handler: pipe.Handler(),
+5 -5
View File
@@ -248,8 +248,8 @@ func (s *apigw) ProxyAuthDef() (list []*proxy.ProxyAuthDefinition) {
func (s *apigw) loadRoutes(ctx context.Context) (rr []*route, err error) {
routes, _, err := s.storer.SearchApigwRoutes(ctx, st.ApigwRouteFilter{
Enabled: true,
Deleted: f.StateExcluded,
Deleted: f.StateExcluded,
Disabled: f.StateExcluded,
})
if err != nil {
@@ -275,9 +275,9 @@ func (s *apigw) loadRoutes(ctx context.Context) (rr []*route, err error) {
func (s *apigw) loadFilters(ctx context.Context, route uint64) (ff []*st.ApigwFilter, err error) {
ff, _, err = s.storer.SearchApigwFilters(ctx, st.ApigwFilterFilter{
RouteID: route,
Deleted: f.StateExcluded,
Enabled: true,
RouteID: route,
Deleted: f.StateExcluded,
Disabled: f.StateExcluded,
})
return
+1
View File
@@ -95,6 +95,7 @@ func (f *apiGwFilter) MarshalYAML() (interface{}, error) {
"weight", f.res.Weight,
"ref", f.res.Ref,
"kind", f.res.Kind,
"enabled", f.res.Enabled,
"params", f.res.Params,
)
if err != nil {
+3
View File
@@ -112,6 +112,9 @@ func (wrap *apiGwFilter) UnmarshalYAML(n *yaml.Node) (err error) {
case "kind":
return y7s.DecodeScalar(v, "route filter kind", &wrap.res.Kind)
case "enabled":
return y7s.DecodeScalar(v, "route filter enabled", &wrap.res.Enabled)
case "params":
return v.Decode(&wrap.res.Params)
}
+1
View File
@@ -12,6 +12,7 @@ fields:
- { field: Weight }
- { field: Kind }
- { field: Ref }
- { field: Enabled }
- { field: Params, type: "map[string]interface{}" }
- { field: CreatedBy }
- { field: UpdatedBy }
+3
View File
@@ -414,6 +414,7 @@ func (s Store) internalApigwFilterRowScanner(row rowScanner) (res *types.ApigwFi
&res.Weight,
&res.Kind,
&res.Ref,
&res.Enabled,
&res.Params,
&res.CreatedBy,
&res.UpdatedBy,
@@ -465,6 +466,7 @@ func (Store) apigwFilterColumns(aa ...string) []string {
alias + "weight",
alias + "kind",
alias + "ref",
alias + "enabled",
alias + "params",
alias + "created_by",
alias + "updated_by",
@@ -497,6 +499,7 @@ func (s Store) internalApigwFilterEncoder(res *types.ApigwFilter) store.Payload
"weight": res.Weight,
"kind": res.Kind,
"ref": res.Ref,
"enabled": res.Enabled,
"params": res.Params,
"created_by": res.CreatedBy,
"updated_by": res.UpdatedBy,
+1
View File
@@ -10,6 +10,7 @@ func (s Store) convertApigwFilterFilter(f types.ApigwFilterFilter) (query squirr
query = s.apigwFiltersSelectBuilder()
query = filter.StateCondition(query, "af.deleted_at", f.Deleted)
query = filter.StateConditionNegBool(query, "af.enabled", f.Disabled)
if f.RouteID > 0 {
query = query.Where(squirrel.Eq{"af.rel_route": f.RouteID})
+1 -4
View File
@@ -9,10 +9,7 @@ import (
func (s Store) convertApigwRouteFilter(f types.ApigwRouteFilter) (query squirrel.SelectBuilder, err error) {
query = s.apigwRoutesSelectBuilder()
query = filter.StateCondition(query, "ar.deleted_at", f.Deleted)
if f.Enabled {
query = query.Where(squirrel.Eq{"ar.enabled": f.Enabled})
}
query = filter.StateConditionNegBool(query, "ar.enabled", f.Disabled)
return
}
+1
View File
@@ -733,6 +733,7 @@ func (Schema) ApigwFilter() *Table {
ColumnDef("weight", ColumnTypeInteger),
ColumnDef("kind", ColumnTypeVarchar, ColumnTypeLength(handleLength)),
ColumnDef("ref", ColumnTypeVarchar, ColumnTypeLength(handleLength)),
ColumnDef("enabled", ColumnTypeBoolean),
ColumnDef("params", ColumnTypeJson),
CUDTimestamps,
CUDUsers,
+2
View File
@@ -1715,6 +1715,7 @@ endpoints:
- { name: weight, type: uint64, title: "Filter priority" }
- { name: kind, type: string, title: "Filter kind" }
- { name: ref, type: string, title: "Filter ref" }
- { name: enabled, type: bool, title: "Is Filter enabled" }
- { name: params, type: "types.ApigwFilterParams", title: "Filter parameters", parser: "types.ParseApigwfFilterParams" }
- name: update
method: POST
@@ -1727,6 +1728,7 @@ endpoints:
- { name: weight, type: uint64, title: "Filter priority" }
- { name: kind, type: string, title: "Filter kind" }
- { name: ref, type: string, title: "Filter ref" }
- { name: enabled, type: bool, title: "Is Filter enabled" }
- { name: params, type: "types.ApigwFilterParams", title: "Filter parameters", parser: "types.ParseApigwfFilterParams" }
- name: read
method: GET
+18 -15
View File
@@ -49,8 +49,9 @@ func (ctrl *ApigwFilter) List(ctx context.Context, r *request.ApigwFilterList) (
var (
err error
f = types.ApigwFilterFilter{
RouteID: r.RouteID,
Deleted: filter.State(r.Deleted),
RouteID: r.RouteID,
Deleted: filter.State(r.Deleted),
Disabled: filter.State(r.Disabled),
}
)
@@ -62,20 +63,21 @@ func (ctrl *ApigwFilter) List(ctx context.Context, r *request.ApigwFilterList) (
return nil, err
}
set, filter, err := ctrl.svc.Search(ctx, f)
set, f, err := ctrl.svc.Search(ctx, f)
return ctrl.makeFilterPayload(ctx, set, filter, err)
return ctrl.makeFilterPayload(ctx, set, f, err)
}
func (ctrl *ApigwFilter) Create(ctx context.Context, r *request.ApigwFilterCreate) (interface{}, error) {
var (
err error
q = &types.ApigwFilter{
Route: r.RouteID,
Weight: r.Weight,
Kind: r.Kind,
Ref: r.Ref,
Params: r.Params,
Route: r.RouteID,
Weight: r.Weight,
Kind: r.Kind,
Ref: r.Ref,
Enabled: r.Enabled,
Params: r.Params,
}
)
@@ -92,12 +94,13 @@ func (ctrl *ApigwFilter) Update(ctx context.Context, r *request.ApigwFilterUpdat
var (
err error
q = &types.ApigwFilter{
ID: r.FilterID,
Route: r.RouteID,
Weight: r.Weight,
Kind: r.Kind,
Ref: r.Ref,
Params: r.Params,
ID: r.FilterID,
Route: r.RouteID,
Weight: r.Weight,
Kind: r.Kind,
Ref: r.Ref,
Enabled: r.Enabled,
Params: r.Params,
}
)
+4 -3
View File
@@ -46,7 +46,8 @@ func (ctrl *ApigwRoute) List(ctx context.Context, r *request.ApigwRouteList) (in
var (
err error
f = types.ApigwRouteFilter{
Deleted: filter.State(r.Deleted),
Deleted: filter.State(r.Deleted),
Disabled: filter.State(r.Disabled),
}
)
@@ -58,9 +59,9 @@ func (ctrl *ApigwRoute) List(ctx context.Context, r *request.ApigwRouteList) (in
return nil, err
}
set, filter, err := ctrl.svc.Search(ctx, f)
set, f, err := ctrl.svc.Search(ctx, f)
return ctrl.makeFilterPayload(ctx, set, filter, err)
return ctrl.makeFilterPayload(ctx, set, f, err)
}
func (ctrl *ApigwRoute) Create(ctx context.Context, r *request.ApigwRouteCreate) (interface{}, error) {
+36
View File
@@ -87,6 +87,11 @@ type (
// Filter ref
Ref string
// Enabled POST parameter
//
// Is Filter enabled
Enabled bool
// Params POST parameter
//
// Filter parameters
@@ -119,6 +124,11 @@ type (
// Filter ref
Ref string
// Enabled POST parameter
//
// Is Filter enabled
Enabled bool
// Params POST parameter
//
// Filter parameters
@@ -264,6 +274,7 @@ func (r ApigwFilterCreate) Auditable() map[string]interface{} {
"weight": r.Weight,
"kind": r.Kind,
"ref": r.Ref,
"enabled": r.Enabled,
"params": r.Params,
}
}
@@ -288,6 +299,11 @@ func (r ApigwFilterCreate) GetRef() string {
return r.Ref
}
// Auditable returns all auditable/loggable parameters
func (r ApigwFilterCreate) GetEnabled() bool {
return r.Enabled
}
// Auditable returns all auditable/loggable parameters
func (r ApigwFilterCreate) GetParams() types.ApigwFilterParams {
return r.Params
@@ -342,6 +358,13 @@ func (r *ApigwFilterCreate) Fill(req *http.Request) (err error) {
}
}
if val, ok := req.Form["enabled"]; ok && len(val) > 0 {
r.Enabled, err = payload.ParseBool(val[0]), nil
if err != nil {
return err
}
}
if val, ok := req.Form["params[]"]; ok {
r.Params, err = types.ParseApigwfFilterParams(val)
if err != nil {
@@ -371,6 +394,7 @@ func (r ApigwFilterUpdate) Auditable() map[string]interface{} {
"weight": r.Weight,
"kind": r.Kind,
"ref": r.Ref,
"enabled": r.Enabled,
"params": r.Params,
}
}
@@ -400,6 +424,11 @@ func (r ApigwFilterUpdate) GetRef() string {
return r.Ref
}
// Auditable returns all auditable/loggable parameters
func (r ApigwFilterUpdate) GetEnabled() bool {
return r.Enabled
}
// Auditable returns all auditable/loggable parameters
func (r ApigwFilterUpdate) GetParams() types.ApigwFilterParams {
return r.Params
@@ -454,6 +483,13 @@ func (r *ApigwFilterUpdate) Fill(req *http.Request) (err error) {
}
}
if val, ok := req.Form["enabled"]; ok && len(val) > 0 {
r.Enabled, err = payload.ParseBool(val[0]), nil
if err != nil {
return err
}
}
if val, ok := req.Form["params[]"]; ok {
r.Params, err = types.ParseApigwfFilterParams(val)
if err != nil {
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"github.com/cortezaproject/corteza-server/pkg/apigw"
agtypes "github.com/cortezaproject/corteza-server/pkg/apigw/types"
a "github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/filter"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
)
@@ -107,8 +108,8 @@ func (svc *apigwFilter) Create(ctx context.Context, new *types.ApigwFilter) (q *
func (svc *apigwFilter) validateAsyncRoute(ctx context.Context, r *types.ApigwRoute, f *types.ApigwFilter, props *apigwFilterActionProps) (err error) {
filters, _, err := svc.Search(ctx, types.ApigwFilterFilter{
RouteID: r.ID,
Enabled: true,
RouteID: r.ID,
Disabled: filter.StateExcluded,
})
if err != nil {
+9 -8
View File
@@ -13,12 +13,13 @@ type (
ApigwFilterParams map[string]interface{}
ApigwFilter struct {
ID uint64 `json:"filterID,string"`
Route uint64 `json:"routeID,string"`
Weight uint64 `json:"weight,string"`
Ref string `json:"ref,omitempty"`
Kind string `json:"kind,omitempty"`
Params ApigwFilterParams `json:"params"`
ID uint64 `json:"filterID,string"`
Route uint64 `json:"routeID,string"`
Weight uint64 `json:"weight,string"`
Ref string `json:"ref,omitempty"`
Kind string `json:"kind,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Params ApigwFilterParams `json:"params"`
CreatedAt time.Time `json:"createdAt,omitempty"`
CreatedBy uint64 `json:"createdBy,string" `
@@ -30,9 +31,9 @@ type (
ApigwFilterFilter struct {
RouteID uint64 `json:"routeID,string"`
Enabled bool `json:"enabled"`
Deleted filter.State `json:"deleted"`
Deleted filter.State `json:"deleted"`
Disabled filter.State `json:"disabled"`
// Check fn is called by store backend for each resource found function can
// modify the resource and return false if store should not return it
+4 -4
View File
@@ -32,11 +32,11 @@ type (
}
ApigwRouteFilter struct {
Route string `json:"route"`
Group string `json:"group"`
Enabled bool `json:"enabled"`
Route string `json:"route"`
Group string `json:"group"`
Deleted filter.State `json:"deleted"`
Deleted filter.State `json:"deleted"`
Disabled filter.State `json:"disabled"`
// Check fn is called by store backend for each resource found function can
// modify the resource and return false if store should not return it
+1 -1
View File
@@ -142,7 +142,7 @@ func (h helper) apiInit() *apitest.APITest {
func setupScenario(t *testing.T) (context.Context, helper, store.Storer) {
ctx, h, s := setup(t)
loadScenario(ctx, s, t, h)
apigw.Service().Reload(ctx)
_ = apigw.Service().Reload(ctx)
return ctx, h, s
}
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "Token == \"super-secret-token\""
@@ -14,5 +15,6 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "Accept-Language == \"fr-CH, fr;q=0.9\""
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "P == \"a\""
@@ -14,5 +15,6 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "P == \"b\""
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "Token == \"super-secret-token\""
@@ -14,5 +15,6 @@ apigateway:
filters:
- ref: "header"
kind: "prefilter"
enabled: true
params:
expr: "headers[\"Accept-Language\"] == \"fr-CH, fr;q=0.9\""
+2
View File
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "token == \"super-secret-token\""
@@ -14,6 +15,7 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "foo-bar == \"encrypted-string\""
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "p == \"a\""
@@ -14,5 +15,6 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "p == \"b\""
+2
View File
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "token == \"super-secret-token\""
@@ -14,5 +15,6 @@ apigateway:
filters:
- ref: "queryParam"
kind: "prefilter"
enabled: true
params:
expr: "params[\"foo-bar\"] == \"encrypted-string\""
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "payload"
kind: "processer"
enabled: true
params:
jsfunc: |
const x = 10;
+1
View File
@@ -5,6 +5,7 @@ apigateway:
filters:
- ref: "payload"
kind: "processer"
enabled: true
params:
jsfunc: |
const x = 10;
+1 -1
View File
@@ -47,7 +47,7 @@ func TestStoreYaml_APIGateway(t *testing.T) {
_ = sTestAPIGatewayFilter(ctx, t, s, gwr.ID, "test")
df := su.NewDecodeFilter().
APIGWRoutes(&types.ApigwRouteFilter{Enabled: true})
APIGWRoutes(&types.ApigwRouteFilter{})
return nil, df
},
+6 -5
View File
@@ -230,11 +230,12 @@ func sTestAPIGatewayRoute(ctx context.Context, t *testing.T, s store.Storer, r s
func sTestAPIGatewayFilter(ctx context.Context, t *testing.T, s store.Storer, routeID uint64, pfx string) *types.ApigwFilter {
gwf := &types.ApigwFilter{
ID: su.NextID(),
Route: routeID,
Weight: 0,
Ref: pfx + "_ref",
Kind: pfx + "_kind",
ID: su.NextID(),
Route: routeID,
Weight: 0,
Ref: pfx + "_ref",
Kind: pfx + "_kind",
Enabled: true,
Params: map[string]interface{}{
"param1": "value1",
},
+149 -2
View File
@@ -17,8 +17,16 @@ import (
)
func (h helper) createRouteWithFilter(s string, fkind string) (*types.ApigwRoute, *types.ApigwFilter) {
r := h.createRoute(&types.ApigwRoute{Endpoint: "/" + s, Method: "GET"})
f := h.createFilters(&types.ApigwFilter{Kind: fkind}, r.ID)
return h.createRouteAndFilterWithEnabled(s, fkind, true, true)
}
func (h helper) createRouteWithFilterEnabled(s string, fkind string, enable bool) (*types.ApigwRoute, *types.ApigwFilter) {
return h.createRouteAndFilterWithEnabled(s, fkind, true, enable)
}
func (h helper) createRouteAndFilterWithEnabled(s string, fkind string, rEnable, fEnable bool) (*types.ApigwRoute, *types.ApigwFilter) {
r := h.createRoute(&types.ApigwRoute{Endpoint: "/" + s, Method: "GET", Enabled: rEnable})
f := h.createFilters(&types.ApigwFilter{Kind: fkind, Enabled: fEnable}, r.ID)
return r, f
}
@@ -96,6 +104,7 @@ func TestApigwRouteSearch(t *testing.T) {
h.createRouteWithFilter("test1", "")
h.createRouteWithFilter("test2", "")
h.createRouteAndFilterWithEnabled("test3", "", false, true)
helpers.AllowMe(h, types.ComponentRbacResource(), "apigw-routes.search")
helpers.AllowMe(h, types.ApigwRouteRbacResource(0), "read")
@@ -112,6 +121,31 @@ func TestApigwRouteSearch(t *testing.T) {
End()
}
func TestApigwRouteSearch_includeDisabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
h.createRouteWithFilter("test1", "")
h.createRouteWithFilter("test2", "")
h.createRouteAndFilterWithEnabled("test3", "", false, true)
h.createRouteAndFilterWithEnabled("test4", "", false, false)
helpers.AllowMe(h, types.ComponentRbacResource(), "apigw-routes.search")
helpers.AllowMe(h, types.ApigwRouteRbacResource(0), "read")
h.apiInit().
Get(fmt.Sprintf("/apigw/route/")).
Query("disabled", "1").
Header("Accept", "application/json").
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Len(`$.response.set`, 4)).
Assert(jsonpath.Equal(`$.response.set[0].endpoint`, "/test1")).
Assert(jsonpath.Equal(`$.response.set[1].endpoint`, "/test2")).
End()
}
func TestApigwRouteSearch_forbiden(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
@@ -168,6 +202,7 @@ func TestApigwRouteCreate(t *testing.T) {
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.routeID`)).
Assert(jsonpath.Equal(`$.response.endpoint`, "/test")).
Assert(jsonpath.Equal(`$.response.enabled`, false)).
End()
}
@@ -206,6 +241,7 @@ func TestApigwRouteUpdate(t *testing.T) {
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.routeID`)).
Assert(jsonpath.Equal(`$.response.endpoint`, "/test-edited")).
Assert(jsonpath.Equal(`$.response.enabled`, false)).
End()
}
@@ -348,6 +384,29 @@ func TestApigwFilterSearch(t *testing.T) {
End()
}
func TestApigwFilterSearch_includeDisabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
r, f := h.createRouteWithFilterEnabled("test1", "", false)
helpers.AllowMe(h, types.ComponentRbacResource(), "apigw-routes.search")
helpers.AllowMe(h, types.ApigwRouteRbacResource(0), "read")
h.apiInit().
Get(fmt.Sprintf("/apigw/filter/")).
Query("routeID", strconv.FormatUint(r.ID, 10)).
Query("disabled", "1").
Header("Accept", "application/json").
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Len(`$.response.set`, 1)).
Assert(jsonpath.Equal(`$.response.set[0].filterID`, strconv.FormatUint(f.ID, 10))).
Assert(jsonpath.Equal(`$.response.set[0].routeID`, strconv.FormatUint(r.ID, 10))).
End()
}
func TestApigwFilterSearch_forbiden(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
@@ -384,6 +443,50 @@ func TestApigwFilterCreate(t *testing.T) {
End()
}
func TestApigwFilterCreate_enabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
r, _ := h.createRouteWithFilter("test1", "")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "read")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "update")
h.apiInit().
Put(fmt.Sprintf("/apigw/filter")).
Header("Accept", "application/json").
FormData("routeID", strconv.FormatUint(r.ID, 10)).
FormData("enabled", strconv.FormatBool(true)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.filterID`)).
Assert(jsonpath.Equal(`$.response.routeID`, strconv.FormatUint(r.ID, 10))).
Assert(jsonpath.Equal(`$.response.enabled`, true)).
End()
}
func TestApigwFilterCreate_disabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
r, _ := h.createRouteWithFilter("test1", "")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "read")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "update")
h.apiInit().
Put(fmt.Sprintf("/apigw/filter")).
Header("Accept", "application/json").
FormData("routeID", strconv.FormatUint(r.ID, 10)).
FormData("enabled", strconv.FormatBool(false)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Present(`$.response.filterID`)).
Assert(jsonpath.Equal(`$.response.routeID`, strconv.FormatUint(r.ID, 10))).
Assert(jsonpath.NotPresent(`$.response.enabled`)).
End()
}
func TestApigwFilterCreate_forbiden(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
@@ -421,6 +524,50 @@ func TestApigwFilterUpdate(t *testing.T) {
End()
}
func TestApigwFilterUpdate_enabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
r, f := h.createRouteWithFilterEnabled("test1", "", false)
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "read")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "update")
h.apiInit().
Post(fmt.Sprintf("/apigw/filter/%d", f.ID)).
Header("Accept", "application/json").
FormData("routeID", strconv.FormatUint(r.ID, 10)).
FormData("enabled", strconv.FormatBool(true)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Equal(`$.response.filterID`, strconv.FormatUint(f.ID, 10))).
Assert(jsonpath.Equal(`$.response.routeID`, strconv.FormatUint(r.ID, 10))).
Assert(jsonpath.Equal(`$.response.enabled`, true)).
End()
}
func TestApigwFilterUpdate_disabled(t *testing.T) {
h := newHelper(t)
h.clearRoutes()
r, f := h.createRouteWithFilterEnabled("test1", "", true)
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "read")
helpers.AllowMe(h, types.ApigwRouteRbacResource(r.ID), "update")
h.apiInit().
Post(fmt.Sprintf("/apigw/filter/%d", f.ID)).
Header("Accept", "application/json").
FormData("routeID", strconv.FormatUint(r.ID, 10)).
FormData("enabled", strconv.FormatBool(false)).
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Equal(`$.response.filterID`, strconv.FormatUint(f.ID, 10))).
Assert(jsonpath.Equal(`$.response.routeID`, strconv.FormatUint(r.ID, 10))).
Assert(jsonpath.NotPresent(`$.response.enabled`)).
End()
}
func TestApigwFilterUpdate_forbiden(t *testing.T) {
h := newHelper(t)
h.clearRoutes()