Sha256: 0517378a23a5374422135d10b9e4c9f3ac701f8b2401a253a97298ac7d85f098

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

module CryptKeeper
  module Provider
    describe MysqlAes 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
        Base64.decode64 "nbKOoWn8kvAw9k/C2Mex6Q==\n"
      end

      subject { MysqlAes.new key: 'candy' }

      its(:key) { should == 'candy' }

      describe "#initialize" do
        it "should raise an exception with a missing key" do
          expect { MysqlAes.new }.to raise_error(ArgumentError, "Missing :key")
        end
      end

      describe "#encrypt" do
        it "should encrypt the string" do
          subject.encrypt(plain_text).should_not == plain_text
          subject.encrypt(plain_text).should_not be_empty
        end
      end

      describe "#decrypt" do
        it "should decrypt the string" do
          subject.decrypt(cipher_text).should == plain_text
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crypt_keeper-0.5.0 spec/provider/mysql_aes_spec.rb