mirror of https://github.com/rails/rails
Merge pull request #42370 from sunny/better-error-message-when-encrypted-file-key-is-blank
Raise missing key error when master key env variable is blank
This commit is contained in:
commit
5c09cfd96f
|
@ -1,3 +1,8 @@
|
|||
* Raise `ActiveSupport::EncryptedFile::MissingKeyError` when the
|
||||
`RAILS_MASTER_KEY` environment variable is blank (e.g. `""`).
|
||||
|
||||
*Sunny Ripert*
|
||||
|
||||
* The `from:` option is added to `ActiveSupport::TestCase#assert_no_changes`.
|
||||
|
||||
It permits asserting on the initial value that is expected not to change.
|
||||
|
|
|
@ -98,7 +98,7 @@ module ActiveSupport
|
|||
|
||||
|
||||
def read_env_key
|
||||
ENV[env_key]
|
||||
ENV[env_key].presence
|
||||
end
|
||||
|
||||
def read_key_file
|
||||
|
|
|
@ -55,6 +55,22 @@ class EncryptedFileTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "raise MissingKeyError when env key is blank" do
|
||||
FileUtils.rm_rf @key_path
|
||||
|
||||
begin
|
||||
ENV["CONTENT_KEY"] = ""
|
||||
raised = assert_raise ActiveSupport::EncryptedFile::MissingKeyError do
|
||||
@encrypted_file.write @content
|
||||
@encrypted_file.read
|
||||
end
|
||||
|
||||
assert_match(/Missing encryption key to decrypt file/, raised.message)
|
||||
ensure
|
||||
ENV["CONTENT_KEY"] = nil
|
||||
end
|
||||
end
|
||||
|
||||
test "raise InvalidKeyLengthError when key is too short" do
|
||||
File.write(@key_path, ActiveSupport::EncryptedFile.generate_key[0..-2])
|
||||
|
||||
|
|
Loading…
Reference in New Issue