Sha256: dd1df741dee6facb8de913c780e7013f6df458b2e2dd6296c081465524c7f7cf

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

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
    refute_equal plaintext, ciphertext
    assert_equal plaintext, @crypt.decrypt(ciphertext)
  end

  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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
quo_vadis-2.2.4 test/models/crypt_test.rb
quo_vadis-2.2.2 test/models/crypt_test.rb
quo_vadis-2.2.1 test/models/crypt_test.rb
quo_vadis-2.2.0 test/models/crypt_test.rb
quo_vadis-2.1.11 test/models/crypt_test.rb
quo_vadis-2.1.10 test/models/crypt_test.rb
quo_vadis-2.1.9 test/models/crypt_test.rb
quo_vadis-2.1.8 test/models/crypt_test.rb
quo_vadis-2.1.7 test/models/crypt_test.rb