Sha256: 625516af4333696776e44b1afb8cc9ddd3de16d8a6ac0c46b6cec84e6ccfc6f4
Contents?: true
Size: 1.93 KB
Versions: 13
Compression:
Stored size: 1.93 KB
Contents
require 'spec_helper' describe Heirloom do before do @logger_mock = mock 'logger', :info => true @logger_mock.stub :info => true @config_mock = mock 'config' @config_mock.stub :logger => @logger_mock @data = Heirloom::Cipher::Data.new :config => @config_mock end context "with secret given" do before do @aes_mock = mock 'aes' OpenSSL::Cipher::AES256.should_receive(:new). with(:CBC).and_return @aes_mock end it "should decrypt the given data" do @aes_mock.should_receive(:decrypt) @aes_mock.should_receive(:key=).with Digest::SHA256.hexdigest 'mysecret' @aes_mock.should_receive(:iv=).with 'firstsixteenchar' @aes_mock.should_receive(:update).with('crypteddata').and_return 'cleartext' @aes_mock.stub :final => 'final' @data.decrypt_data(:data => 'firstsixteencharcrypteddata', :secret => 'mysecret'). should == 'cleartextfinal' end it "should rescue bad key error and return false" do @logger_mock.should_receive(:error). with "Unable to decrypt archive: 'OpenSSL::Cipher::CipherError'" @aes_mock.should_receive(:decrypt) @aes_mock.should_receive(:key=).with Digest::SHA256.hexdigest 'badsecret' @aes_mock.should_receive(:iv=).with 'firstsixteenchar' @aes_mock.should_receive(:update).with('crypteddata').and_return 'crap' @aes_mock.should_receive(:final).and_raise OpenSSL::Cipher::CipherError @data.decrypt_data(:data => 'firstsixteencharcrypteddata', :secret => 'badsecret'). should be_false end end context "no secret given" do before do @data = Heirloom::Cipher::Data.new :config => @config_mock end it "should return the data if no secret given" do @data.decrypt_data(:data => 'plaintext', :secret => nil).should == 'plaintext' end end end
Version data entries
13 entries across 13 versions & 1 rubygems