diff --git a/Makefile.core.mk b/Makefile.core.mk index 221c677436..d72657c087 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -247,4 +247,4 @@ run-higress-e2e-test-wasmplugin: kubectl wait --timeout=10m -n higress-system deployment/higress-controller --for=condition=Available @echo -e "\n\033[36mWaiting higress-gateway to be ready...\033[0m\n" kubectl wait --timeout=10m -n higress-system deployment/higress-gateway --for=condition=Available - go test -v -tags conformance ./test/e2e/e2e_test.go -isWasmPluginTest=true --ingress-class=higress --debug=true + go test -v -tags conformance ./test/e2e/e2e_test.go -isWasmPluginTest=true -WasmPluginType=$(PLUGIN_TYPE) -WasmPluginName=$(PLUGIN_NAME) --ingress-class=higress --debug=true diff --git a/plugins/wasm-cpp/README.md b/plugins/wasm-cpp/README.md new file mode 100644 index 0000000000..275204152d --- /dev/null +++ b/plugins/wasm-cpp/README.md @@ -0,0 +1,170 @@ +[English](./README_EN.md) + +## 介绍 + +此 SDK 用于使用 CPP 语言开发 Higress 的 Wasm 插件。 + +## 使用 Higress wasm-cpp builder 快速构建 + +使用以下命令可以快速构建 wasm-cpp 插件: + +```bash +$ PLUGIN_NAME=request_block make build +``` + +
+输出结果 +

+DOCKER_BUILDKIT=1 docker build --build-arg PLUGIN_NAME=request_block \
+                                    -t request_block:20230721-141120-aa17e95 \
+                                    --output extensions/request_block \
+                                    .
+[+] Building 2.3s (10/10) FINISHED 
+
+output wasm file: extensions/request_block/plugin.wasm
+
+
+ +该命令最终构建出一个 wasm 文件和一个 Docker image。 +这个本地的 wasm 文件被输出到了指定的插件的目录下,可以直接用于调试。 + +### 参数说明 + +| 参数名称 | 可选/必须 | 默认值 | 含义 | +|---------------|-------|-------------------------------------------|----------------------------------------------------------------------| +| `PLUGIN_NAME` | 可选的 | hello-world | 要构建的插件名称。 | +| `IMG` | 可选的 | 如不设置则根据仓库地址、插件名称、构建时间以及 git commit id 生成。 | 生成的镜像名称。如非空,则会覆盖`REGISTRY` 参 | + +## 创建 WasmPlugin 资源使插件生效 + +编写 WasmPlugin 资源如下: + +```yaml +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: request-block + namespace: higress-system +spec: + defaultConfig: + block_urls: + - "swagger.html" + url: oci:///request_block:1.0.0 # 之前构建和推送的 image 地址 +``` + +使用 `kubectl apply -f ` 使资源生效。 +资源生效后,如果请求url携带 `swagger.html`, 则这个请求就会被拒绝,例如: + +```bash +curl /api/user/swagger.html +``` + +```text +HTTP/1.1 403 Forbidden +date: Wed, 09 Nov 2022 12:12:32 GMT +server: istio-envoy +content-length: 0 +``` + +如果需要进一步控制插件的执行阶段和顺序 + +可以阅读此 [文档](https://istio.io/latest/docs/reference/config/proxy_extensions/wasm-plugin/) 了解更多关于 wasmplugin 的配置 + +## 路由级或域名级生效 + +```yaml +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: request-block + namespace: higress-system +spec: + defaultConfig: + # 跟上面例子一样,这个配置会全局生效,但如果被下面规则匹配到,则会改为执行命中规则的配置 + block_urls: + - "swagger.html" + matchRules: + # 路由级生效配置 + - ingress: + - default/foo + # default 命名空间下名为 foo 的 ingress 会执行下面这个配置 + config: + block_bodies: + - "foo" + - ingress: + - default/bar + # default 命名空间下名为 bar 的 ingress 会执行下面这个配置 + config: + block_bodies: + - "bar" + # 域名级生效配置 + - domain: + - "*.example.com" + # 若请求匹配了上面的域名, 会执行下面这个配置 + config: + block_bodies: + - "foo" + - "bar" + url: oci:///request_block:1.0.0 +``` + +所有规则会按上面配置的顺序一次执行匹配,当有一个规则匹配时,就停止匹配,并选择匹配的配置执行插件逻辑。 + +## E2E测试 + +当你完成一个GO语言的插件功能时, 可以同时创建关联的e2e test cases, 并在本地对插件功能完成测试验证。 + +### step1. 编写 test cases +在目录./test/e2e/conformance下面, 分别添加xxx.yaml文件和xxx.go文件, 比如测试插件request-block + +./test/e2e/conformance/tests/cpp-request_block.yaml +``` +apiVersion: networking.k8s.io/v1 +kind: Ingress +... +... +spec: + defaultConfig: + block_urls: + - "swagger.html" + url: file:///opt/plugins/wasm-cpp/extensions/request_block/plugin.wasm +``` +`其中url中extensions后面的'request-block'为插件所在文件夹名称` + +./test/e2e/conformance/tests/cpp-request_block.go + +### step2. 添加 test cases +将上述所写test cases添加到e2e测试列表中, + +./test/e2e/e2e_test.go + +``` +... +cSuite.Setup(t) + var higressTests []suite.ConformanceTest + + if *isWasmPluginTest { + if strings.Compare(*wasmPluginType, "CPP") == 0 { + m := make(map[string]suite.ConformanceTest) + m["request_block"] = tests.CPPWasmPluginsRequestBlock + m["key_auth"] = tests.CPPWasmPluginsKeyAuth + //这里新增你新写的case方法名称 + + higressTests = []suite.ConformanceTest{ + m[*wasmPluginName], + } + } else { + higressTests = []suite.ConformanceTest{ + tests.WasmPluginsRequestBlock, + } + } + } else { +... +``` + +### step3. 编译插件并执行 test cases +考虑到本地构建wasm比较耗时, 我们支持只构建需要测试的插件(同时你也可以临时修改上面第二小步的测试cases列表, 只执行你新写的case)。 + +```bash +PLUGIN_TYPE=CPP PLUGIN_NAME=request_block make higress-wasmplugin-test +``` \ No newline at end of file diff --git a/plugins/wasm-cpp/README_EN.md b/plugins/wasm-cpp/README_EN.md new file mode 100644 index 0000000000..2aa863944e --- /dev/null +++ b/plugins/wasm-cpp/README_EN.md @@ -0,0 +1,167 @@ +## Intro + +This SDK is used to develop the WASM Plugins for Higress in Go. + +## Quick build with Higress wasm-go builder + +The wasm-go plugin can be built quickly with the following command: + +```bash +$ PLUGIN_NAME=request_block make build +``` + +
+Output +

