BigW Consortium Gitlab

variable_spec.rb 779 Bytes
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Ci::Variable, models: true do
Dmitriy Zaporozhets committed
4
  subject { Ci::Variable.new }
5 6 7 8 9 10 11

  let(:secret_value) { 'secret' }

  before :each do
    subject.value = secret_value
  end

12
  describe '#value' do
13
    it 'stores the encrypted value' do
Dmitriy Zaporozhets committed
14
      expect(subject.encrypted_value).not_to be_nil
15 16 17
    end

    it 'stores an iv for value' do
Dmitriy Zaporozhets committed
18
      expect(subject.encrypted_value_iv).not_to be_nil
19 20 21
    end

    it 'stores a salt for value' do
Dmitriy Zaporozhets committed
22
      expect(subject.encrypted_value_salt).not_to be_nil
23 24 25
    end

    it 'fails to decrypt if iv is incorrect' do
26
      subject.encrypted_value_iv = SecureRandom.hex
27
      subject.instance_variable_set(:@value, nil)
28 29
      expect { subject.value }.
        to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt')
30 31 32
    end
  end
end