Skip to content

Commit eb8510c

Browse files
committed
test for pass_cookies option
1 parent bdc1a0e commit eb8510c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tests/spec/introspection_spec.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ describe("when the introspection endpoint is invoked", function()
3636
it("the request contains the token parameter", function()
3737
assert_introspection_endpoint_call_contains("token=" .. jwt:gsub("%-", "%%%-"))
3838
end)
39+
it("no cookies are sent with the introspecion request", function()
40+
assert.error_log_contains("no cookie in introspecion call")
41+
end)
3942
it("the response is valid", function()
4043
assert.are.equals(200, status)
4144
end)
@@ -86,6 +89,59 @@ describe("when additional parameters have been configured", function()
8689
end)
8790
end)
8891

92+
describe("when cookies shall be sent with the introspection call", function()
93+
test_support.start_server({
94+
introspection_opts = {
95+
pass_cookies = "foo bar"
96+
}
97+
})
98+
teardown(test_support.stop_server)
99+
local jwt = test_support.trim(http.request("http://127.0.0.1/jwt"))
100+
describe("but no cookies are included in request", function()
101+
local _, status = http.request({
102+
url = "http://127.0.0.1/introspect",
103+
headers = {
104+
authorization = "Bearer " .. jwt,
105+
}
106+
})
107+
it("the response is valid", function()
108+
assert.are.equals(200, status)
109+
end)
110+
it("the request doesn't contain any cookies", function()
111+
assert.error_log_contains("no cookie in introspecion call")
112+
end)
113+
end)
114+
describe("a cookie is included in request", function()
115+
local _, status = http.request({
116+
url = "http://127.0.0.1/introspect",
117+
headers = {
118+
authorization = "Bearer " .. jwt,
119+
cookie = "foo=x; baz=y"
120+
}
121+
})
122+
it("the response is valid", function()
123+
assert.are.equals(200, status)
124+
end)
125+
it("the request contains the cookie", function()
126+
assert.error_log_contains("cookie foo=x in introspecion call")
127+
end)
128+
end)
129+
describe("multiple cookie headers are included in request", function()
130+
-- the http module doesn't support specifying multiple headers
131+
local r = io.popen("curl -H 'Authorization: Bearer " .. jwt .. "' -H 'Cookie: foo=x'"
132+
.. " -H 'Cookie: baz=y'"
133+
.. " -o /dev/null -v --max-redirs 0 http://127.0.0.1/introspect 2>&1")
134+
local o = r:read("*a")
135+
r:close()
136+
it("the response is valid", function()
137+
assert.truthy(string.match(string.lower(o), ".*http/.* 200"))
138+
end)
139+
it("the request contains the cookie", function()
140+
assert.error_log_contains("cookie foo=x in introspecion call")
141+
end)
142+
end)
143+
end)
144+
89145
describe("when the response is inactive", function()
90146
test_support.start_server({
91147
introspection_response = {

tests/spec/test_support.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ JWT_VERIFY_SECRET]=]
276276
ngx.log(ngx.ERR, "Received introspection request: " .. ngx.req.get_body_data())
277277
local auth = ngx.req.get_headers()["Authorization"]
278278
ngx.log(ngx.ERR, "introspection authorization header: " .. (auth and auth or ""))
279+
local cookie = ngx.req.get_headers()["Cookie"]
280+
if cookie then
281+
if type(cookie) == "string" then
282+
cookie = { cookie }
283+
end
284+
for _, c in ipairs(cookie) do
285+
ngx.log(ngx.ERR, "cookie " .. c .. " in introspecion call")
286+
end
287+
else
288+
ngx.log(ngx.ERR, "no cookie in introspecion call")
289+
end
279290
ngx.header.content_type = 'application/json;charset=UTF-8'
280291
delay(INTROSPECTION_DELAY_RESPONSE)
281292
ngx.say(cjson.encode(INTROSPECTION_RESPONSE))

0 commit comments

Comments
 (0)