Skip to content

Commit

Permalink
cleanup of merge leftover files from refactor/cli branch (Kong#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske authored Jul 14, 2016
1 parent 2e22fce commit dd1e17e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 85 deletions.
84 changes: 84 additions & 0 deletions spec/03-plugins/response-transformer/02-body_transformer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,88 @@ describe("Plugin: response-transformer", function()
assert.falsy(body_transformer.is_json_body("application/x-www-form-urlencoded"))
end)
end)

describe("leave body alone", function()
-- Related to issue https://github.com/Mashape/kong/issues/1207
-- unit test to check body remains unaltered

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("body remains 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": "[email protected]",
"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 re-encode 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)
end)
85 changes: 0 additions & 85 deletions spec/plugins/response-transformer/skip_body_spec.lua

This file was deleted.

0 comments on commit dd1e17e

Please sign in to comment.