Handle l param missing for WKD request
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Râu Cao 2025-05-18 14:37:22 +04:00
parent c43e43d89c
commit ebbd87368c
Signed by: raucao
GPG Key ID: 37036C356E56CC51
2 changed files with 10 additions and 2 deletions

View File

@ -1,9 +1,10 @@
class WebKeyDirectoryController < WellKnownController class WebKeyDirectoryController < WellKnownController
before_action :allow_cross_origin_requests before_action :allow_cross_origin_requests
# /.well-known/openpgpkey/hu/:hashed_username(.txt) # /.well-known/openpgpkey/hu/:hashed_username(.txt)?l=username
def show def show
@user = User.find_by(cn: params[:l].downcase) username = params[:l] || ""
@user = User.find_by(cn: username.downcase)
if @user.nil? || if @user.nil? ||
@user.pgp_pubkey.blank? || @user.pgp_pubkey.blank? ||

View File

@ -9,6 +9,13 @@ RSpec.describe "OpenPGP Web Key Directory", type: :request do
end end
end end
describe "omitted 'l' param" do
it "returns a 404 status" do
get "/.well-known/openpgpkey/hu/fmb8gw3n4zdj4xpwaziki4mwcxr1368i"
expect(response).to have_http_status(:not_found)
end
end
describe "non-existent user" do describe "non-existent user" do
it "returns a 404 status" do it "returns a 404 status" do
get "/.well-known/openpgpkey/hu/fmb8gw3n4zdj4xpwaziki4mwcxr1368i?l=aristotle" get "/.well-known/openpgpkey/hu/fmb8gw3n4zdj4xpwaziki4mwcxr1368i?l=aristotle"