Skip to content

Commit

Permalink
feat: support req&resp body check
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle-Justice committed Jan 3, 2024
1 parent 03597f1 commit 24443be
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 136 deletions.
32 changes: 25 additions & 7 deletions test/e2e/conformance/base/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ spec:
containers:
- name: infra-backend-v1
# From https://github.com/kubernetes-sigs/ingress-controller-conformance/tree/master/images/echoserver
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -107,7 +110,10 @@ spec:
spec:
containers:
- name: infra-backend-v2
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -153,7 +159,10 @@ spec:
spec:
containers:
- name: infra-backend-v3
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -200,7 +209,7 @@ spec:
containers:
- name: infra-backend-echo-body-v1
# FROM https://github.com/higress-group/echo-body
image: 873292889/echo-body:1.5.0
image: 873292889/echo-body:1.0.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -253,7 +262,10 @@ spec:
spec:
containers:
- name: app-backend-v1
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -299,7 +311,10 @@ spec:
spec:
containers:
- name: app-backend-v2
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down Expand Up @@ -352,7 +367,10 @@ spec:
spec:
containers:
- name: web-backend
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e
# image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/echoserver:v20221109-7ee2f3e

# From https://github.com/Uncle-Justice/echo-server
image: 873292889/echo-server:1.3.0
env:
- name: POD_NAME
valueFrom:
Expand Down
47 changes: 30 additions & 17 deletions test/e2e/conformance/tests/go-wasm-request-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ 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: "foo2.com",
Host: "foo.com",
Path: "/foo",
Method: "POST",
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello world`),
Method: "POST",
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello world`),
UnfollowRedirect: true,
},
},
Expand All @@ -105,44 +109,53 @@ var WasmPluginsRequestBlock = suite.ConformanceTest{
},
},
{
// check body echoed back
// 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: "Request",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "foo2.com",
Host: "foo.com",
Path: "/foo",
Method: "POST",
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello higress`),
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`),
},
},
},
{
// not check body echoed back
// check body echoed back in expected response
Meta: http.AssertionMeta{
TargetBackend: "infra-backend-echo-body-v1",
TargetNamespace: "higress-conformance-infra",
CompareTarget: "Response",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "foo2.com",
Path: "/foo",
Method: "POST",
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello higress`),
Method: "POST",
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello higress`),
UnfollowRedirect: true,
},
},
Response: http.AssertionResponse{
ExpectedResponse: http.Response{
StatusCode: 200,
StatusCode: 200,
ContentType: http.ContentTypeTextPlain,
Body: []byte(`hello higress`),
},
},
},

}
t.Run("WasmPlugins request-block", func(t *testing.T) {
for _, testcase := range testcases {
Expand Down
49 changes: 47 additions & 2 deletions test/e2e/conformance/tests/go-wasm-transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ var WasmPluginsTransformer = suite.ConformanceTest{
},
{
Meta: http.AssertionMeta{
TestCaseName: "case 3: resquest body transformer",
TestCaseName: "case 4: request body transformer",
TargetBackend: "infra-backend-v1",
TargetNamespace: "higress-conformance-infra",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Expand All @@ -129,10 +131,53 @@ var WasmPluginsTransformer = suite.ConformanceTest{
`),
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 body transformer",
TargetBackend: "infra-backend-echo-body-v1",
TargetNamespace: "higress-conformance-infra",
CompareTarget: "Response",
},
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(`
Expand Down
65 changes: 59 additions & 6 deletions test/e2e/conformance/tests/go-wasm-transformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,6 +62,26 @@ 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
Expand Down Expand Up @@ -138,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
Expand Down Expand Up @@ -171,8 +190,6 @@ spec:
headers:
- key: X-add-append
value: X-map

# request transformer
- ingress:
- higress-conformance-infra/wasmplugin-transform-request-body
configDisable: false
Expand Down Expand Up @@ -210,5 +227,41 @@ spec:
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
Loading

0 comments on commit 24443be

Please sign in to comment.