Sha256: 712396962193104e687cf9b1b1b7059092cc12fe6190305f08f487ffa3ae288c

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

# -*- encoding: utf-8 -*-
require 'spec_helper'

describe 'SHA encryption' do
  let(:credential) { ShaCredential.create(:email => 'john.smith@example.com', :password => 'this is a secret') }

  context "#to_s" do
    subject { "#{credential.password}" }
    it { should eq("70a202166f0a78defe464d810f30b50b767cb89a") }
  end

  context "'this is a secret'" do
    subject { credential.password }
    it { should be_encrypted }
    it { should eq('this is a secret') }
  end

  context "cipher" do
    subject { credential.password.cipher }
    it { should be_an_instance_of(EncryptedStrings::ShaCipher) }
  end

  context "use default salt" do
    subject { credential.password.cipher.salt }
    it { should eq('salt') }
  end

  context "load from database" do
    subject { ShaCredential.find(credential.id).password }
    it { should be_encrypted }
    it { should eq('this is a secret') }

    context "#to_s" do
      subject { "#{ShaCredential.find(credential.id).password}" }
      it { should eq("70a202166f0a78defe464d810f30b50b767cb89a") }
    end
  end

  context "with mass assignment" do
    let(:credential) { ShaCredential.new(:email => 'john.smith@example.com', :password => 'this is a secret') }
    subject { credential.password }
    it { should eq('this is a secret') }
    it { should_not be_encrypted }

    context "after save" do
      before { credential.save! }
      subject { credential.password }
      it { should be_encrypted }
      it { should eq('this is a secret') }

      context "#to_s" do
        subject { "#{credential.password}" }
        it { should eq('70a202166f0a78defe464d810f30b50b767cb89a') }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-encryptor-0.0.4 spec/sha_encryption_spec.rb
mongoid-encryptor-0.0.1 spec/sha_encryption_spec.rb