Sha256: 5b91dd1a8d82ae5188e1b695d785e16dbd1208405e15ddf3beb386075ca7dba7

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

module CryptKeeper
  module Provider
    describe PostgresPgp do
      use_postgres

      let(:cipher_text) { '\\xc30d0407030283b15f71b6a7d0296cd23501bd2c8fe3c7a56005ff4619527c4291509a78c77a6758cddd2a14acbde589fa10b3e0686865182d3beadaf237b9f928e7ba1810b8' }
      let(:plain_text)  { 'test' }

      let(:integer_cipher_text) { '\xc30d040703028c65c58c0e9d015360d2320125112fc38f094e57cce1c0313f3eea4a7fc3e95c048bc319e25003ab6f29ceabe3609089d12094508c1eb79a2d70f95233' }
      let(:integer_plain_text) { 1 }

      subject { PostgresPgp.new key: 'candy' }

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

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

      describe "#encrypt" do
        context "Strings" do
          specify { subject.encrypt(plain_text).should_not == plain_text }
          specify { subject.encrypt(plain_text).should_not be_empty }
        end

        context "Integers" do
          specify { subject.encrypt(integer_plain_text).should_not == integer_plain_text }
          specify { subject.encrypt(integer_plain_text).should_not be_empty }
        end
      end

      describe "#decrypt" do
        specify { subject.decrypt(cipher_text).should == plain_text }
      end

      describe "Custom pgcrypto options" do
        let(:pgcrypto_options) { 'compress-level=0' }

        subject { PostgresPgp.new key: 'candy', pgcrypto_options: pgcrypto_options }

        it "reads and writes" do
          queries = logged_queries do
            encrypted = subject.encrypt(plain_text)
            subject.decrypt(encrypted).should == plain_text
          end

          queries.should_not be_empty

          queries.select { |query| query.include?("pgp_sym_encrypt") }.each do |q|
            q.should include(pgcrypto_options)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
crypt_keeper-0.14.0.pre spec/provider/postgres_pgp_spec.rb
crypt_keeper-0.13.1 spec/provider/postgres_pgp_spec.rb
crypt_keeper-0.13.0 spec/provider/postgres_pgp_spec.rb