Skip to content

Commit adf5af6

Browse files
committed
apply suggestion
1 parent 0ea7647 commit adf5af6

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

t/plugin/openid-connect7.t

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ token validate successfully by jwks
337337
"openid-connect": {
338338
"client_id": "dummy",
339339
"client_secret": "dummy",
340-
"discovery": "http://127.0.0.1:8089/realms/University/.well-known/openid-configuration",
340+
"discovery": "http://127.0.0.1:8080/realms/University/.well-known/openid-configuration",
341341
"redirect_uri": "http://localhost:3000",
342342
"ssl_verify": false,
343343
"timeout": 10,
@@ -368,23 +368,6 @@ passed
368368
369369
370370
=== TEST 8: Obtain valid token and access route with it. Use valid_issuer from discovery endpoint.
371-
--- http_config
372-
server {
373-
listen 8089;
374-
375-
location /realms/University/.well-known/openid-configuration {
376-
content_by_lua_block {
377-
ngx.say([[
378-
{
379-
"issuer": "http://127.0.0.1:8089/realms/University",
380-
"jwks_uri": "http://127.0.0.1:8089/realms/University/protocol/openid-connect/certs",
381-
"response_types_supported": ["id_token"],
382-
"subject_types_supported": ["public"],
383-
"id_token_signing_alg_values_supported": ["RS256"]
384-
}]])
385-
}
386-
}
387-
}
388371
--- config
389372
location /t {
390373
content_by_lua_block {
@@ -407,20 +390,39 @@ passed
407390
return
408391
end
409392
393+
-- Check if response code was ok.
394+
if res.status == 200 then
395+
-- Get access token from JSON response body.
396+
local body = json_decode(res.body)
397+
local accessToken = body["access_token"]
410398
411-
-- Get access token from JSON response body.
412-
local body = json_decode(res.body)
413-
local accessToken = body["access_token"]
399+
-- Access route using access token. Should work.
400+
uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
401+
local res, err = httpc:request_uri(uri, {
402+
method = "GET",
403+
headers = {
404+
["Authorization"] = "Bearer " .. body["access_token"]
405+
}
406+
})
414407
415-
-- Access route using access token. Should work.
416-
uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
417-
local res, err = httpc:request_uri(uri, {
418-
method = "GET",
419-
headers = {
420-
["Authorization"] = "Bearer " .. body["access_token"]
421-
}
422-
})
408+
if res.status == 200 then
409+
-- Route accessed successfully.
410+
ngx.say(true)
411+
else
412+
-- Couldn't access route.
413+
ngx.say(false)
414+
end
415+
else
416+
-- Response from Keycloak not ok.
417+
ngx.say(false)
418+
end
423419
}
424420
}
421+
--- response_body
422+
true
423+
--- grep_error_log eval
424+
qr/token validate successfully by \w+/
425+
--- grep_error_log_out
426+
token validate successfully by jwks
425427
--- error_log
426-
valid_issuers not provided, using issuer from discovery doc: http://127.0.0.1:8089/realms/University
428+
valid_issuers not provided, using issuer from discovery doc: http://127.0.0.1:8080/realms/University

0 commit comments

Comments
 (0)