diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-12-05 21:41:19 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-12-18 08:04:15 +0900 |
commit | 35373219c91ea8096ef2f8e7f3c62bcd46f436be (patch) | |
tree | 568eddd5f7ef943f297c8cfe56d1087d371d5122 /activesupport/test/encrypted_file_test.rb | |
parent | daf15f58b943d85d8fb726590ae94f77ca0a5d5f (diff) | |
download | rails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.tar.gz rails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.tar.bz2 rails-35373219c91ea8096ef2f8e7f3c62bcd46f436be.zip |
Raise an error only when `require_master_key` is specified
To prevent errors from being raise in environments where credentials
is unnecessary.
Context: https://github.com/rails/rails/issues/31283#issuecomment-348801489
Fixes #31283
Diffstat (limited to 'activesupport/test/encrypted_file_test.rb')
-rw-r--r-- | activesupport/test/encrypted_file_test.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/activesupport/test/encrypted_file_test.rb b/activesupport/test/encrypted_file_test.rb index 7259726d08..ba3bbef903 100644 --- a/activesupport/test/encrypted_file_test.rb +++ b/activesupport/test/encrypted_file_test.rb @@ -12,8 +12,9 @@ class EncryptedFileTest < ActiveSupport::TestCase @key_path = File.join(Dir.tmpdir, "content.txt.key") File.write(@key_path, ActiveSupport::EncryptedFile.generate_key) - @encrypted_file = ActiveSupport::EncryptedFile.new \ - content_path: @content_path, key_path: @key_path, env_key: "CONTENT_KEY" + @encrypted_file = ActiveSupport::EncryptedFile.new( + content_path: @content_path, key_path: @key_path, env_key: "CONTENT_KEY", raise_if_missing_key: true + ) end teardown do @@ -47,4 +48,12 @@ class EncryptedFileTest < ActiveSupport::TestCase assert_equal "#{@content} and went by the lake", @encrypted_file.read end + + test "raise MissingKeyError when key is missing" do + assert_raise(ActiveSupport::EncryptedFile::MissingKeyError) do + ActiveSupport::EncryptedFile.new( + content_path: @content_path, key_path: "", env_key: "", raise_if_missing_key: true + ).read + end + end end |