Skip to content

Commit

Permalink
hotfix(resolver) avoid URL decoding in URI proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Nov 6, 2015
1 parent c72c8b0 commit 5164bc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kong/resolver/access.lua
Expand Up @@ -194,7 +194,8 @@ local function find_api(uri)
end

function _M.execute(conf)
local uri = ngx.var.uri
local uri = stringy.split(ngx.var.request_uri, "?")[1]

local err, api, hosts, strip_request_path_pattern = find_api(uri)
if err then
return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
Expand Down
20 changes: 19 additions & 1 deletion spec/integration/proxy/api_resolver_spec.lua
Expand Up @@ -36,7 +36,8 @@ describe("Resolver", function()
{name = "tests-wildcard-subdomain", upstream_url = "http://mockbin.com/status/200", request_host = "*.wildcard.com"},
{name = "tests-wildcard-subdomain-2", upstream_url = "http://mockbin.com/status/201", request_host = "wildcard.*"},
{name = "tests-preserve-host", request_host = "httpbin-nopreserve.com", upstream_url = "http://httpbin.org"},
{name = "tests-preserve-host-2", request_host = "httpbin-preserve.com", upstream_url = "http://httpbin.org", preserve_host = true}
{name = "tests-preserve-host-2", request_host = "httpbin-preserve.com", upstream_url = "http://httpbin.org", preserve_host = true},
{name = "tests-uri", request_host = "mockbin-uri.com", upstream_url = "http://mockbin.org"}
},
plugin = {
{name = "key-auth", config = {key_names = {"apikey"} }, __api = 2}
Expand All @@ -50,6 +51,22 @@ describe("Resolver", function()
spec_helper.stop_kong()
end)

describe("Test URI", function()

it("should URL decode the URI with querystring", function()
local response, status = http_client.get(spec_helper.STUB_GET_URL.."/hello%2F", { hello = "world"}, {host = "mockbin-uri.com"})
assert.equal(200, status)
assert.equal("http://mockbin.org/request/hello%2f?hello=world", cjson.decode(response).url)
end)

it("should URL decode the URI without querystring", function()
local response, status = http_client.get(spec_helper.STUB_GET_URL.."/hello%2F", nil, {host = "mockbin-uri.com"})
assert.equal(200, status)
assert.equal("http://mockbin.org/request/hello%2f", cjson.decode(response).url)
end)

end)

describe("Inexistent API", function()

it("should return Not Found when the API is not in Kong", function()
Expand Down Expand Up @@ -216,4 +233,5 @@ describe("Resolver", function()
assert.equal("httpbin-preserve.com", parsed_response.headers["Host"])
end)
end)

end)

0 comments on commit 5164bc4

Please sign in to comment.