diff --git a/kong/plugins/request-termination/schema.lua b/kong/plugins/request-termination/schema.lua index 0bf13e407d5e..5e6e80e2d16c 100644 --- a/kong/plugins/request-termination/schema.lua +++ b/kong/plugins/request-termination/schema.lua @@ -1,7 +1,6 @@ local Errors = require "kong.dao.errors" return { - no_consumer = true, fields = { status_code = { type = "number", default = 503 }, message = { type = "string" }, diff --git a/spec/03-plugins/27-request-termination/03-integration_spec.lua b/spec/03-plugins/27-request-termination/03-integration_spec.lua new file mode 100644 index 000000000000..2d15af35d4ae --- /dev/null +++ b/spec/03-plugins/27-request-termination/03-integration_spec.lua @@ -0,0 +1,67 @@ +local helpers = require "spec.helpers" + +describe("Plugin: request-termination (integration)", function() + local client, admin_client + local consumer1 + + setup(function() + assert(helpers.dao.apis:insert { + name = "api-1", + hosts = { "api1.request-termination.com" }, + upstream_url = "http://mockbin.com" + }) + assert(helpers.dao.plugins:insert { + name = "key-auth", + }) + consumer1 = assert(helpers.dao.consumers:insert { + username = "bob" + }) + assert(helpers.dao.keyauth_credentials:insert { + key = "kong", + consumer_id = consumer1.id + }) + + + assert(helpers.start_kong()) + client = helpers.proxy_client() + admin_client = helpers.admin_client() + end) + + teardown(function() + if client and admin_client then + client:close() + admin_client:close() + end + helpers.stop_kong() + end) + + + it("can be applied on a consumer", function() + -- add the plugin to a consumer + local res = assert(admin_client:send { + method = "POST", + path = "/plugins", + headers = { + ["Content-type"] = "application/json", + }, + body = { + name = "request-termination", + consumer_id = consumer1.id, + }, + }) + assert.response(res).has.status(201) + + -- verify access being blocked + res = assert(client:send { + method = "GET", + path = "/request", + headers = { + ["Host"] = "api1.request-termination.com", + ["apikey"] = "kong", + }, + }) + assert.response(res).has.status(503) + local body = assert.response(res).has.jsonbody() + assert.same({ message = "Service unavailable" }, body) + end) +end)