aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/encrypted_file_test.rb
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-12-05 21:41:19 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-12-18 08:04:15 +0900
commit35373219c91ea8096ef2f8e7f3c62bcd46f436be (patch)
tree568eddd5f7ef943f297c8cfe56d1087d371d5122 /activesupport/test/encrypted_file_test.rb
parentdaf15f58b943d85d8fb726590ae94f77ca0a5d5f (diff)
downloadrails-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.rb13
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