1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Raise missing key error when master key env var is blank

This commit is contained in:
Sunny Ripert 2021-06-03 15:16:14 +02:00
parent 2257a237d8
commit afdc2af9e2
3 changed files with 23 additions and 2 deletions

View file

@ -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.
@ -7,7 +12,7 @@
post :create, params: { status: { ok: true } }
end
```
*George Claghorn*
* Deprecate `ActiveSupport::SafeBuffer`'s incorrect implicit conversion of objects into string.

View file

@ -98,7 +98,7 @@ module ActiveSupport
def read_env_key
ENV[env_key]
ENV[env_key].presence
end
def read_key_file

View 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])