Skip to content

Commit

Permalink
Fix issues based on review comments by @thibault
Browse files Browse the repository at this point in the history
  • Loading branch information
bungle committed Mar 27, 2017
1 parent f62edfd commit f4c607c
Showing 1 changed file with 55 additions and 53 deletions.
108 changes: 55 additions & 53 deletions spec/02-integration/05-proxy/10-server_tokens_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ local function start(config)
helpers.dao.apis:insert {
name = "api-1",
upstream_url = "http://localhost:9999/headers-inspect",
hosts = "inexistent.com",
hosts = {
"header-inspect.com",
}
}

config = config or {}
Expand Down Expand Up @@ -42,32 +44,32 @@ describe("Server Tokens", function()

teardown(helpers.stop_kong)

it("should return Kong 'Via' header but not change the 'Server' header", function()
it("should return Kong 'Via' header but not change the 'Server' header when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com",
}
})

assert.response(res).has.status(200)
assert.res_status(200, res)
assert.not_equal(default_server_header, res.headers["server"])
assert.equal(default_server_header, res.headers["via"])
end)

it("should return Kong 'Server' header but not the Kong 'Via' header", function()
it("should return Kong 'Server' header but not the Kong 'Via' header when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header "via"
assert.res_status(404, res)
assert.equal(default_server_header, res.headers["server"])
assert.equal(nil, res.headers["via"])
end)

end)
Expand All @@ -81,32 +83,32 @@ describe("Server Tokens", function()

teardown(helpers.stop_kong)

it("should return Kong 'Via' header but not change the 'Server' header", function()
it("should return Kong 'Via' header but not change the 'Server' header when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com",
}
})

assert.response(res).has.status(200)
assert.res_status(200, res)
assert.not_equal(default_server_header, res.headers["server"])
assert.equal(default_server_header, res.headers["via"])
end)

it("should return Kong 'Server' header but not the Kong 'Via' header", function()
it("should return Kong 'Server' header but not the Kong 'Via' header when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header "via"
assert.res_status(404, res)
assert.equal(default_server_header, res.headers["server"])
assert.equal(nil, res.headers["via"])

This comment has been minimized.

Copy link
@thibaultcha

thibaultcha Mar 27, 2017

Member

assert.is_nil works too, but this is definitely good enough :)

end)

end)
Expand All @@ -120,33 +122,33 @@ describe("Server Tokens", function()

teardown(helpers.stop_kong)

it("should not return Kong 'Via' header but it should forward the 'Server' header", function()
it("should not return Kong 'Via' header but it should forward the 'Server' header when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com",
}
})

assert.response(res).has.status(200)
assert.res_status(200, res)
assert.response(res).has.header "server"
assert.response(res).has_not.header "via"
assert.not_equal(default_server_header, res.headers["server"])
end)

it("should not return Kong 'Server' or 'Via' headers", function()
it("should not return Kong 'Server' or 'Via' headers when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header "server"
assert.response(res).has_not.header "via"
assert.res_status(404, res)
assert.equal(nil, res.headers["server"])
assert.equal(nil, res.headers["via"])
end)

end)
Expand Down Expand Up @@ -174,32 +176,32 @@ describe("Latency Tokens", function()

teardown(helpers.stop_kong)

it("should be returned", function()
it("should be returned when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com",
}
})

assert.response(res).has.status(200)
assert.response(res).has.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(200, res)
assert.not_equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.not_equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

it("should not be returned", function()
it("should not be returned when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has_not.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(404, res)
assert.equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

end)
Expand All @@ -213,32 +215,32 @@ describe("Latency Tokens", function()

teardown(helpers.stop_kong)

it("should be returned", function()
it("should be returned when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com"
}
})

assert.response(res).has.status(200)
assert.response(res).has.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(200, res)
assert.not_equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.not_equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

it("should not be returned", function()
it("should not be returned when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has_not.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(404, res)
assert.equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

end)
Expand All @@ -254,32 +256,32 @@ describe("Latency Tokens", function()
helpers.stop_kong()
end)

it("should not be returned", function()
it("should not be returned when request was proxied", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "inexistent.com"
host = "header-inspect.com",
}
})

assert.response(res).has.status(200)
assert.response(res).has_not.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has_not.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(200, res)
assert.equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

it("should not be returned", function()
it("should not be returned when no API matched (no proxy)", function()
local res = assert(client:send {
method = "GET",
path = "/get",
headers = {
host = "404.com"
host = "404.com",
}
})

assert.response(res).has.status(404)
assert.response(res).has_not.header(constants.HEADERS.UPSTREAM_LATENCY)
assert.response(res).has_not.header(constants.HEADERS.PROXY_LATENCY)
assert.res_status(404, res)
assert.equal(nil, res.headers[constants.HEADERS.UPSTREAM_LATENCY])
assert.equal(nil, res.headers[constants.HEADERS.PROXY_LATENCY])
end)

end)
Expand Down

0 comments on commit f4c607c

Please sign in to comment.