summaryrefslogtreecommitdiff
path: root/spec/models/variable_spec.rb
blob: c089df9e9e6f6ffc9eb826de48d80b508bd0ceea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# == Schema Information
#
# Table name: variables
#
#  id                   :integer          not null, primary key
#  project_id           :integer          not null
#  key                  :string(255)
#  value                :text
#  encrypted_value      :text
#  encrypted_value_salt :string(255)
#  encrypted_value_iv   :string(255)
#

require 'spec_helper'

describe Variable do
  subject { described_class.new }

  let(:secret_value) { 'secret' }

  before :each do
    subject.value = secret_value
  end

  describe '#value' do
    it 'stores the encrypted value' do
      subject.encrypted_value.should_not be_nil
    end

    it 'stores an iv for value' do
      subject.encrypted_value_iv.should_not be_nil
    end

    it 'stores a salt for value' do
      subject.encrypted_value_salt.should_not be_nil
    end

    it 'fails to decrypt if iv is incorrect' do
      subject.encrypted_value_iv = nil
      subject.instance_variable_set(:@value, nil)
      expect { subject.value }.
        to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt')
    end
  end
end