From b6d64ba5252216d367d8c89f50492885d364f76c Mon Sep 17 00:00:00 2001 From: Stanislaw Klajn Date: Fri, 20 Oct 2023 11:05:16 +0100 Subject: [PATCH] Removed now obsolete SecretKeyFinder --- lib/devise.rb | 1 - lib/devise/rails.rb | 2 +- lib/devise/secret_key_finder.rb | 27 ------- test/secret_key_finder_test.rb | 121 -------------------------------- 4 files changed, 1 insertion(+), 150 deletions(-) delete mode 100644 lib/devise/secret_key_finder.rb delete mode 100644 test/secret_key_finder_test.rb diff --git a/lib/devise.rb b/lib/devise.rb index 3847e190c6..2b8ac66ef3 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -19,7 +19,6 @@ module Devise autoload :TestHelpers, 'devise/test_helpers' autoload :TimeInflector, 'devise/time_inflector' autoload :TokenGenerator, 'devise/token_generator' - autoload :SecretKeyFinder, 'devise/secret_key_finder' module Controllers autoload :Helpers, 'devise/controllers/helpers' diff --git a/lib/devise/rails.rb b/lib/devise/rails.rb index ab308e979d..dad9e86dc9 100644 --- a/lib/devise/rails.rb +++ b/lib/devise/rails.rb @@ -38,7 +38,7 @@ class Engine < ::Rails::Engine end initializer "devise.secret_key" do |app| - Devise.secret_key ||= Devise::SecretKeyFinder.new(app).find + Devise.secret_key ||= app.secret_key_base Devise.token_generator ||= if secret_key = Devise.secret_key diff --git a/lib/devise/secret_key_finder.rb b/lib/devise/secret_key_finder.rb deleted file mode 100644 index d07106c44b..0000000000 --- a/lib/devise/secret_key_finder.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Devise - class SecretKeyFinder - def initialize(application) - @application = application - end - - def find - if @application.respond_to?(:credentials) && key_exists?(@application.credentials) - @application.credentials.secret_key_base - elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets) - @application.secrets.secret_key_base - elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config) - @application.config.secret_key_base - elsif @application.respond_to?(:secret_key_base) && key_exists?(@application) - @application.secret_key_base - end - end - - private - - def key_exists?(object) - object.secret_key_base.present? - end - end -end diff --git a/test/secret_key_finder_test.rb b/test/secret_key_finder_test.rb deleted file mode 100644 index 434dbc8d12..0000000000 --- a/test/secret_key_finder_test.rb +++ /dev/null @@ -1,121 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class Rails52Credentials - def credentials - OpenStruct.new(secret_key_base: 'credentials') - end -end - -class Rails52Secrets - def credentials - OpenStruct.new(secret_key_base: nil) - end - - def secrets - OpenStruct.new(secret_key_base: 'secrets') - end -end - -class Rails52Config - def credentials - OpenStruct.new(secret_key_base: nil) - end - - def secrets - OpenStruct.new(secret_key_base: nil) - end - - def config - OpenStruct.new(secret_key_base: 'config') - end -end - -class Rails52SecretKeyBase - def credentials - OpenStruct.new(secret_key_base: nil) - end - - def secrets - OpenStruct.new(secret_key_base: nil) - end - - def config - OpenStruct.new(secret_key_base: nil) - end - - def secret_key_base - 'secret_key_base' - end -end - -class Rails41Secrets - def secrets - OpenStruct.new(secret_key_base: 'secrets') - end - - def config - OpenStruct.new(secret_key_base: nil) - end -end - -class Rails41Config - def secrets - OpenStruct.new(secret_key_base: nil) - end - - def config - OpenStruct.new(secret_key_base: 'config') - end -end - -class Rails40Config - def config - OpenStruct.new(secret_key_base: 'config') - end -end - -class SecretKeyFinderTest < ActiveSupport::TestCase - test "rails 5.2 uses credentials when they're available" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails52Credentials.new) - - assert_equal 'credentials', secret_key_finder.find - end - - test "rails 5.2 uses secrets when credentials are empty" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails52Secrets.new) - - assert_equal 'secrets', secret_key_finder.find - end - - test "rails 5.2 uses config when secrets are empty" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails52Config.new) - - assert_equal 'config', secret_key_finder.find - end - - test "rails 5.2 uses secret_key_base when config is empty" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails52SecretKeyBase.new) - - assert_equal 'secret_key_base', secret_key_finder.find - end - - test "rails 4.1 uses secrets" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new) - - assert_equal 'secrets', secret_key_finder.find - end - - test "rails 4.1 uses config when secrets are empty" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails41Config.new) - - assert_equal 'config', secret_key_finder.find - end - - test "rails 4.0 uses config" do - secret_key_finder = Devise::SecretKeyFinder.new(Rails40Config.new) - - assert_equal 'config', secret_key_finder.find - end -end