-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup of merge leftover files from refactor/cli branch (Kong#1398)
- Loading branch information
Showing
2 changed files
with
84 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) |
This file was deleted.
Oops, something went wrong.