Sha256: 5e2a1928d0b61e4c5099f7a4056dd175bd24f795924f49e53a1be5338beb027c

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe Clearance::PasswordStrategies::Blowfish do
  subject do
    Class.new do
      attr_accessor :salt, :password, :encrypted_password
      include Clearance::PasswordStrategies::Blowfish

      def generate_random_code; "code"; end
    end.new
  end

  describe "#encrypt_password" do
    context "when the password is set" do
      let(:salt) { "salt" }
      let(:password) { "password" }

      before do
        subject.salt = salt
        subject.password = password
        subject.send(:encrypt_password)
      end

      it "should encrypt the password using Blowfish into encrypted_password" do
        cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt
        cipher.key = Digest::SHA256.digest(salt)
        expected = cipher.update("--#{salt}--#{password}--") << cipher.final
        
        subject.encrypted_password.should == expected
      end
    end

    context "when the salt is not set" do
      before do
        subject.salt = nil

        subject.send(:encrypt_password)
      end

      it "should initialize the salt" do
        subject.salt.should_not be_nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clearance-0.16.3 spec/models/blowfish_spec.rb
clearance-0.16.2 spec/models/blowfish_spec.rb
clearance-0.16.1 spec/models/blowfish_spec.rb
clearance-0.16.0 spec/models/blowfish_spec.rb