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