Fix error caused by missing subject in Webfinger response (#18204)

pull/18248/head
Eugen Rochko 2022-05-01 00:37:46 +02:00 committed by GitHub
parent ad084ce7db
commit 6da648227e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -6,8 +6,13 @@ class Webfinger
class RedirectError < StandardError; end
class Response
def initialize(body)
attr_reader :uri
def initialize(uri, body)
@uri = uri
@json = Oj.load(body, mode: :strict)
validate_response!
end
def subject
@ -23,6 +28,10 @@ class Webfinger
def links
@links ||= @json['links'].index_by { |link| link['rel'] }
end
def validate_response!
raise Webfinger::Error, "Missing subject in response for #{@uri}" if subject.blank?
end
end
def initialize(uri)
@ -34,7 +43,7 @@ class Webfinger
end
def perform
Response.new(body_from_webfinger)
Response.new(@uri, body_from_webfinger)
rescue Oj::ParseError
raise Webfinger::Error, "Invalid JSON in response for #{@uri}"
rescue Addressable::URI::InvalidURIError