Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin) empty url sugar attribute, see #3448 #3452

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions kong/api/api_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,26 @@ end

function _M.resolve_url_params(self)
local sugar_url = self.args.post.url
if sugar_url then
local parsed_url = url.parse(sugar_url)
self.args.post.protocol = parsed_url.scheme
self.args.post.host = parsed_url.host
self.args.post.port = tonumber(parsed_url.port) or
parsed_url.port or
(parsed_url.scheme == "http" and 80) or
(parsed_url.scheme == "https" and 443) or
nil
self.args.post.path = parsed_url.path
self.args.post.url = nil

self.args.post.url = nil

if type(sugar_url) ~= "string" then
return
end

local parsed_url = url.parse(sugar_url)
if not parsed_url then
return
end

self.args.post.protocol = parsed_url.scheme
self.args.post.host = parsed_url.host
self.args.post.port = tonumber(parsed_url.port) or
parsed_url.port or
(parsed_url.scheme == "http" and 80) or
(parsed_url.scheme == "https" and 443) or
nil
self.args.post.path = parsed_url.path
end


Expand Down
24 changes: 24 additions & 0 deletions spec/02-integration/04-admin_api/21-services_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ for _, strategy in helpers.each_strategy() do
assert.equals(60000, json.read_timeout)
end
end)

it_content_types("client error with with empty url", function(content_type)
return function()
local res = client:post("/services", {
body = {
url = "",
},
headers = { ["Content-Type"] = content_type },
})
assert.res_status(400, res)
end
end)

it_content_types("client error with invalid url", function(content_type)
return function()
local res = client:post("/services", {
body = {
url = " ",
},
headers = { ["Content-Type"] = content_type },
})
assert.res_status(400, res)
end
end)
end)

describe("GET", function()
Expand Down