test/models/crypt_test.rb in quo_vadis-2.1.6 vs test/models/crypt_test.rb in quo_vadis-2.1.7
- old
+ new
@@ -2,10 +2,17 @@
class CryptTest < ActiveSupport::TestCase
setup do
@crypt = QuoVadis::Crypt
+
+ @crypt_sha1 = Class.new(QuoVadis::Crypt) do
+ def self.encryptor(salt)
+ key_sha1 = key salt, OpenSSL::Digest::SHA1
+ ActiveSupport::MessageEncryptor.new key_sha1
+ end
+ end
end
test 'round trip' do
plaintext = 'the quick brown fox'
ciphertext = @crypt.encrypt plaintext
@@ -15,8 +22,20 @@
test 'same plaintext encrypts to different ciphertexts' do
plaintext = 'the quick brown fox'
ciphertext = @crypt.encrypt plaintext
refute_equal ciphertext, @crypt.encrypt(plaintext)
+ end
+
+ test 'rotation' do
+ # This test only works if our test Rails contains this commit:
+ # https://github.com/rails/rails/commit/447e28347eb46e2ad5dc625de616152bd1b69a32
+ return unless ActiveSupport::KeyGenerator.respond_to? :hash_digest_class
+
+ plaintext = 'the quick brown fox'
+ # Encrypt with SHA1 digest
+ ciphertext_sha1 = @crypt_sha1.encrypt plaintext
+ # Ensure code can decrypt it.
+ assert_equal plaintext, @crypt.decrypt(ciphertext_sha1)
end
end