Sha256: c12112abc24f8ab657d58675d98e00b0aaefaffad1c25a8c9a52e9a0bd664201

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe CryptKeeper::Provider::MysqlAesNew do
  use_mysql

  let(:plain_text) { 'test' }

  # MySQL stores AES encrypted strings in binary which you can't paste
  # into a spec :). This is a Base64 encoded string of 'test' AES encrypted
  # by AES_ENCRYPT()
  let(:cipher_text) do
    "fBN8i7bx/DGAA4NJ4EWi0A=="
  end

  subject { described_class.new key: ENCRYPTION_PASSWORD, salt: 'salt' }

  specify { expect(subject.key).to eq("825e8c5e8ca394818b307b22b8cb7d3df2735e9c1e5838b476e7719135a4f499f2133022c1a0e8597c9ac1507b0f0c44328a40049f9704fab3598c5dec120724") }

  describe "#initialize" do
    specify { expect { described_class.new }.to raise_error(ArgumentError, "Missing :key") }
    specify { expect { described_class.new(key: 'blah') }.to raise_error(ArgumentError, "Missing :salt") }
  end

  describe "#encrypt" do
    specify { expect(subject.encrypt(plain_text)).to_not eq(plain_text) }
    specify { expect(subject.encrypt(plain_text)).to_not be_blank }
  end

  describe "#decrypt" do
    specify { expect(subject.decrypt(cipher_text)).to eq(plain_text) }
  end

  describe "#search" do
    subject { mysql_model }

    it "finds the matching record" do
      subject.create!(storage: 'blah2')
      match = subject.create!(storage: 'blah')
      expect(subject.search_by_plaintext(:storage, 'blah').first).to eq(match)
    end

    it "keeps the scope" do
      subject.create!(storage: 'blah')
      subject.create!(storage: 'blah')

      scope = subject.limit(1)
      expect(scope.search_by_plaintext(:storage, 'blah').count).to eq(1)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
crypt_keeper-2.0.0.rc1 spec/crypt_keeper/provider/mysql_aes_new_spec.rb
crypt_keeper-1.1.1 spec/crypt_keeper/provider/mysql_aes_new_spec.rb
crypt_keeper-1.1.0 spec/crypt_keeper/provider/mysql_aes_new_spec.rb
crypt_keeper-1.0.1 spec/crypt_keeper/provider/mysql_aes_new_spec.rb
crypt_keeper-1.0.0 spec/crypt_keeper/provider/mysql_aes_new_spec.rb
crypt_keeper-1.0.0.beta1 spec/crypt_keeper/provider/mysql_aes_new_spec.rb