Skip to content

Commit

Permalink
Merge pull request Kong#482 from Mashape/fix/plugins-route
Browse files Browse the repository at this point in the history
[fix/api] disabling route path with plugin name

Former-commit-id: eddca3d39899fc86e6b56e5b29b962838ca72067
  • Loading branch information
thibaultcha committed Aug 18, 2015
2 parents e8de5d5 + 1480781 commit e873fe4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions kong/api/routes/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ return {
end
},

["/apis/:name_or_id/plugins/:plugin_name_or_id"] = {
["/apis/:name_or_id/plugins/:plugin_id"] = {
before = function(self, dao_factory, helpers)
crud.find_api_by_name_or_id(self, dao_factory, helpers)
self.params.api_id = self.api.id

local fetch_keys = {
api_id = self.api.id,
[validations.is_valid_uuid(self.params.plugin_name_or_id) and "id" or "name"] = self.params.plugin_name_or_id
id = self.params.plugin_id
}
self.params.plugin_name_or_id = nil
self.params.plugin_id = nil

local data, err = dao_factory.plugins_configurations:find_by_keys(fetch_keys)
if err then
Expand Down
17 changes: 5 additions & 12 deletions spec/integration/admin_api/apis_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,6 @@ describe("Admin API", function()
assert.same(plugin, body)
end)

it("should retrieve by name", function()
local response, status = http_client.get(BASE_URL..plugin.name)
assert.equal(200, status)
local body = json.decode(response)
assert.same(plugin, body)
end)

end)

describe("PATCH", function()
Expand All @@ -362,26 +355,26 @@ describe("Admin API", function()
local body = json.decode(response)
assert.same("key_updated", body.value.key_names[1])

response, status = http_client.patch(BASE_URL..plugin.name, {["value.key_names"]={"key_updated-json"}}, {["content-type"]="application/json"})
response, status = http_client.patch(BASE_URL..plugin.id, {["value.key_names"]={"key_updated-json"}}, {["content-type"]="application/json"})
assert.equal(200, status)
body = json.decode(response)
assert.same("key_updated-json", body.value.key_names[1])
end)

it("[FAILURE] should return proper errors", function()
local _, status = http_client.patch(BASE_URL.."hello", {})
local _, status = http_client.patch(BASE_URL.."b6cca0aa-4537-11e5-af97-23a06d98af51", {})
assert.equal(404, status)
end)

it("should not override a plugin's `value` if partial", function()
-- This is delicate since a plugin's `value` is a text field in a DB like Cassandra
local _, status = http_client.patch(BASE_URL..plugin.name, {
local _, status = http_client.patch(BASE_URL..plugin.id, {
["value.key_names"] = {"key_set_null_test"},
["value.hide_credentials"] = true
})
assert.equal(200, status)

local response, status = http_client.patch(BASE_URL..plugin.name, {
local response, status = http_client.patch(BASE_URL..plugin.id, {
["value.key_names"] = {"key_set_null_test_updated"}
})
assert.equal(200, status)
Expand All @@ -395,7 +388,7 @@ describe("Admin API", function()
describe("DELETE", function()

it("[FAILURE] should return proper errors", function()
local _, status = http_client.delete(BASE_URL.."hello")
local _, status = http_client.delete(BASE_URL.."b6cca0aa-4537-11e5-af97-23a06d98af51")
assert.equal(404, status)
end)

Expand Down

0 comments on commit e873fe4

Please sign in to comment.