Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: authz_keycloak plugin giving 500 error #10763

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/plugins/authz-keycloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ local function authz_keycloak_resolve_resource(conf, uri, sa_access_token)
if not resource_registration_endpoint then
local err = "Unable to determine registration endpoint."
log.error(err)
return 503, err
return nil, err
end

log.debug("Resource registration endpoint: ", resource_registration_endpoint)
Expand Down
87 changes: 87 additions & 0 deletions t/plugin/authz-keycloak2.t
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,90 @@ true
GET /t
--- response_body
true



=== TEST 16: add plugin with lazy_load_paths when resource_registration_endpoint is neither in config nor in the discovery doc
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"authz-keycloak": {
"discovery": "http://127.0.0.1:8080/realms/University/.well-known/openid-configuration",
"client_id": "course_management",
"client_secret": "d1ec69e9-55d2-4109-a3ea-befa071579d5",
"lazy_load_paths": true
}
},
"upstream": {
"nodes": {
"127.0.0.1:1982": 1
},
"type": "roundrobin"
},
"uri": "/course/foo"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed



=== TEST 17: Get access token for student and access view course route.
--- config
location /t {
content_by_lua_block {
local json_decode = require("toolkit.json").decode
local http = require "resty.http"
local httpc = http.new()
local uri = "http://127.0.0.1:8080/realms/University/protocol/openid-connect/token"
local res, err = httpc:request_uri(uri, {
method = "POST",
body = "grant_type=password&client_id=course_management&client_secret=d1ec69e9-55d2-4109-a3ea-befa071579d5&username=student@gmail.com&password=123456",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded"
}
})

if res.status == 200 then
local body = json_decode(res.body)
local accessToken = body["access_token"]


uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/course/foo"
local res, err = httpc:request_uri(uri, {
method = "GET",
headers = {
["Authorization"] = "Bearer " .. accessToken,
}
})

if res.status == 503 then
ngx.say(true)
else
ngx.say(res.status)
end
else
ngx.say(false)
end
}
}
--- request
GET /t
--- response_body
true
--- error_log
Unable to determine registration endpoint.
lakshya8066 marked this conversation as resolved.
Show resolved Hide resolved
Loading