-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding first simple tests using pongo * Set static plugin version 1.0.0 for tests * Adding simple tests for auth config service plugin * Run tests for each plugin in parallel * Fix ENVs
- Loading branch information
Showing
9 changed files
with
636 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: Test | ||
|
||
on: | ||
push | ||
|
||
env: | ||
IMAGE_NAME: pongo | ||
PONGO_VERSION: 1.1.0 | ||
KONG_VERSION: 2.8.1 | ||
|
||
# Static value, only used to fulfill rockspec format | ||
PLUGIN_VERSION: 1.0.0 | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
file: ./pongo/Dockerfile | ||
tags: ${{ env.IMAGE_NAME }}:${{ env.PONGO_VERSION }} | ||
build-args: | | ||
PONGO_VERSION=${{ env.PONGO_VERSION }} | ||
outputs: type=docker,dest=/tmp/test-image.tar | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: test-image | ||
path: /tmp/test-image.tar | ||
|
||
|
||
|
||
ngsi-ishare-policies: | ||
|
||
runs-on: ubuntu-latest | ||
needs: build | ||
env: | ||
PONGO_PLUGIN_SOURCE: ./kong-plugin-ngsi-ishare-policies | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '>=1.17.0' | ||
|
||
- name: Prepare values | ||
run: | | ||
echo GITHUB_ORGANISATION: fiware >> values.yaml | ||
echo GITHUB_REPO: kong-plugins-fiware >> values.yaml | ||
echo VERSION: ${{ env.PLUGIN_VERSION }} >> values.yaml | ||
- name: Download artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: test-image | ||
path: /tmp | ||
|
||
- name: Load Docker image | ||
run: | | ||
docker load --input /tmp/test-image.tar | ||
- name: Parse rockspec | ||
run: | | ||
go install github.com/cbroglie/mustache/cmd/mustache@v1.3.1 | ||
~/go/bin/mustache values.yaml kong-plugin-ngsi-ishare-policies/rockspec.mustache > kong-plugin-ngsi-ishare-policies/kong-plugin-ngsi-ishare-policies-1.0.0-1.rockspec | ||
- name: Run tests | ||
run: ./pongo/pongo-docker.sh run | ||
|
||
|
||
auth-endpoint-config-ishare: | ||
|
||
runs-on: ubuntu-latest | ||
needs: build | ||
env: | ||
PONGO_PLUGIN_SOURCE: ./kong-plugin-auth-endpoint-config-ishare | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '>=1.17.0' | ||
|
||
- name: Prepare values | ||
run: | | ||
echo GITHUB_ORGANISATION: fiware >> values.yaml | ||
echo GITHUB_REPO: kong-plugins-fiware >> values.yaml | ||
echo VERSION: ${{ env.PLUGIN_VERSION }} >> values.yaml | ||
- name: Download artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: test-image | ||
path: /tmp | ||
|
||
- name: Load Docker image | ||
run: | | ||
docker load --input /tmp/test-image.tar | ||
- name: Parse rockspec | ||
run: | | ||
go install github.com/cbroglie/mustache/cmd/mustache@v1.3.1 | ||
~/go/bin/mustache values.yaml kong-plugin-auth-endpoint-config-ishare/rockspec.mustache > kong-plugin-auth-endpoint-config-ishare/kong-plugin-auth-endpoint-config-ishare-1.0.0-1.rockspec | ||
- name: Run tests | ||
run: ./pongo/pongo-docker.sh run |
100 changes: 100 additions & 0 deletions
100
kong-plugin-auth-endpoint-config-ishare/spec/auth-endpoint-config-ishare/01-schema_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
-- Schema tests | ||
|
||
local PLUGIN_NAME = "auth-endpoint-config-ishare" | ||
local schema_def = require("kong.plugins."..PLUGIN_NAME..".schema") | ||
local v = require("spec.helpers").validate_plugin_config_schema | ||
|
||
describe("Plugin: " .. PLUGIN_NAME .. " (schema), ", function() | ||
|
||
it("Full config with satellite validates", function() | ||
assert(v({ | ||
access_token = { | ||
header_names = {"authorization", "Authorization"} | ||
}, | ||
jws = { | ||
identifier = "EU.EORI.TEST", | ||
private_key = "XXXX", | ||
x5c = "YYYY", | ||
}, | ||
ar = { | ||
identifier = "EU.EORI.TESTAR", | ||
host = "AR_HOST", | ||
token_endpoint = "AR_TOKEN", | ||
delegation_endpoint = "AR_DELEGATION" | ||
}, | ||
satellite = { | ||
identifier = "EU.EORI.TESTSAT", | ||
host = "SAT_HOST", | ||
token_endpoint = "SAT_TOKEN", | ||
trusted_list_endpoint = "SAT_TRUSTED_LIST" | ||
}, | ||
}, schema_def)) | ||
end) | ||
|
||
describe("Errors", function() | ||
|
||
it("jws.identifier required", function() | ||
local config = { | ||
access_token = { | ||
header_names = {"authorization", "Authorization"} | ||
}, | ||
jws = { | ||
private_key = "XXXX", | ||
x5c = "YYYY", | ||
}, | ||
ar = { | ||
identifier = "EU.EORI.TESTAR", | ||
host = "AR_HOST", | ||
token_endpoint = "AR_TOKEN", | ||
delegation_endpoint = "AR_DELEGATION" | ||
}, | ||
satellite = { | ||
identifier = "EU.EORI.TESTSAT", | ||
host = "SAT_HOST", | ||
token_endpoint = "SAT_TOKEN", | ||
trusted_list_endpoint = "SAT_TRUSTED_LIST" | ||
}, | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.falsy(ok) | ||
assert.same({ | ||
jws = { | ||
identifier = 'required field missing' | ||
} | ||
}, err.config) | ||
end) | ||
|
||
it("ar.identifier required", function() | ||
local config = { | ||
access_token = { | ||
header_names = {"authorization", "Authorization"} | ||
}, | ||
jws = { | ||
identifier = "EU.EORI.TEST", | ||
private_key = "XXXX", | ||
x5c = "YYYY", | ||
}, | ||
ar = { | ||
host = "AR_HOST", | ||
token_endpoint = "AR_TOKEN", | ||
delegation_endpoint = "AR_DELEGATION" | ||
}, | ||
satellite = { | ||
identifier = "EU.EORI.TESTSAT", | ||
host = "SAT_HOST", | ||
token_endpoint = "SAT_TOKEN", | ||
trusted_list_endpoint = "SAT_TRUSTED_LIST" | ||
}, | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.falsy(ok) | ||
assert.same({ | ||
ar = { | ||
identifier = 'required field missing' | ||
} | ||
}, err.config) | ||
end) | ||
|
||
end) | ||
|
||
end) |
98 changes: 98 additions & 0 deletions
98
kong-plugin-auth-endpoint-config-ishare/spec/auth-endpoint-config-ishare/02-plugin_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
-- Simple tests to check for loading of plugin | ||
|
||
local PLUGIN_NAME = "auth-endpoint-config-ishare" | ||
|
||
local helpers = require "spec.helpers" | ||
local cjson = require "cjson" | ||
|
||
for _, strategy in helpers.each_strategy() do | ||
|
||
describe("Plugin: " .. PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function() | ||
local client | ||
|
||
lazy_setup(function() | ||
|
||
local bp = helpers.get_db_utils(strategy == "off" and "postgres" or strategy, nil, { PLUGIN_NAME }) | ||
|
||
local route1 = bp.routes:insert({ | ||
hosts = { "test1.com" }, | ||
}) | ||
-- add the plugin with dummy config | ||
bp.plugins:insert { | ||
name = PLUGIN_NAME, | ||
route = { id = route1.id }, | ||
config = { | ||
access_token = { | ||
header_names = {"authorization", "Authorization"} | ||
}, | ||
jws = { | ||
identifier = "EU.EORI.TEST", | ||
private_key = "XXXX", | ||
x5c = "YYYY", | ||
}, | ||
ar = { | ||
identifier = "EU.EORI.TESTAR", | ||
host = "AR_HOST", | ||
token_endpoint = "AR_TOKEN", | ||
delegation_endpoint = "AR_DELEGATION" | ||
}, | ||
satellite = { | ||
identifier = "EU.EORI.TESTSAT", | ||
host = "SAT_HOST", | ||
token_endpoint = "SAT_TOKEN", | ||
trusted_list_endpoint = "SAT_TRUSTED_LIST" | ||
} | ||
}, | ||
} | ||
|
||
-- start kong | ||
assert(helpers.start_kong({ | ||
-- set the strategy | ||
database = strategy, | ||
-- use the custom test template to create a local mock server | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
-- make sure our plugin gets loaded | ||
plugins = "bundled," .. PLUGIN_NAME, | ||
-- write & load declarative config, only if 'strategy=off' | ||
declarative_config = strategy == "off" and helpers.make_yaml_file() or nil, | ||
})) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong(nil, true) | ||
end) | ||
|
||
before_each(function() | ||
client = helpers.proxy_client() | ||
end) | ||
|
||
after_each(function() | ||
if client then client:close() end | ||
end) | ||
|
||
-- Simple tests | ||
describe("Simple tests for loading plugin", function() | ||
|
||
it("fails with missing access_token", function() | ||
|
||
local r = client:get("/request", { | ||
headers = { | ||
host = "test1.com" | ||
} | ||
}) | ||
local res = assert(r) | ||
|
||
-- Assert failed request and get body | ||
local body = assert.res_status(401, res) | ||
local json = cjson.decode(body) | ||
|
||
-- Assert message | ||
assert.same({ message = "Unauthorized" }, json) | ||
|
||
end) | ||
|
||
end) | ||
|
||
end) | ||
|
||
end |
Oops, something went wrong.