Sha256: c98ba022d7caca327cd57bca3bfd044efc28e1c80f46c9a412ca22cbd5b165bc

Contents?: true

Size: 1.68 KB

Versions: 36

Compression:

Stored size: 1.68 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe TwitterAuth::Cryptify do
  before do
    stub_basic!
  end

  it 'should have encrypt and decrypt methods' do
    TwitterAuth::Cryptify.should respond_to(:encrypt)
    TwitterAuth::Cryptify.should respond_to(:decrypt)
  end

  describe '.encrypt' do
    it 'should return a hash with :encrypted_data and :salt keys' do
      result = TwitterAuth::Cryptify.encrypt('some string')
      result.should be_a(Hash)
      result.key?(:encrypted_data).should be_true
      result.key?(:salt).should be_true
    end

    it 'should make a call to EzCrypto::Key.encrypt_with_password' do
      EzCrypto::Key.should_receive(:encrypt_with_password).once.and_return('gobbledygook')
      TwitterAuth::Cryptify.encrypt('some string') 
    end

    it 'should not have the same encrypted as plaintext data' do
      TwitterAuth::Cryptify.encrypt('some string')[:encrypted_data].should_not == 'some string'
    end
  end

  describe '.decrypt' do
    before do
      @salt = TwitterAuth::Cryptify.generate_salt
      TwitterAuth::Cryptify.stub!(:generate_salt).and_return(@salt)
      @string = 'decrypted string'
      @encrypted = TwitterAuth::Cryptify.encrypt(@string)
    end

    it 'should return the original string' do
      TwitterAuth::Cryptify.decrypt(@encrypted).should == @string
    end

    it 'should raise an argument error if encrypted data is provided without a salt' do
      lambda{TwitterAuth::Cryptify.decrypt('asodiaoie2')}.should raise_error(ArgumentError)
    end

    it 'should raise an argument error if a string or hash are not provided' do
      lambda{TwitterAuth::Cryptify.decrypt(23)}.should raise_error(ArgumentError)
    end
  end
end

Version data entries

36 entries across 36 versions & 6 rubygems

Version Path
mbleigh-twitter-auth-0.1.1 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.10 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.11 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.12 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.13 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.14 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.15 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.16 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.18 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.20 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.21 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.22 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.3 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.5 spec/twitter_auth/cryptify_spec.rb
mbleigh-twitter-auth-0.1.8 spec/twitter_auth/cryptify_spec.rb
millsb-twitter-auth-0.1.16 spec/twitter_auth/cryptify_spec.rb
xaviershay-twitter-auth-0.1.19 spec/twitter_auth/cryptify_spec.rb
twitter-auth-with-mongo-mapper-0.1.1 spec/twitter_auth/cryptify_spec.rb
twitter-auth-with-mongo-mapper-0.1.0 spec/twitter_auth/cryptify_spec.rb
twitter-auth-with-mongo-mapper-0.0.9 spec/twitter_auth/cryptify_spec.rb