about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-05-01 16:52:27 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-05-01 16:52:27 +0200
commit392ca0472a50ea930f46e22dccf5ce55b04ef588 (patch)
tree9f8c6b3dcb11a620a417205f9554e8d37e5f3e12 /app/lib
parent252deefe3433d0cedafd973becd0d85b5182eb49 (diff)
parent33f3818d660c67194f94c7ff2bb180f4865e6748 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `app/javascript/packs/admin.js`:
  Conflicts due to glitch-soc's theming system.
  Upstream changes have been ported to `app/javascript/core/admin.js`
- `app/models/trends/statuses.rb`:
  Minor conflict due to glitch-soc's option to allow CWed toots in trends.
  Ported upstream changes.
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/redis_configuration.rb7
-rw-r--r--app/lib/webfinger.rb13
2 files changed, 17 insertions, 3 deletions
diff --git a/app/lib/redis_configuration.rb b/app/lib/redis_configuration.rb
index fc8cf2f80..e14d6c8b6 100644
--- a/app/lib/redis_configuration.rb
+++ b/app/lib/redis_configuration.rb
@@ -2,12 +2,17 @@
 
 class RedisConfiguration
   class << self
+    def establish_pool(new_pool_size)
+      @pool&.shutdown(&:close)
+      @pool = ConnectionPool.new(size: new_pool_size) { new.connection }
+    end
+
     def with
       pool.with { |redis| yield redis }
     end
 
     def pool
-      @pool ||= ConnectionPool.new(size: pool_size) { new.connection }
+      @pool ||= establish_pool(pool_size)
     end
 
     def pool_size
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