-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wasm): add a startup check for missing filters
This adds a check during `init` that will prevent Kong from starting if any filter chain entities are found in the database using a filter that is not installed. Example: > Error: ./kong/cmd/start.lua:99: nginx: [error] init_by_lua error: /path/to/kong/init.lua:750: [wasm]: found one or more filter chain entities with filters that are not enabled/installed: > filter chain: 9e0b56d6-0e8c-469f-bf15-142debdd5d05, filter: #1 (response_transformer) > filter chain: 9e0b56d6-0e8c-469f-bf15-142debdd5d05, filter: #3 (response_transformer) Previously, this condition would not be caught until the Wasm state is built during `init_worker`. This change brings Wasm more in line with the behavior of the plugins iterator.
- Loading branch information
Showing
3 changed files
with
124 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
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
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,87 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
local FILTER_PATH = assert(helpers.test_conf.wasm_filters_path) | ||
|
||
-- no cassandra support | ||
for _, strategy in helpers.each_strategy({ "postgres" }) do | ||
|
||
describe("missing filters in the config [#" .. strategy .. "]", function() | ||
local bp | ||
local service, route | ||
|
||
lazy_setup(function() | ||
require("kong.runloop.wasm").enable({ | ||
{ name = "tests", | ||
path = FILTER_PATH .. "/tests.wasm", | ||
}, | ||
{ name = "response_transformer", | ||
path = FILTER_PATH .. "/response_transformer.wasm", | ||
}, | ||
}) | ||
|
||
bp = helpers.get_db_utils(strategy, { | ||
"routes", | ||
"services", | ||
"filter_chains", | ||
}) | ||
|
||
service = assert(bp.services:insert { | ||
name = "wasm-test", | ||
}) | ||
|
||
route = assert(bp.routes:insert { | ||
service = service, | ||
paths = { "/" }, | ||
}) | ||
|
||
assert(bp.filter_chains:insert { | ||
name = "test", | ||
route = route, | ||
filters = { | ||
{ | ||
name = "response_transformer", | ||
config = require("cjson").encode { | ||
append = { | ||
headers = { | ||
"x-wasm-test:my-value", | ||
}, | ||
}, | ||
} | ||
}, | ||
{ | ||
name = "tests", | ||
config = nil, | ||
}, | ||
{ | ||
name = "response_transformer", | ||
config = require("cjson").encode { | ||
append = { | ||
headers = { | ||
"x-wasm-test:my-value", | ||
}, | ||
}, | ||
} | ||
} | ||
} | ||
}) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.clean_prefix() | ||
end) | ||
|
||
it("causes Kong to fail to start", function() | ||
local ok, err = helpers.start_kong({ | ||
database = strategy, | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
wasm_filters = "tests", | ||
wasm = true, | ||
}) | ||
|
||
assert.falsy(ok, "expected `kong start` to fail") | ||
assert.string(err) | ||
assert.matches("response_transformer", err) | ||
end) | ||
end) | ||
|
||
end -- each strategy |