Skip to content

Commit 02bbadc

Browse files
committed
addressing comments
1 parent d128dc9 commit 02bbadc

4 files changed

Lines changed: 69 additions & 2 deletions

File tree

lua-resty-openidc-1.9.0-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ description = {
2424
dependencies = {
2525
"lua >= 5.1",
2626
"lua-resty-http >= 0.08",
27-
"lua-resty-session >= 4.2.0",
27+
"lua-resty-session = 4.2.0",
2828
"lua-resty-jwt >= 0.2.0",
2929
"lua-resty-openssl >= 1.8.0"
3030
}

tests/spec/access_token_access_spec.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ describe("if there is an active non-expired login", function()
3939
end)
4040
end)
4141

42+
describe("if revocation_fail_mode is closed and the revocation store read fails", function()
43+
test_support.start_server({
44+
revocation_test = {
45+
fail_mode = "closed",
46+
get_fails_after = 1,
47+
},
48+
})
49+
teardown(test_support.stop_server)
50+
51+
local _, _, cookies = test_support.login()
52+
local content_table = {}
53+
local _, status = http.request({
54+
url = "http://localhost/access_token",
55+
redirect = false,
56+
headers = { cookie = cookies },
57+
sink = ltn12.sink.table(content_table)
58+
})
59+
local body = table.concat(content_table)
60+
61+
it("returns the session start failure", function()
62+
assert.are.equals(401, status)
63+
assert.truthy(string.find(body, "unable to check session revocation", 1, true))
64+
end)
65+
66+
it("does not return the access token", function()
67+
assert.is_nil(string.find(body, "a_token", 1, true))
68+
end)
69+
end)
70+
4271
describe("if there is an active non-expired login but access token is not stored in session", function()
4372
test_support.start_server({
4473
access_token_opts = {

tests/spec/logout_revocation_spec.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@ local ltn12 = require("ltn12")
33
local test_support = require("test_support")
44
require 'busted.runner'()
55

6+
describe("when revocation_fail_mode is closed and the revocation store read fails", function()
7+
test_support.start_server({
8+
revocation_test = {
9+
fail_mode = "closed",
10+
get_fails_after = 1,
11+
},
12+
})
13+
teardown(test_support.stop_server)
14+
15+
local _, _, cookie = test_support.login()
16+
17+
local response_body = {}
18+
local _, status = http.request({
19+
url = "http://127.0.0.1/default/t",
20+
headers = { cookie = cookie },
21+
redirect = false,
22+
sink = ltn12.sink.table(response_body),
23+
})
24+
local body = table.concat(response_body)
25+
26+
it("propagates the session start failure", function()
27+
assert.are.equals(401, status)
28+
assert.truthy(string.find(body, "unable to check session revocation", 1, true))
29+
end)
30+
31+
it("does not authenticate the request", function()
32+
assert.is_nil(string.find(body, "hello, world!", 1, true))
33+
end)
34+
end)
35+
636
describe("when revocation_fail_mode is closed and the revocation store is unreachable during logout", function()
737
test_support.start_server({
838
revocation_test = {

tests/spec/test_support.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ local DEFAULT_DELAY_RESPONSE = "0"
9898
local DEFAULT_REVOCATION_TEST_ENABLED = "false"
9999
local DEFAULT_REVOCATION_FAIL_MODE = '"closed"'
100100
local DEFAULT_REVOCATION_SET_FAILS = "false"
101+
local DEFAULT_REVOCATION_GET_FAILS_AFTER = "nil"
101102

102103
local DEFAULT_INIT_TEMPLATE = [[
103104
local test_globals = {}
@@ -165,6 +166,10 @@ if REVOCATION_TEST_ENABLED then
165166
return true
166167
end,
167168
get = function(_, key)
169+
local calls = revoked:incr("get_calls", 1, 0)
170+
if REVOCATION_GET_FAILS_AFTER and calls > REVOCATION_GET_FAILS_AFTER then
171+
return nil, "connection refused"
172+
end
168173
return revoked:get(key)
169174
end,
170175
},
@@ -539,10 +544,11 @@ http {
539544
540545
location /access_token {
541546
content_by_lua_block {
542-
local access_token, err = test_globals.oidc.access_token(ACCESS_TOKEN_OPTS)
547+
local access_token, err = test_globals.oidc.access_token(ACCESS_TOKEN_OPTS, test_globals.session_opts)
543548
if not access_token then
544549
ngx.status = 401
545550
ngx.log(ngx.ERR, "access_token error: " .. (err or 'no message'))
551+
ngx.say("access_token failed: " .. (err or 'no message'))
546552
else
547553
ngx.header.content_type = 'text/plain'
548554
ngx.say(access_token)
@@ -684,6 +690,8 @@ local function write_template(out, template, custom_config)
684690
('"' .. (custom_config["revocation_test"].fail_mode or "closed") .. '"') or DEFAULT_REVOCATION_FAIL_MODE)
685691
:gsub("REVOCATION_SET_FAILS", custom_config["revocation_test"] and
686692
(custom_config["revocation_test"].set_fails and "true" or "false") or DEFAULT_REVOCATION_SET_FAILS)
693+
:gsub("REVOCATION_GET_FAILS_AFTER", custom_config["revocation_test"] and
694+
tostring(custom_config["revocation_test"].get_fails_after) or DEFAULT_REVOCATION_GET_FAILS_AFTER)
687695
out:write(content)
688696
end
689697

0 commit comments

Comments
 (0)