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:
parent
2257a237d8
commit
afdc2af9e2
3 changed files with 23 additions and 2 deletions
|
@ -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`.
|
* The `from:` option is added to `ActiveSupport::TestCase#assert_no_changes`.
|
||||||
|
|
||||||
It permits asserting on the initial value that is expected not to change.
|
It permits asserting on the initial value that is expected not to change.
|
||||||
|
|
|
@ -98,7 +98,7 @@ module ActiveSupport
|
||||||
|
|
||||||
|
|
||||||
def read_env_key
|
def read_env_key
|
||||||
ENV[env_key]
|
ENV[env_key].presence
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_key_file
|
def read_key_file
|
||||||
|
|
|
@ -55,6 +55,22 @@ class EncryptedFileTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
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
|
test "raise InvalidKeyLengthError when key is too short" do
|
||||||
File.write(@key_path, ActiveSupport::EncryptedFile.generate_key[0..-2])
|
File.write(@key_path, ActiveSupport::EncryptedFile.generate_key[0..-2])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue