Skip to content

Commit

Permalink
added testcase for issue #1207
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 30, 2016
1 parent a34f6ce commit 4797e81
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions spec/plugins/response-transformer/skip_body_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
-- Related to issue https://github.com/Mashape/kong/issues/1207
-- unit test to check body remains unaltered
describe("response-transformer body-check", function()

local old_ngx, handler

setup(function()
old_ngx = ngx
_G.ngx = { -- busted requires explicit _G to access the global environment
log = function() end,
header = {
["content-type"] = "application/json",
},
arg = {},
ctx = {
buffer = "",
},
}
handler = require("kong.plugins.response-transformer.handler")
handler:new()
end)

teardown(function()
ngx = old_ngx
end)

it("check the body to remain unaltered if no transforms have been set", function()
-- only a header transform, no body changes
local conf = {
remove = {
headers = {"h1", "h2", "h3"},
json = {}
},
add = {
headers = {},
json = {},
},
append = {
headers = {},
json = {},
},
replace = {
headers = {},
json = {},
},
}
local body = [[
{
"id": 1,
"name": "Some One",
"username": "Bretchen",
"email": "Not@here.com",
"address": {
"street": "Down Town street",
"suite": "Apt. 23",
"city": "Gwendoline"
},
"phone": "1-783-729-8531 x56442",
"website": "hardwork.org",
"company": {
"name": "BestBuy",
"catchPhrase": "just a bunch of words",
"bs": "bullshit words"
}
}
]]

ngx.arg[1] = body
handler:body_filter(conf)
local result = ngx.arg[1]
ngx.arg[1] = ""
ngx.arg[2] = true -- end of body marker
handler:body_filter(conf)
result = result .. ngx.arg[1]

-- body filter should not execute, it would parse and reencode the json, removing
-- the whitespace. So check equality to make sure whitespace is still there, and hence
-- body was not touched.
assert.are.same(body, result)

end)

end)

0 comments on commit 4797e81

Please sign in to comment.