Revision 1da8bd42
Added by Dominic Cleal about 7 years ago
test/unit/encryptable_test.rb | ||
---|---|---|
assert compute_resource.is_decryptable?(encrypted_str)
|
||
end
|
||
|
||
test "encrypt unsuccessfully logs error once" do
|
||
EncryptValue.reset_warnings
|
||
compute_resource = cr_with_encryption_key
|
||
ActiveSupport::MessageEncryptor.any_instance.expects(:encrypt_and_sign).twice.raises('Encryption error')
|
||
compute_resource.expects(:puts_and_logs).once
|
||
encrypted_str = compute_resource.encrypt_field('secret')
|
||
assert_equal 'secret', encrypted_str
|
||
compute_resource.encrypt_field('secret')
|
||
end
|
||
|
||
test "decrypt successfully" do
|
||
compute_resource = cr_with_encryption_key
|
||
plain_str = "secretpassword"
|
||
... | ... | |
assert_equal plain_str, decrypted_str
|
||
end
|
||
|
||
test "decrypt unsuccessfully logs error once" do
|
||
EncryptValue.reset_warnings
|
||
compute_resource = stub_encryption_key(FactoryGirl.build(:ec2_cr, password: 'encrypted-invalid'))
|
||
compute_resource.expects(:puts_and_logs).once
|
||
decrypted_str = compute_resource.password
|
||
assert_equal 'encrypted-invalid', decrypted_str
|
||
compute_resource.password
|
||
end
|
||
|
||
test "encrypt_field returns nil if password is nil" do
|
||
compute_resource = cr_with_encryption_key
|
||
encrypted_str = compute_resource.encrypt_field(nil)
|
Also available in: Unified diff
refs #19534 - check EncryptValue class variables are defined
bed4594 added class variables to record logging state, but failed to
check it was defined before accessing them, causing exceptions when
decryption failed. Tests added for this new behaviour.