Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/ahoy_email/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/click_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion test/token_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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