diff --git a/ci/tests/plugin-compiler/README.md b/ci/tests/plugin-compiler/README.md index b2aa02579fd..488f22da15a 100644 --- a/ci/tests/plugin-compiler/README.md +++ b/ci/tests/plugin-compiler/README.md @@ -38,6 +38,12 @@ The following variables are set as defaults: Use `task -l` to list available targets, or read on. +Example: Run a plugin subtest against a release image. + +``` +task test:qa-plugin image=tykio/tyk-plugin-compiler:v5.3.9-rc4 +``` + ## Building and testing plugin compiler locally In order to build the plugin compiler images locally from source, diff --git a/ci/tests/plugin-compiler/Taskfile.yml b/ci/tests/plugin-compiler/Taskfile.yml index 0e0fe1c0ed5..2c4a1495b82 100644 --- a/ci/tests/plugin-compiler/Taskfile.yml +++ b/ci/tests/plugin-compiler/Taskfile.yml @@ -1,3 +1,4 @@ +# yamllint disable rule:line-length --- version: "3" @@ -82,7 +83,6 @@ tasks: internal: true cmds: - test:basic-plugin: desc: "Test plugin compiler (basic-plugin)" vars: @@ -96,6 +96,20 @@ tasks: - docker run {{.args}} --entrypoint=/usr/local/bin/tyk {{.image}} plugin load -f plugin.so -s {{.symbol}} - strings {{.plugin_path}}/plugin.so | grep test_goplugin.go + test:qa-plugin: + desc: "Test plugin compiler (qa-plugin)" + vars: + plugin_path: '{{.root}}/ci/tests/plugin-compiler/testdata/qa-plugin' + symbol: AuthCheck + args: --rm -e DEBUG=1 -v {{.plugin_path}}:/plugin-source -w /plugin-source + cmds: + - rm -f {{.plugin_path}}/*.so + - docker run {{.args}} {{.image}} plugin.so + - cp -f {{.plugin_path}}/*.so {{.plugin_path}}/plugin.so + - docker run -e GOARCH=arm64 {{.args}} {{.image}} plugin.so + - docker run {{.args}} --entrypoint=/usr/local/bin/tyk {{.image}} plugin load -f plugin.so -s {{.symbol}} + - strings {{.plugin_path}}/plugin.so | grep test_goplugin.go + test:basic-plugin-id: desc: "Test plugin compiler (basic-plugin)" vars: @@ -136,4 +150,3 @@ tasks: - cp -f {{.plugin_path}}/*.so {{.plugin_path}}/plugin.so - docker run {{.args}} --entrypoint=/usr/local/bin/tyk {{.image}} plugin load -f plugin.so -s {{.symbol}} - strings {{.plugin_path}}/plugin.so | grep main.go - diff --git a/ci/tests/plugin-compiler/testdata/qa-plugin/README.md b/ci/tests/plugin-compiler/testdata/qa-plugin/README.md new file mode 100644 index 00000000000..ca3790e1bd9 --- /dev/null +++ b/ci/tests/plugin-compiler/testdata/qa-plugin/README.md @@ -0,0 +1,6 @@ +# QA Plugin + +The only difference between this and other plugins is that this one does +not provide a go.mod. This means a slightly different build path is +tested for the plugin compiler, ensuring coverage for when no go.mod is +provided. diff --git a/ci/tests/plugin-compiler/testdata/qa-plugin/main.go b/ci/tests/plugin-compiler/testdata/qa-plugin/main.go new file mode 100644 index 00000000000..06909267480 --- /dev/null +++ b/ci/tests/plugin-compiler/testdata/qa-plugin/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "github.com/TykTechnologies/tyk/ctx" + "github.com/TykTechnologies/tyk/log" + "github.com/TykTechnologies/tyk/user" + "net/http" +) + +var logger = log.Get() + +// AddFooBarHeader adds custom "Foo: Bar" header to the request +func AddFooBarHeader(rw http.ResponseWriter, r *http.Request) { + r.Header.Add("Foo", "Bar") +} + +// Custom Auth, applies a rate limit of +// 2 per 10 given a token of "abc" +func AuthCheck(rw http.ResponseWriter, r *http.Request) { + token := r.Header.Get("Authorization") + if token != "d3fd1a57-94ce-4a36-9dfe-679a8f493b49" && token != "3be61aa4-2490-4637-93b9-105001aa88a5" { + rw.WriteHeader(http.StatusUnauthorized) + return + } + session := &user.SessionState{ + Alias: token, + Rate: 2, + Per: 10, + MetaData: map[string]interface{}{ + token: token, + }, + KeyID: token, + } + ctx.SetSession(r, session, true) +} +func main() {} +func init() { + logger.Info("--- Go custom plugin v4 init success! ---- ") +}