]> cat aescling's git repositories - mastodon.git/commitdiff
Fix error caused by missing subject in Webfinger response (#18204)
authorEugen Rochko <eugen@zeonfederated.com>
Sat, 30 Apr 2022 22:37:46 +0000 (00:37 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Thu, 5 May 2022 17:49:13 +0000 (13:49 -0400)
app/lib/webfinger.rb

index 1ffb5b4bf37ceff4f9110e6d675618d26b4aea55..a681e0815faf83961015c5340afd28293b0b0688 100644 (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