BigW Consortium Gitlab

variable_spec.rb 1.12 KB
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

  let(:secret_value) { 'secret' }

8 9 10 11 12 13 14
  it { is_expected.to validate_presence_of(:key) }
  it { is_expected.to validate_uniqueness_of(:key).scoped_to(:gl_project_id) }
  it { is_expected.to validate_length_of(:key).is_at_most(255) }
  it { is_expected.to allow_value('foo').for(:key) }
  it { is_expected.not_to allow_value('foo bar').for(:key) }
  it { is_expected.not_to allow_value('foo/bar').for(:key) }

15 16 17 18
  before :each do
    subject.value = secret_value
  end

19
  describe '#value' do
20
    it 'stores the encrypted value' do
Dmitriy Zaporozhets committed
21
      expect(subject.encrypted_value).not_to be_nil
22 23 24
    end

    it 'stores an iv for value' do
Dmitriy Zaporozhets committed
25
      expect(subject.encrypted_value_iv).not_to be_nil
26 27 28
    end

    it 'stores a salt for value' do
Dmitriy Zaporozhets committed
29
      expect(subject.encrypted_value_salt).not_to be_nil
30 31 32
    end

    it 'fails to decrypt if iv is incorrect' do
33
      subject.encrypted_value_iv = SecureRandom.hex
34
      subject.instance_variable_set(:@value, nil)
35 36
      expect { subject.value }.
        to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt')
37 38 39
    end
  end
end