Skip to content

Commit c24803a

Browse files
authored
test(openid-connect): stop logout tests from calling live IdPs (#13608)
1 parent 841dbea commit c24803a

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

t/lib/server.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,20 @@ function _M._well_known_openid_configuration()
496496
ngx.say(openid_data)
497497
end
498498

499+
-- Same discovery document but advertising an end_session_endpoint, so the
500+
-- openid-connect logout flow can be exercised without reaching a live provider.
501+
function _M._well_known_openid_configuration_with_end_session()
502+
local t = require("lib.test_admin")
503+
local openid_data = json_decode(t.read_file("t/plugin/openid-connect/configuration.json"))
504+
if not openid_data then
505+
ngx.status = 500
506+
ngx.say("failed to decode openid discovery fixture")
507+
return
508+
end
509+
openid_data.end_session_endpoint = "https://samples.auth0.com/v2/logout"
510+
ngx.say(json_encode(openid_data))
511+
end
512+
499513
function _M.google_logging_token()
500514
local args = ngx.req.get_uri_args()
501515
local args_token_type = args.token_type or "Bearer"

t/plugin/openid-connect.t

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,9 +1384,10 @@ x-userinfo: ey.*
13841384
"openid-connect": {
13851385
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
13861386
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
1387-
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
1387+
"discovery": "http://127.0.0.1:1980/.well-known/openid-configuration",
13881388
"redirect_uri": "https://iresty.com",
13891389
"post_logout_redirect_uri": "https://iresty.com",
1390+
"ssl_verify": false,
13901391
"scope": "openid profile",
13911392
"session": {
13921393
"secret": "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK"
@@ -1414,8 +1415,7 @@ passed
14141415
14151416
14161417
1417-
=== TEST 36: Check whether auth0 can redirect normally using post_logout_redirect_uri configuration
1418-
--- custom_trusted_cert: /etc/ssl/certs/ca-certificates.crt
1418+
=== TEST 36: Redirect to post_logout_redirect_uri when provider has no end_session_endpoint
14191419
--- config
14201420
location /t {
14211421
content_by_lua_block {
@@ -1424,9 +1424,9 @@ passed
14241424
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/logout"
14251425
local res, err = httpc:request_uri(uri, {method = "GET"})
14261426
ngx.status = res.status
1427-
local location = res.headers['Location']
1428-
if location and string.find(location, 'https://iresty.com') ~= -1 and
1429-
string.find(location, 'post_logout_redirect_uri=https://iresty.com') ~= -1 then
1427+
local location = ngx.unescape_uri(res.headers['Location'] or "")
1428+
if location:find('https://iresty.com', 1, true) and
1429+
location:find('post_logout_redirect_uri=https://iresty.com', 1, true) then
14301430
ngx.say(true)
14311431
end
14321432
}
@@ -1447,11 +1447,12 @@ true
14471447
ngx.HTTP_PUT,
14481448
[[{ "plugins": {
14491449
"openid-connect": {
1450-
"client_id": "942299072001-vhduu1uljmdhhbbp7g22m3qsmo246a75.apps.googleusercontent.com",
1451-
"client_secret": "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",
1452-
"discovery": "https://accounts.google.com/.well-known/openid-configuration",
1450+
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
1451+
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
1452+
"discovery": "http://127.0.0.1:1980/.well-known/openid-configuration-with-end-session",
14531453
"redirect_uri": "https://iresty.com",
14541454
"post_logout_redirect_uri": "https://iresty.com",
1455+
"ssl_verify": false,
14551456
"scope": "openid profile",
14561457
"session": {
14571458
"secret": "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK"
@@ -1479,8 +1480,7 @@ passed
14791480
14801481
14811482
1482-
=== TEST 38: Check whether google can redirect normally using post_logout_redirect_uri configuration
1483-
--- custom_trusted_cert: /etc/ssl/certs/ca-certificates.crt
1483+
=== TEST 38: Redirect to end_session_endpoint with post_logout_redirect_uri when provider exposes it
14841484
--- config
14851485
location /t {
14861486
content_by_lua_block {
@@ -1489,9 +1489,9 @@ passed
14891489
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/logout"
14901490
local res, err = httpc:request_uri(uri, {method = "GET"})
14911491
ngx.status = res.status
1492-
local location = res.headers['Location']
1493-
if location and string.find(location, 'https://iresty.com') ~= -1 and
1494-
string.find(location, 'post_logout_redirect_uri=https://iresty.com') ~= -1 then
1492+
local location = ngx.unescape_uri(res.headers['Location'] or "")
1493+
if location:find('https://samples.auth0.com/v2/logout', 1, true) and
1494+
location:find('post_logout_redirect_uri=https://iresty.com', 1, true) then
14951495
ngx.say(true)
14961496
end
14971497
}

0 commit comments

Comments
 (0)