+DOCKER_BUILDKIT=1 docker build --build-arg PLUGIN_NAME=request_block \
+                                    -t request_block:20230721-141120-aa17e95 \
+                                    --output extensions/request_block \
+                                    .
+[+] Building 2.3s (10/10) FINISHED 
+
+output wasm file: extensions/request_block/plugin.wasm
+
+
+ +This command eventually builds a wasm file and a Docker image. +This local wasm file is exported to the specified plugin's directory and can be used directly for debugging. + +### Environmental parameters + +| Name | Optional/Required | Default | meaning | +|---------------|---------------|------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +| `PLUGIN_NAME` | Optional | hello-world | The name of the plugin to build. | +| `IMG` | Optional | If it is empty, it is generated based on the repository address, plugin name, build time, and git commit id. | The generated image tag will override the `REGISTRY` parameter if it is not empty. | + +## Apply WasmPlugin API + +Read this [document](https://istio.io/latest/docs/reference/config/proxy_extensions/wasm-plugin/) to learn more about wasmplugin. + +Create a WasmPlugin API resource: + +```yaml +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: request-block + namespace: higress-system +spec: + defaultConfig: + block_urls: + - "swagger.html" + url: oci:///request-block:1.0.0 +``` + +When the resource is applied on the Kubernetes cluster with `kubectl apply -f `, +the request will be blocked if the string `swagger.html` in the url. + +```bash +curl /api/user/swagger.html +``` + +```text +HTTP/1.1 403 Forbidden +date: Wed, 09 Nov 2022 12:12:32 GMT +server: istio-envoy +content-length: 0 +``` + +## route-level & domain-level takes effect + +```yaml +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: request-block + namespace: higress-system +spec: + defaultConfig: + # this config will take effect globally (all incoming requests not matched by rules below) + block_urls: + - "swagger.html" + matchRules: + # ingress-level takes effect + - ingress: + - default/foo + # the ingress foo in namespace default will use this config + config: + block_bodies: + - "foo" + - ingress: + - default/bar + # the ingress bar in namespace default will use this config + config: + block_bodies: + - "bar" + # domain-level takes effect + - domain: + - "*.example.com" + # if the request's domain matched, this config will be used + config: + block_bodies: + - "foo" + - "bar" + url: oci:///request-block:1.0.0 +``` + +The rules will be matched in the order of configuration. If one match is found, it will stop, and the matching configuration will take effect. + + +## E2E test + +When you complete a GO plug-in function, you can create associated e2e test cases at the same time, and complete the test verification of the plug-in function locally. + +### step1. write test cases +In the directory of `./ test/e2e/conformance/tests/`, add the xxx.yaml file and xxx.go file. Such as test for `request-block` wasm-plugin, + +./test/e2e/conformance/tests/request-block.yaml +``` +apiVersion: networking.k8s.io/v1 +kind: Ingress +... +... +spec: + defaultConfig: + block_urls: + - "swagger.html" + url: file:///opt/plugins/wasm-go/extensions/request-block/plugin.wasm +``` +`Above of the url, the name of after extensions indicates the name of the folder where the plug-in resides.` + +./test/e2e/conformance/tests/request-block.go + +### step2. add test cases +Add the test cases written above to the e2e test list, + +./test/e2e/e2e_test.go + +``` +... +cSuite.Setup(t) + var higressTests []suite.ConformanceTest + + if *isWasmPluginTest { + if strings.Compare(*wasmPluginType, "CPP") == 0 { + m := make(map[string]suite.ConformanceTest) + m["request_block"] = tests.CPPWasmPluginsRequestBlock + m["key_auth"] = tests.CPPWasmPluginsKeyAuth + //Add your newly written case method name here + + higressTests = []suite.ConformanceTest{ + m[*wasmPluginName], + } + } else { + higressTests = []suite.ConformanceTest{ + tests.WasmPluginsRequestBlock, + } + } + } else { +... +``` + +### step3. compile and run test cases +Considering that building wasm locally is time-consuming, we support building only the plug-ins that need to be tested (at the same time, you can also temporarily modify the list of test cases in the second small step above, and only execute your newly written cases). + +```bash +PLUGIN_TYPE=CPP PLUGIN_NAME=request_block make higress-wasmplugin-test +``` \ No newline at end of file diff --git a/plugins/wasm-go/README.md b/plugins/wasm-go/README.md index 2d560f49c6..804ef79101 100644 --- a/plugins/wasm-go/README.md +++ b/plugins/wasm-go/README.md @@ -149,9 +149,9 @@ spec: 当你完成一个GO语言的插件功能时, 可以同时创建关联的e2e test cases, 并在本地对插件功能完成测试验证。 ### step1. 编写 test cases -在目录./test/ingress/conformance下面, 分别添加xxx.yaml文件和xxx.go文件, 比如测试插件request-block +在目录./test/e2e/conformance/tests/下面, 分别添加xxx.yaml文件和xxx.go文件, 比如测试插件request-block -./test/ingress/conformance/request-block.yaml +./test/e2e/conformance/tests/request-block.yaml ``` apiVersion: networking.k8s.io/v1 kind: Ingress @@ -165,12 +165,12 @@ spec: ``` `其中url中extensions后面的'request-block'为插件所在文件夹名称` -./test/ingress/conformance/request-block.go +./test/e2e/conformance/tests/request-block.go ### step2. 添加 test cases 将上述所写test cases添加到e2e测试列表中, -./test/ingress/conformance/request-block.yaml +./test/e2e/e2e_test.go ``` ... @@ -178,14 +178,21 @@ cSuite.Setup(t) var higressTests []suite.ConformanceTest if *isWasmPluginTest { - higressTests = []suite.ConformanceTest{ - tests.WasmPluginsRequestBlock, - //这里新增你新写的case方法名称 + if strings.Compare(*wasmPluginType, "CPP") == 0 { + m := make(map[string]suite.ConformanceTest) + m["request_block"] = tests.CPPWasmPluginsRequestBlock + m["key_auth"] = tests.CPPWasmPluginsKeyAuth + + higressTests = []suite.ConformanceTest{ + m[*wasmPluginName], + } + } else { + higressTests = []suite.ConformanceTest{ + tests.WasmPluginsRequestBlock, + //这里新增你新写的case方法名称 + } } } else { - higressTests = []suite.ConformanceTest{ - tests.HTTPRouteSimpleSameNamespace, - tests.HTTPRouteHostNameSameNamespace, ... ``` @@ -193,5 +200,5 @@ cSuite.Setup(t) 考虑到本地构建wasm比较耗时, 我们支持只构建需要测试的插件(同时你也可以临时修改上面第二小步的测试cases列表, 只执行你新写的case)。 ```bash -PLUGIN_NAME=request-block make ingress-wasmplugin-test +PLUGIN_NAME=request-block make higress-wasmplugin-test ``` \ No newline at end of file diff --git a/plugins/wasm-go/README_EN.md b/plugins/wasm-go/README_EN.md index a8f9220ea3..cc640154d9 100644 --- a/plugins/wasm-go/README_EN.md +++ b/plugins/wasm-go/README_EN.md @@ -144,9 +144,9 @@ The rules will be matched in the order of configuration. If one match is found, When you complete a GO plug-in function, you can create associated e2e test cases at the same time, and complete the test verification of the plug-in function locally. ### step1. write test cases -In the directory of `./ test/ingress/conformance`, add the xxx.yaml file and xxx.go file. Such as test for `request-block` wasm-plugin, +In the directory of `./ test/e2e/conformance/tests/`, add the xxx.yaml file and xxx.go file. Such as test for `request-block` wasm-plugin, -./test/ingress/conformance/request-block.yaml +./test/e2e/conformance/tests/request-block.yaml ``` apiVersion: networking.k8s.io/v1 kind: Ingress @@ -160,12 +160,12 @@ spec: ``` `Above of the url, the name of after extensions indicates the name of the folder where the plug-in resides.` -./test/ingress/conformance/request-block.go +./test/e2e/conformance/tests/request-block.go ### step2. add test cases Add the test cases written above to the e2e test list, -./test/ingress/conformance/request-block.yaml +./test/e2e/e2e_test.go ``` ... @@ -173,14 +173,21 @@ cSuite.Setup(t) var higressTests []suite.ConformanceTest if *isWasmPluginTest { - higressTests = []suite.ConformanceTest{ - tests.WasmPluginsRequestBlock, - //Add your newly written case method name here + if strings.Compare(*wasmPluginType, "CPP") == 0 { + m := make(map[string]suite.ConformanceTest) + m["request_block"] = tests.CPPWasmPluginsRequestBlock + m["key_auth"] = tests.CPPWasmPluginsKeyAuth + + higressTests = []suite.ConformanceTest{ + m[*wasmPluginName], + } + } else { + higressTests = []suite.ConformanceTest{ + tests.WasmPluginsRequestBlock, + //Add your newly written case method name here + } } } else { - higressTests = []suite.ConformanceTest{ - tests.HTTPRouteSimpleSameNamespace, - tests.HTTPRouteHostNameSameNamespace, ... ``` @@ -188,5 +195,5 @@ cSuite.Setup(t) Considering that building wasm locally is time-consuming, we support building only the plug-ins that need to be tested (at the same time, you can also temporarily modify the list of test cases in the second small step above, and only execute your newly written cases). ```bash -PLUGIN_NAME=request-block make ingress-wasmplugin-test +PLUGIN_NAME=request-block make higress-wasmplugin-test ``` \ No newline at end of file diff --git a/test/README.md b/test/README.md index d5fb6b86c1..d0c20cb611 100644 --- a/test/README.md +++ b/test/README.md @@ -17,9 +17,11 @@ Higress e2e tests are mainly focusing on two parts for now: Higress provides make target to run ingress api conformance tests and wasmplugin tests, -+ API Tests: `make ingress-conformance-test` -+ WasmPlugin Tests: `make ingress-wasmplugin-test` - + Only build one WasmPlugin for testing: `PLUGIN_NAME=request-block make ingress-wasmplugin-test` ++ API Tests: `make higress-conformance-test` ++ WasmPlugin Tests: `make higress-wasmplugin-test` + + Build ALL GO WasmPlugins for testing: `make higress-wasmplugin-test` + + Only build one GO WasmPlugin for testing: `PLUGIN_NAME=request-block make higress-wasmplugin-test` + + Only build one CPP WasmPlugin for testing: `PLUGIN_TYPE=CPP PLUGIN_NAME=key_auth make higress-wasmplugin-test` It can be divided into below steps: diff --git a/test/e2e/conformance/tests/cpp-key_auth.go b/test/e2e/conformance/tests/cpp-key_auth.go new file mode 100644 index 0000000000..bbcaa8cd23 --- /dev/null +++ b/test/e2e/conformance/tests/cpp-key_auth.go @@ -0,0 +1,77 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tests + +import ( + "testing" + + "github.com/alibaba/higress/test/e2e/conformance/utils/http" + "github.com/alibaba/higress/test/e2e/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, CPPWasmPluginsKeyAuth) +} + +var CPPWasmPluginsKeyAuth = suite.ConformanceTest{ + ShortName: "CPPWasmPluginsKeyAuth", + Description: "The Ingress in the higress-conformance-infra namespace test the CPP key_auth wasmplugins.", + Manifests: []string{"tests/cpp-key_auth.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/test.html", + UnfollowRedirect: true, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 401, + }, + }, + }, + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/test.html?apikey=2bda943c-ba2b-11ec-ba07-00163e1250b5", + UnfollowRedirect: true, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, + } + t.Run("WasmPlugins key-auth.yaml", func(t *testing.T) { + for _, testcase := range testcases { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase) + } + }) + }, +} diff --git a/test/e2e/conformance/tests/cpp-key_auth.yaml b/test/e2e/conformance/tests/cpp-key_auth.yaml new file mode 100644 index 0000000000..e32807ef08 --- /dev/null +++ b/test/e2e/conformance/tests/cpp-key_auth.yaml @@ -0,0 +1,51 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/app-root: "/foo" + name: httproute-app-root + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: "foo.com" + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 +--- +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: cpp-key-auth + namespace: higress-system +spec: + defaultConfig: + consumers: + - credential: 2bda943c-ba2b-11ec-ba07-00163e1250b5 + name: consumer1 + - credential: c8c8e9ca-558e-4a2d-bb62-e700dcc40e35 + name: consumer2 + keys: + - apikey + in_query: true + url: file:///opt/plugins/wasm-cpp/extensions/key_auth/plugin.wasm diff --git a/test/e2e/conformance/tests/cpp-request_block.go b/test/e2e/conformance/tests/cpp-request_block.go new file mode 100644 index 0000000000..f9aeb87348 --- /dev/null +++ b/test/e2e/conformance/tests/cpp-request_block.go @@ -0,0 +1,59 @@ +// Copyright (c) 2022 Alibaba Group Holding Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tests + +import ( + "testing" + + "github.com/alibaba/higress/test/e2e/conformance/utils/http" + "github.com/alibaba/higress/test/e2e/conformance/utils/suite" +) + +func init() { + HigressConformanceTests = append(HigressConformanceTests, CPPWasmPluginsRequestBlock) +} + +var CPPWasmPluginsRequestBlock = suite.ConformanceTest{ + ShortName: "CPPWasmPluginsRequestBlock", + Description: "The Ingress in the higress-conformance-infra namespace test the cpp request-block wasmplugins.", + Manifests: []string{"tests/cpp-request_block.yaml"}, + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { + testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "foo.com", + Path: "/swagger.html", + UnfollowRedirect: true, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 403, + }, + }, + }, + } + t.Run("WasmPlugins request-block", func(t *testing.T) { + for _, testcase := range testcases { + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase) + } + }) + }, +} diff --git a/test/e2e/conformance/tests/cpp-request_block.yaml b/test/e2e/conformance/tests/cpp-request_block.yaml new file mode 100644 index 0000000000..fdfecab1ae --- /dev/null +++ b/test/e2e/conformance/tests/cpp-request_block.yaml @@ -0,0 +1,45 @@ +# Copyright (c) 2022 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/app-root: "/foo" + name: httproute-app-root + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: "foo.com" + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 +--- +apiVersion: extensions.higress.io/v1alpha1 +kind: WasmPlugin +metadata: + name: cpp-request-block + namespace: higress-system +spec: + defaultConfig: + block_urls: + - "swagger.html" + url: file:///opt/plugins/wasm-cpp/extensions/request_block/plugin.wasm diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 00ceaf20ad..9fb28cf832 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -16,6 +16,7 @@ package test import ( "flag" + "strings" "testing" "github.com/stretchr/testify/require" @@ -29,6 +30,8 @@ import ( ) var isWasmPluginTest = flag.Bool("isWasmPluginTest", false, "") +var wasmPluginType = flag.String("WasmPluginType", "GO", "") +var wasmPluginName = flag.String("WasmPluginName", "", "") func TestHigressConformanceTests(t *testing.T) { flag.Parse() @@ -53,8 +56,18 @@ func TestHigressConformanceTests(t *testing.T) { var higressTests []suite.ConformanceTest if *isWasmPluginTest { - higressTests = []suite.ConformanceTest{ - tests.WasmPluginsRequestBlock, + if strings.Compare(*wasmPluginType, "CPP") == 0 { + m := make(map[string]suite.ConformanceTest) + m["request_block"] = tests.CPPWasmPluginsRequestBlock + m["key_auth"] = tests.CPPWasmPluginsKeyAuth + + higressTests = []suite.ConformanceTest{ + m[*wasmPluginName], + } + } else { + higressTests = []suite.ConformanceTest{ + tests.WasmPluginsRequestBlock, + } } } else { higressTests = []suite.ConformanceTest{ diff --git a/tools/hack/build-wasm-plugins.sh b/tools/hack/build-wasm-plugins.sh index fd3831ae3d..43759b8a8c 100755 --- a/tools/hack/build-wasm-plugins.sh +++ b/tools/hack/build-wasm-plugins.sh @@ -16,25 +16,41 @@ set -euo pipefail -cd ./plugins/wasm-go/ +TYPE=${PLUGIN_TYPE-""} INNER_PLUGIN_NAME=${PLUGIN_NAME-""} -if [ ! -n "$INNER_PLUGIN_NAME" ]; then - EXTENSIONS_DIR=$(pwd)"/extensions/" - echo "build all wasmplugins under folder of $EXTENSIONS_DIR" - for file in `ls $EXTENSIONS_DIR` - do - # TODO: adjust waf build - if [ $file == "waf" ]; then - continue - fi - if [ -d $EXTENSIONS_DIR$file ]; then - name=${file##*/} - echo "build wasmplugin name of $name" - PLUGIN_NAME=${name} make build - fi - done + +if [ $TYPE == "CPP" ] +then + cd ./plugins/wasm-cpp/ + if [ ! -n "$INNER_PLUGIN_NAME" ]; then + echo "you must specify which cpp plugin you want to compile" + else + echo "build wasmplugin-cpp name of $INNER_PLUGIN_NAME" + PLUGIN_NAME=${INNER_PLUGIN_NAME} make build + fi else - echo "build wasmplugin name of $INNER_PLUGIN_NAME" - PLUGIN_NAME=${INNER_PLUGIN_NAME} make build + echo "not specify plugin language, so just compile wasm-go as default" + cd ./plugins/wasm-go/ + if [ ! -n "$INNER_PLUGIN_NAME" ]; then + EXTENSIONS_DIR=$(pwd)"/extensions/" + echo "build all wasmplugins-go under folder of $EXTENSIONS_DIR" + for file in `ls $EXTENSIONS_DIR` + do + # TODO: adjust waf build + if [ $file == "waf" ]; then + continue + fi + if [ -d $EXTENSIONS_DIR$file ]; then + name=${file##*/} + echo "build wasmplugin name of $name" + PLUGIN_NAME=${name} make build + fi + done + else + echo "build wasmplugin-go name of $INNER_PLUGIN_NAME" + PLUGIN_NAME=${INNER_PLUGIN_NAME} make build + fi fi + +