about summary refs log tree commit diff
path: root/app/lib/webfinger.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-05-01 18:24:42 +0200
committerGitHub <noreply@github.com>2022-05-01 18:24:42 +0200
commita41b3d0457451abf750ecd2e5576e4d516d8ab95 (patch)
tree9e2238c87c72ef0bdca8159e4beb886553cd8755 /app/lib/webfinger.rb
parent252deefe3433d0cedafd973becd0d85b5182eb49 (diff)
parent26a51291c74e7f27bf5e97bec9cd415d7ed48246 (diff)
Merge pull request #1760 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/lib/webfinger.rb')
-rw-r--r--app/lib/webfinger.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb
index 1ffb5b4bf..a681e0815 100644
--- a/app/lib/webfinger.rb
+++ b/app/lib/webfinger.rb
@@ -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