Skip to content

Commit

Permalink
Merge pull request Kong#319 from Mashape/chore/linting
Browse files Browse the repository at this point in the history
[chore] now lints tests

Former-commit-id: a77a212f20753bc42c9fc74027f2640311f23f4e
  • Loading branch information
thibaultcha committed Jun 9, 2015
2 parents 5668e42 + fbc1baf commit 666bea2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ install:

script:
- "busted -o spec/busted-print.lua --coverage spec/"
- "luacheck kong"
- "make lint"

after_success: "luacov-coveralls -i kong"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ drop:
@bin/kong db -c $(DEVELOPMENT_CONF) drop

lint:
@luacheck kong
@find kong spec -name '*.lua' ! -name 'invalid-module.lua' | xargs luacheck -q

test:
@busted spec/unit
Expand Down
1 change: 0 additions & 1 deletion spec/integration/proxy/database_cache_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local spec_helper = require "spec.spec_helpers"
local http_client = require "kong.tools.http_client"
local cache = require "kong.tools.database_cache"

local env = spec_helper.get_env()

Expand Down
16 changes: 8 additions & 8 deletions spec/plugins/request_size_limiting_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ describe("RequestSizeLimiting Plugin", function()

describe("With request size less than allowed limit", function()
it("should be allowed", function()
local response, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Length'] = "24", Expect = "100-continue", ['Content-Type'] = "application/x-www-form-urlencoded" } )
local _, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Length'] = "24", Expect = "100-continue", ['Content-Type'] = "application/x-www-form-urlencoded" } )
assert.are.equal(200, status)
end)
end)

describe("With request size greater than allowed limit", function()
it("should get blocked", function()
local response, status = http_client.post(STUB_POST_URL, {key = "This is a long test string"}, { host = "test3.com", ['Content-Length'] = "12000000", Expect = "100-continue", ['Content-Type'] = "application/x-www-form-urlencoded" } )
local _, status = http_client.post(STUB_POST_URL, {key = "This is a long test string"}, { host = "test3.com", ['Content-Length'] = "12000000", Expect = "100-continue", ['Content-Type'] = "application/x-www-form-urlencoded" } )
assert.are.equal(417, status)
end)
end)

describe("With request size greater than allowed limit but no expect header", function()
it("should get blocked", function()
local response, status = http_client.post(STUB_POST_URL, {key = "This is a long test string"}, { host = "test3.com", ['Content-Length'] = "12000000", ['Content-Type'] = "application/x-www-form-urlencoded" } )
local _, status = http_client.post(STUB_POST_URL, {key = "This is a long test string"}, { host = "test3.com", ['Content-Length'] = "12000000", ['Content-Type'] = "application/x-www-form-urlencoded" } )
assert.are.equal(413, status)
end)
end)

describe("With request size less than allowed limit but no expect header", function()
it("should be allowed", function()
local response, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Length'] = "24", ['Content-Type'] = "application/x-www-form-urlencoded" } )
local _, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Length'] = "24", ['Content-Type'] = "application/x-www-form-urlencoded" } )
assert.are.equal(200, status)
end)
end)

describe("With no content-length header post request", function()
it("should be allowed", function()
local response, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Type'] = "application/x-www-form-urlencoded" } )
local _, status = http_client.post(STUB_POST_URL, {key = "This is a test string"}, { host = "test3.com", ['Content-Type'] = "application/x-www-form-urlencoded" } )
assert.are.equal(200, status)
end)
end)

describe("With no content-length header get request", function()
it("should be allowed", function()
local response, status = http_client.get(STUB_POST_URL, {}, { host = "test3.com" } )
local _, status = http_client.get(STUB_POST_URL, {}, { host = "test3.com" } )
assert.are.equal(200, status)
end)
end)
Expand Down
19 changes: 9 additions & 10 deletions spec/plugins/response_transformer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local cjson = require "cjson"

local STUB_GET_URL = spec_helper.PROXY_URL.."/get"
local STUB_HEADERS_URL = spec_helper.PROXY_URL.."/response-headers"
local STUB_POST_URL = spec_helper.PROXY_URL.."/post"

describe("Response Transformer Plugin #proxy", function()

Expand Down Expand Up @@ -50,51 +49,51 @@ describe("Response Transformer Plugin #proxy", function()
end)

describe("Test adding parameters", function()

it("should add new headers", function()
local body, status, headers = http_client.get(STUB_GET_URL, {}, {host = "response.com"})
local _, status, headers = http_client.get(STUB_GET_URL, {}, {host = "response.com"})
assert.are.equal(200, status)
assert.are.equal("true", headers["x-added"])
assert.are.equal("true", headers["x-added2"])
end)

it("should add new parameters on GET", function()
local response, status, headers = http_client.get("http://127.0.0.1:8100/get", {}, {host = "response.com"})
local response, status = http_client.get("http://127.0.0.1:8100/get", {}, {host = "response.com"})
assert.are.equal(200, status)
local body = cjson.decode(response)
assert.are.equal("newvalue", body["newjsonparam"])
end)

it("should add new parameters on POST", function()
local response, status, headers = http_client.post("http://127.0.0.1:8100/post", {}, {host = "response.com"})
local response, status = http_client.post("http://127.0.0.1:8100/post", {}, {host = "response.com"})
assert.are.equal(200, status)
local body = cjson.decode(response)
assert.are.equal("newvalue", body["newjsonparam"])
end)

it("should add new headers", function()
local body, status, headers = http_client.get(STUB_GET_URL, {}, {host = "response2.com"})
local _, status, headers = http_client.get(STUB_GET_URL, {}, {host = "response2.com"})
assert.are.equal(200, status)
assert.are.equal("max-age=86400", headers["cache-control"])
end)

end)

describe("Test removing parameters", function()

it("should remove a header", function()
local _, status, headers = http_client.get(STUB_HEADERS_URL, { ["x-to-remove"] = "true"}, {host = "response.com"})
assert.are.equal(200, status)
assert.falsy(headers["x-to-remove"])
end)

it("should remove a parameter on GET", function()
local response, status, headers = http_client.get("http://127.0.0.1:8100/get", {}, {host = "response.com"})
local response, status = http_client.get("http://127.0.0.1:8100/get", {}, {host = "response.com"})
assert.are.equal(200, status)
local body = cjson.decode(response)
assert.falsy(body.origin)
end)

end)

end)

0 comments on commit 666bea2

Please sign in to comment.