Fixes apigw prefilter for string with hyphen
This commit is contained in:
parent
4092f1bfc7
commit
2d2e02b3a0
@ -100,13 +100,16 @@ func (h header) Handler() types.HandlerFunc {
|
||||
|
||||
// get the request data and put it into vars
|
||||
out, err := expr.NewVars(vv)
|
||||
|
||||
if err != nil {
|
||||
return pe.Internal("could not validate headers: %v", err)
|
||||
}
|
||||
|
||||
b, err := h.eval.Test(ctx, out)
|
||||
err = out.Set("headers", vv)
|
||||
if err != nil {
|
||||
return pe.Internal("could not set headers: %v", err)
|
||||
}
|
||||
|
||||
b, err := h.eval.Test(ctx, out)
|
||||
if err != nil {
|
||||
return pe.InvalidData("could not validate headers: %v", err)
|
||||
}
|
||||
@ -181,13 +184,16 @@ func (qp *queryParam) Handler() types.HandlerFunc {
|
||||
|
||||
// get the request data and put it into vars
|
||||
out, err := expr.NewVars(vv)
|
||||
|
||||
if err != nil {
|
||||
return pe.Internal("could not validate query parameters: %v", err)
|
||||
}
|
||||
|
||||
b, err := qp.eval.Test(ctx, out)
|
||||
err = out.Set("params", vv)
|
||||
if err != nil {
|
||||
return pe.Internal("could not set params: %v", err)
|
||||
}
|
||||
|
||||
b, err := qp.eval.Test(ctx, out)
|
||||
if err != nil {
|
||||
return pe.InvalidData("could not validate query parameters: %v", err)
|
||||
}
|
||||
|
||||
@ -67,11 +67,11 @@ func Test_headerHandle(t *testing.T) {
|
||||
expr: `{"expr":"match(Foo, \"^b\\\\wr\\\\s.*$\")"}`,
|
||||
headers: map[string][]string{"Foo": {"bar "}},
|
||||
},
|
||||
// {
|
||||
// name: "matching header with hyphen - TODO",
|
||||
// expr: `{"expr":"Content-type == \"application/json\""}`,
|
||||
// headers: map[string][]string{"Content-type": {"application/json"}},
|
||||
// },
|
||||
{
|
||||
name: "matching header with hyphen",
|
||||
expr: `{"expr":"headers[\"Content-type\"] == \"application/json\""}`,
|
||||
headers: map[string][]string{"Content-type": {"application/json"}},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@ -134,6 +134,11 @@ func Test_queryParamHandle(t *testing.T) {
|
||||
expr: `{"expr":"foo == \"bar-baz\""}`,
|
||||
url: "https://examp.le?foo=bar-baz",
|
||||
},
|
||||
{
|
||||
name: "matching query parameter",
|
||||
expr: `{"expr":"params[\"foo-bar\"] == \"bar-baz\""}`,
|
||||
url: "https://examp.le?foo-bar=bar-baz",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -17,4 +17,12 @@ func Test_prefilter_header_failing(t *testing.T) {
|
||||
Expect(t).
|
||||
Status(http.StatusBadRequest).
|
||||
End()
|
||||
|
||||
h.apiInit().
|
||||
Get("/test-hyphen").
|
||||
Header("Accept-Language", "fr-CH, fr;q=0.9").
|
||||
Header("Token", "brute-force-guess").
|
||||
Expect(t).
|
||||
Status(http.StatusBadRequest).
|
||||
End()
|
||||
}
|
||||
|
||||
@ -17,4 +17,12 @@ func Test_prefilter_header_passing(t *testing.T) {
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
End()
|
||||
|
||||
h.apiInit().
|
||||
Get("/test-hyphen").
|
||||
Header("Accept-Language", "fr-CH, fr;q=0.9").
|
||||
Header("Token", "super-secret-token").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
End()
|
||||
}
|
||||
|
||||
@ -17,4 +17,12 @@ func Test_prefilter_query_failing(t *testing.T) {
|
||||
Expect(t).
|
||||
Status(http.StatusBadRequest).
|
||||
End()
|
||||
|
||||
h.apiInit().
|
||||
Get("/test-hyphen").
|
||||
Query("foo-bar", "encrypted-string").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusBadRequest).
|
||||
End()
|
||||
}
|
||||
|
||||
@ -17,4 +17,12 @@ func Test_prefilter_query_passing(t *testing.T) {
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
End()
|
||||
|
||||
h.apiInit().
|
||||
Get("/test-hyphen").
|
||||
Query("foo-bar", "encrypted-string").
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
End()
|
||||
}
|
||||
|
||||
@ -7,3 +7,12 @@ apigateway:
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "Token == \"super-secret-token\""
|
||||
|
||||
- endpoint: /test-hyphen
|
||||
method: GET
|
||||
enabled: true
|
||||
filters:
|
||||
- ref: "header"
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "Accept-Language == \"fr-CH, fr;q=0.9\""
|
||||
|
||||
@ -7,3 +7,12 @@ apigateway:
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "Token == \"super-secret-token\""
|
||||
|
||||
- endpoint: /test-hyphen
|
||||
method: GET
|
||||
enabled: true
|
||||
filters:
|
||||
- ref: "header"
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "headers[\"Accept-Language\"] == \"fr-CH, fr;q=0.9\""
|
||||
|
||||
@ -7,3 +7,13 @@ apigateway:
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "token == \"super-secret-token\""
|
||||
|
||||
- endpoint: /test-hyphen
|
||||
method: GET
|
||||
enabled: true
|
||||
filters:
|
||||
- ref: "queryParam"
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "foo-bar == \"encrypted-string\""
|
||||
|
||||
|
||||
@ -7,3 +7,12 @@ apigateway:
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "token == \"super-secret-token\""
|
||||
|
||||
- endpoint: /test-hyphen
|
||||
method: GET
|
||||
enabled: true
|
||||
filters:
|
||||
- ref: "queryParam"
|
||||
kind: "prefilter"
|
||||
params:
|
||||
expr: "params[\"foo-bar\"] == \"encrypted-string\""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user