-
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.
fix(termination) allow plugin to be added to a consumer
fixes Kong#2526
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
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
67 changes: 67 additions & 0 deletions
67
spec/03-plugins/27-request-termination/03-integration_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,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) |