aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/message_encryptor_test.rb10
-rw-r--r--activesupport/test/message_verifier_test.rb9
2 files changed, 18 insertions, 1 deletions
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index e45d5ecd59..bd11b76e60 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -8,6 +8,7 @@ rescue LoadError, NameError
else
require 'active_support/time'
+require 'active_support/json'
class MessageEncryptorTest < Test::Unit::TestCase
def setup
@@ -38,7 +39,14 @@ class MessageEncryptorTest < Test::Unit::TestCase
message = @encryptor.encrypt_and_sign(@data)
assert_equal @data, @encryptor.decrypt_and_verify(message)
end
-
+
+ def test_alternative_serialization_method
+ @encryptor.serializer = lambda { |value| ActiveSupport::JSON.encode(value) }
+ @encryptor.deserializer = lambda { |value| ActiveSupport::JSON.decode(value) }
+
+ message = @encryptor.encrypt_and_sign({ :foo => 123, 'bar' => Time.local(2010) })
+ assert_equal @encryptor.decrypt_and_verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00-05:00" }
+ end
private
def assert_not_decrypted(value)
diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb
index 4821311244..83f34ebc33 100644
--- a/activesupport/test/message_verifier_test.rb
+++ b/activesupport/test/message_verifier_test.rb
@@ -8,6 +8,7 @@ rescue LoadError, NameError
else
require 'active_support/time'
+require 'active_support/json'
class MessageVerifierTest < Test::Unit::TestCase
def setup
@@ -31,6 +32,14 @@ class MessageVerifierTest < Test::Unit::TestCase
assert_not_verified("#{data}--#{hash.reverse}")
assert_not_verified("purejunk")
end
+
+ def test_alternative_serialization_method
+ @verifier.serializer = lambda { |value| ActiveSupport::JSON.encode(value) }
+ @verifier.deserializer = lambda { |value| ActiveSupport::JSON.decode(value) }
+
+ message = @verifier.generate({ :foo => 123, 'bar' => Time.local(2010) })
+ assert_equal @verifier.verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00-05:00" }
+ end
def assert_not_verified(message)
assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do