Skip to content

Commit

Permalink
Closes #700
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Nov 9, 2015
1 parent b8c5db1 commit 68e75d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ nginx: |
server {
listen {{admin_api_port}};
client_max_body_size 10m;
client_body_buffer_size 10m;
location / {
default_type application/json;
content_by_lua '
Expand Down
36 changes: 35 additions & 1 deletion spec/integration/admin_api/kong_routes_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local json = require "cjson"
local http_client = require "kong.tools.http_client"
local spec_helper = require "spec.spec_helpers"
local IO = require "kong.tools.io"
local utils = require "kong.tools.utils"
local env = spec_helper.get_env() -- test environment
local dao_factory = env.dao_factory
Expand All @@ -15,7 +16,7 @@ describe("Admin API", function()
teardown(function()
spec_helper.stop_kong()
end)

describe("Kong routes", function()
describe("/", function()
local constants = require "kong.constants"
Expand Down Expand Up @@ -83,4 +84,37 @@ describe("Admin API", function()
assert.truthy(body.server.total_requests)
end)
end)

describe("Request size", function()
it("should properly hanlde big POST bodies < 10MB", function()
local response, status = http_client.post(spec_helper.API_URL.."/apis", { request_path = "hello.com", upstream_url = "http://mockbin.org" })
assert.equal(201, status)
local api_id = json.decode(response).id
assert.truthy(api_id)


local big_value = string.rep("204.48.16.0,", 1000)
big_value = string.sub(big_value, 1, string.len(big_value) - 1)
assert.truthy(string.len(big_value) > 10000) -- More than 10kb

local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { name = "ip-restriction", ["config.blacklist"] = big_value})
assert.equal(201, status)
end)

it("should fail with requests > 10MB", function()
local response, status = http_client.post(spec_helper.API_URL.."/apis", { request_path = "hello2.com", upstream_url = "http://mockbin.org" })
assert.equal(201, status)
local api_id = json.decode(response).id
assert.truthy(api_id)

-- It should fail with more than 10MB
local big_value = string.rep("204.48.16.0,", 1024000)
big_value = string.sub(big_value, 1, string.len(big_value) - 1)
assert.truthy(string.len(big_value) > 10000000) -- More than 10kb

local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { name = "ip-restriction", ["config.blacklist"] = big_value})
assert.equal(413, status)
end)
end)

end)

0 comments on commit 68e75d4

Please sign in to comment.