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

Add test to validate that ciphertext is returned when all previous schemes fail

This commit is contained in:
Jorge Manrubia 2021-04-22 11:49:04 +02:00 committed by George Claghorn
parent 9b7aafac98
commit 6107209361

View file

@ -75,6 +75,17 @@ class ActiveRecord::Encryption::EncryptionSchemesTest < ActiveRecord::Encryption
assert_equal "1", author.reload.name
end
test "returns ciphertext all the previous schemes fail to decrypt and support for unencrypted data is on" do
ActiveRecord::Encryption.config.support_unencrypted_data = true
encrypted_author_class = declare_class_with_global_previous_encryption_schemes({ encryptor: TestEncryptor.new("0" => "1") }, { encryptor: TestEncryptor.new("1" => "2") })
author = ActiveRecord::Encryption.without_encryption do
encrypted_author_class.create name: "some ciphertext"
end
assert_equal "some ciphertext", author.reload.name
end
test "raise decryption error when all the previous schemes fail to decrypt" do
ActiveRecord::Encryption.config.support_unencrypted_data = false
encrypted_author_class = declare_class_with_global_previous_encryption_schemes({ encryptor: TestEncryptor.new("0" => "1") }, { encryptor: TestEncryptor.new("1" => "2") })