mirror of
https://github.com/alibaba/higress.git
synced 2026-04-22 12:37:26 +08:00
feat: e2e test support http body check (#733)
This commit is contained in:
@@ -86,6 +86,76 @@ var WasmPluginsRequestBlock = suite.ConformanceTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// post blocked body
|
||||
Meta: http.AssertionMeta{
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "POST",
|
||||
ContentType: http.ContentTypeTextPlain,
|
||||
Body: []byte(`hello world`),
|
||||
UnfollowRedirect: true,
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 403,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// check body echoed back in expected request(same as ActualRequest if not set)
|
||||
Meta: http.AssertionMeta{
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
CompareTarget: http.CompareTargetRequest,
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "POST",
|
||||
ContentType: http.ContentTypeTextPlain,
|
||||
Body: []byte(`hello higress`),
|
||||
UnfollowRedirect: true,
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// check body echoed back in expected response
|
||||
Meta: http.AssertionMeta{
|
||||
TargetBackend: "infra-backend-echo-body-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
CompareTarget: http.CompareTargetResponse,
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo2.com",
|
||||
Path: "/foo",
|
||||
Method: "POST",
|
||||
ContentType: http.ContentTypeTextPlain,
|
||||
Body: []byte(`hello higress`),
|
||||
UnfollowRedirect: true,
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
ContentType: http.ContentTypeTextPlain,
|
||||
Body: []byte(`hello higress`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
t.Run("WasmPlugins request-block", func(t *testing.T) {
|
||||
for _, testcase := range testcases {
|
||||
|
||||
@@ -33,6 +33,27 @@ spec:
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/app-root: "/foo"
|
||||
name: httproute-app-root2
|
||||
namespace: higress-conformance-infra
|
||||
spec:
|
||||
ingressClassName: higress
|
||||
rules:
|
||||
- host: "foo2.com"
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: infra-backend-echo-body-v1
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: extensions.higress.io/v1alpha1
|
||||
kind: WasmPlugin
|
||||
metadata:
|
||||
@@ -46,4 +67,6 @@ spec:
|
||||
- "/env.*"
|
||||
block_exact_urls:
|
||||
- "/web/info"
|
||||
block_bodies:
|
||||
- "hello world"
|
||||
url: file:///opt/plugins/wasm-go/extensions/request-block/plugin.wasm
|
||||
|
||||
@@ -35,7 +35,7 @@ var WasmPluginsTransformer = suite.ConformanceTest{
|
||||
testcases := []http.Assertion{
|
||||
{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case 1: request transformer",
|
||||
TestCaseName: "case 1: request header&query transformer",
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
@@ -77,7 +77,7 @@ var WasmPluginsTransformer = suite.ConformanceTest{
|
||||
},
|
||||
{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case 2: response transformer",
|
||||
TestCaseName: "case 2: response header&query transformer",
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
@@ -111,6 +111,85 @@ var WasmPluginsTransformer = suite.ConformanceTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case 4: request body transformer",
|
||||
TargetBackend: "infra-backend-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo4.com",
|
||||
Path: "/post",
|
||||
// TODO(Uncle-Justice) dedupe, replace的body插件逻辑有问题,暂跳过测试
|
||||
Method: "POST",
|
||||
Body: []byte(`
|
||||
{
|
||||
"X-removed":["v1", "v2"],
|
||||
"X-not-renamed":["v1"]
|
||||
}
|
||||
`),
|
||||
ContentType: http.ContentTypeApplicationJson,
|
||||
},
|
||||
ExpectedRequest: &http.ExpectedRequest{
|
||||
Request: http.Request{
|
||||
Host: "foo4.com",
|
||||
Path: "/post",
|
||||
// TODO(Uncle-Justice) dedupe, replace的body插件逻辑有问题,暂跳过测试
|
||||
Method: "POST",
|
||||
ContentType: http.ContentTypeApplicationJson,
|
||||
Body: []byte(`
|
||||
{
|
||||
"X-renamed":["v1"],
|
||||
"X-add-append":["add","append"],
|
||||
"X-map":["add","append"]
|
||||
}
|
||||
`),
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case 5: response json body transformer",
|
||||
TargetBackend: "infra-backend-echo-body-v1",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
CompareTarget: http.CompareTargetResponse,
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo5.com",
|
||||
Path: "/post",
|
||||
// TODO(Uncle-Justice) dedupe, replace的body插件逻辑有问题,暂跳过测试
|
||||
Method: "POST",
|
||||
Body: []byte(`
|
||||
{
|
||||
"X-removed":["v1", "v2"],
|
||||
"X-not-renamed":["v1"]
|
||||
}
|
||||
`),
|
||||
ContentType: http.ContentTypeApplicationJson,
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
ContentType: http.ContentTypeApplicationJson,
|
||||
Body: []byte(`
|
||||
{
|
||||
"X-renamed":["v1"],
|
||||
"X-add-append":["add","append"],
|
||||
"X-map":["add","append"]
|
||||
}
|
||||
`),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
t.Run("WasmPlugin transformer", func(t *testing.T) {
|
||||
for _, testcase := range testcases {
|
||||
|
||||
@@ -36,7 +36,7 @@ apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
name: wasmplugin-transform-response
|
||||
name: wasmplugin-transform-response-header-and-query
|
||||
namespace: higress-conformance-infra
|
||||
spec:
|
||||
ingressClassName: higress
|
||||
@@ -52,6 +52,46 @@ spec:
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
name: wasmplugin-transform-request-body
|
||||
namespace: higress-conformance-infra
|
||||
spec:
|
||||
ingressClassName: higress
|
||||
rules:
|
||||
- host: "foo4.com"
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: infra-backend-v1
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
name: wasmplugin-transform-response-body
|
||||
namespace: higress-conformance-infra
|
||||
spec:
|
||||
ingressClassName: higress
|
||||
rules:
|
||||
- host: "foo5.com"
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: infra-backend-echo-body-v1
|
||||
port:
|
||||
number: 8080
|
||||
---
|
||||
apiVersion: extensions.higress.io/v1alpha1
|
||||
kind: WasmPlugin
|
||||
metadata:
|
||||
@@ -118,9 +158,8 @@ spec:
|
||||
- key: k4
|
||||
value: RETAIN_FIRST
|
||||
|
||||
# response transformer
|
||||
- ingress:
|
||||
- higress-conformance-infra/wasmplugin-transform-response
|
||||
- higress-conformance-infra/wasmplugin-transform-response-header-and-query
|
||||
configDisable: false
|
||||
config:
|
||||
type: response
|
||||
@@ -151,5 +190,78 @@ spec:
|
||||
headers:
|
||||
- key: X-add-append
|
||||
value: X-map
|
||||
|
||||
- ingress:
|
||||
- higress-conformance-infra/wasmplugin-transform-request-body
|
||||
configDisable: false
|
||||
config:
|
||||
type: request
|
||||
rules:
|
||||
- operate: remove
|
||||
body:
|
||||
- key: X-removed
|
||||
- operate: rename
|
||||
body:
|
||||
- key: X-not-renamed
|
||||
value: X-renamed
|
||||
- operate: replace
|
||||
body:
|
||||
- key: X-replace
|
||||
value: replaced
|
||||
- operate: add
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: add
|
||||
- operate: append
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: append
|
||||
- operate: map
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: X-map
|
||||
- operate: dedupe
|
||||
body:
|
||||
- key: X-dedupe-first
|
||||
value: RETAIN_FIRST
|
||||
- key: X-dedupe-last
|
||||
value: RETAIN_LAST
|
||||
- key: X-dedupe-unique
|
||||
value: RETAIN_UNIQUE
|
||||
- ingress:
|
||||
- higress-conformance-infra/wasmplugin-transform-response-body
|
||||
configDisable: false
|
||||
config:
|
||||
type: response
|
||||
rules:
|
||||
- operate: remove
|
||||
body:
|
||||
- key: X-removed
|
||||
- operate: rename
|
||||
body:
|
||||
- key: X-not-renamed
|
||||
value: X-renamed
|
||||
- operate: replace
|
||||
body:
|
||||
- key: X-replace
|
||||
value: replaced
|
||||
- operate: add
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: add
|
||||
- operate: append
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: append
|
||||
- operate: map
|
||||
body:
|
||||
- key: X-add-append
|
||||
value: X-map
|
||||
- operate: dedupe
|
||||
body:
|
||||
- key: X-dedupe-first
|
||||
value: RETAIN_FIRST
|
||||
- key: X-dedupe-last
|
||||
value: RETAIN_LAST
|
||||
- key: X-dedupe-unique
|
||||
value: RETAIN_UNIQUE
|
||||
url: file:///opt/plugins/wasm-go/extensions/transformer/plugin.wasm
|
||||
Reference in New Issue
Block a user