diff options
Diffstat (limited to 'activesupport/test/message_encryptor_test.rb')
-rw-r--r-- | activesupport/test/message_encryptor_test.rb | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 5dfa187f36..fb0b1e377d 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'openssl' -require 'active_support/time' -require 'active_support/json' +require "abstract_unit" +require "openssl" +require "active_support/time" +require "active_support/json" class MessageEncryptorTest < ActiveSupport::TestCase class JSONSerializer @@ -16,9 +16,9 @@ class MessageEncryptorTest < ActiveSupport::TestCase def setup @secret = SecureRandom.random_bytes(32) - @verifier = ActiveSupport::MessageVerifier.new(@secret, :serializer => ActiveSupport::MessageEncryptor::NullSerializer) + @verifier = ActiveSupport::MessageVerifier.new(@secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer) @encryptor = ActiveSupport::MessageEncryptor.new(@secret) - @data = { :some => "data", :now => Time.local(2010) } + @data = { some: "data", now: Time.local(2010) } end def test_encrypting_twice_yields_differing_cipher_text @@ -51,8 +51,8 @@ class MessageEncryptorTest < ActiveSupport::TestCase def test_alternative_serialization_method prev = ActiveSupport.use_standard_json_time_format ActiveSupport.use_standard_json_time_format = true - encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), :serializer => JSONSerializer.new) - message = encryptor.encrypt_and_sign({ :foo => 123, 'bar' => Time.utc(2010) }) + encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), serializer: JSONSerializer.new) + message = encryptor.encrypt_and_sign(:foo => 123, "bar" => Time.utc(2010)) exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00.000Z" } assert_equal exp, encryptor.decrypt_and_verify(message) ensure @@ -71,13 +71,13 @@ class MessageEncryptorTest < ActiveSupport::TestCase end def test_aead_mode_encryption - encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: 'aes-256-gcm') + encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") message = encryptor.encrypt_and_sign(@data) assert_equal @data, encryptor.decrypt_and_verify(message) end def test_messing_with_aead_values_causes_failures - encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: 'aes-256-gcm') + encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") text, iv, auth_tag = encryptor.encrypt_and_sign(@data).split("--") assert_not_decrypted([iv, text, auth_tag] * "--") assert_not_decrypted([munge(text), iv, auth_tag] * "--") @@ -90,21 +90,21 @@ class MessageEncryptorTest < ActiveSupport::TestCase private - def assert_not_decrypted(value) - assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do - @encryptor.decrypt_and_verify(@verifier.generate(value)) + def assert_not_decrypted(value) + assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do + @encryptor.decrypt_and_verify(@verifier.generate(value)) + end end - end - def assert_not_verified(value) - assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do - @encryptor.decrypt_and_verify(value) + def assert_not_verified(value) + assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do + @encryptor.decrypt_and_verify(value) + end end - end - def munge(base64_string) - bits = ::Base64.strict_decode64(base64_string) - bits.reverse! - ::Base64.strict_encode64(bits) - end + def munge(base64_string) + bits = ::Base64.strict_decode64(base64_string) + bits.reverse! + ::Base64.strict_encode64(bits) + end end |