Skip to content

Commit

Permalink
fix(termination) allow plugin to be added to a consumer
Browse files Browse the repository at this point in the history
fixes Kong#2526
  • Loading branch information
Tieske authored and p0pr0ck5 committed May 16, 2017
1 parent 900ec4e commit 6683b6c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
1 change: 0 additions & 1 deletion kong/plugins/request-termination/schema.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local Errors = require "kong.dao.errors"

return {
no_consumer = true,
fields = {
status_code = { type = "number", default = 503 },
message = { type = "string" },
Expand Down
67 changes: 67 additions & 0 deletions spec/03-plugins/27-request-termination/03-integration_spec.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6683b6c

Please sign in to comment.