diff --git a/lib/ahoy_email/engine.rb b/lib/ahoy_email/engine.rb index 33e3dd5..09032fa 100644 --- a/lib/ahoy_email/engine.rb +++ b/lib/ahoy_email/engine.rb @@ -2,8 +2,10 @@ module AhoyEmail class Engine < ::Rails::Engine - initializer "ahoy_email" do |app| - AhoyEmail.secret_token ||= app.key_generator.generate_key("ahoy_email") + initializer "ahoy_email", after: :load_config_initializers do |app| + app.config.after_initialize do + AhoyEmail.secret_token ||= app.key_generator.generate_key("ahoy_email") + end end end end diff --git a/test/click_test.rb b/test/click_test.rb index 3c26ca4..32e320c 100644 --- a/test/click_test.rb +++ b/test/click_test.rb @@ -47,7 +47,7 @@ def test_invalid_redirect_url end def test_consistent_signature - get AhoyEmail::Engine.routes.url_helpers.click_path(c: "test", s: "1xjjEyEbkRSohoe0RpWUYAeDNthXDDNdaKFtCJp5lyg", t: "123", u: "https://example.org") + get AhoyEmail::Engine.routes.url_helpers.click_path(c: "test", s: "AgVw_k8ckEXXHdlG0OZ8raH0OVir3LYAivnV3E0HRZU", t: "123", u: "https://example.org") assert_redirected_to "https://example.org" end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7e01d5c..c30c8f4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,12 +21,14 @@ def mongoid? config.secret_key_base = "0" * 128 config.autoload_paths << File.expand_path("support/mongoid_models", __dir__) config.logger = $logger + config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256 end else Combustion.initialize! :action_mailer, :action_controller, :active_record do config.load_defaults Rails::VERSION::STRING.to_f config.secret_key_base = "0" * 128 config.logger = $logger + config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256 end end diff --git a/test/token_test.rb b/test/token_test.rb index 7e5e2d8..958d479 100644 --- a/test/token_test.rb +++ b/test/token_test.rb @@ -3,7 +3,12 @@ class TokenTest < Minitest::Test def test_secret_token # ensure consistent across Rails releases - expected = "0baf04b17695d9934775733e6941fcc0f024c68ee98d539dc0c214823fa0e255708ac74a4957cb561ddd8a63af9a24e1d255259d95306734fb513e5e7cbb897d" + expected = "7f6a02c3632c8f46c90886517bc28c9bb67fc5634afa109cdb1e385592b9b91023bf4de7e2d074a8cd24c1ac0299d1b05837474212ec0cb104ec18659d71490b" assert_equal expected, AhoyEmail.secret_token.unpack1("h*") end + + def test_digest_class + digest_class = Combustion::Application.key_generator.instance_variable_get(:@key_generator).instance_variable_get(:@hash_digest_class) + assert_equal OpenSSL::Digest::SHA256, digest_class, "Digest class is different from what is configured in the Combustion application" + end end