BigW Consortium Gitlab

variable_spec.rb 1.1 KB
Newer Older
1 2
# == Schema Information
#
Dmitriy Zaporozhets committed
3
# Table name: ci_variables
4 5
#
#  id                   :integer          not null, primary key
Stan Hu committed
6
#  project_id           :integer
7 8 9 10 11
#  key                  :string(255)
#  value                :text
#  encrypted_value      :text
#  encrypted_value_salt :string(255)
#  encrypted_value_iv   :string(255)
Stan Hu committed
12
#  gl_project_id        :integer
13 14 15 16
#

require 'spec_helper'

Douwe Maan committed
17
describe Ci::Variable, models: true do
Dmitriy Zaporozhets committed
18
  subject { Ci::Variable.new }
19 20 21 22 23 24 25 26 27

  let(:secret_value) { 'secret' }

  before :each do
    subject.value = secret_value
  end

  describe :value do
    it 'stores the encrypted value' do
Dmitriy Zaporozhets committed
28
      expect(subject.encrypted_value).not_to be_nil
29 30 31
    end

    it 'stores an iv for value' do
Dmitriy Zaporozhets committed
32
      expect(subject.encrypted_value_iv).not_to be_nil
33 34 35
    end

    it 'stores a salt for value' do
Dmitriy Zaporozhets committed
36
      expect(subject.encrypted_value_salt).not_to be_nil
37 38 39 40 41
    end

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