diff options
Diffstat (limited to 'spec/models/concerns/ci/has_variable_spec.rb')
-rw-r--r-- | spec/models/concerns/ci/has_variable_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/models/concerns/ci/has_variable_spec.rb b/spec/models/concerns/ci/has_variable_spec.rb index e917ec6b802..bf699119a37 100644 --- a/spec/models/concerns/ci/has_variable_spec.rb +++ b/spec/models/concerns/ci/has_variable_spec.rb @@ -68,9 +68,48 @@ RSpec.describe Ci::HasVariable do end describe '#to_runner_variable' do + let_it_be(:ci_variable) { create(:ci_variable) } + + subject { ci_variable } + it 'returns a hash for the runner' do expect(subject.to_runner_variable) .to include(key: subject.key, value: subject.value, public: false) end + + context 'with RequestStore enabled', :request_store do + let(:expected) do + { + file: false, + key: subject.key, + value: subject.value, + public: false, + masked: false + } + end + + it 'decrypts once' do + expect(OpenSSL::PKCS5).to receive(:pbkdf2_hmac).once.and_call_original + + 2.times { expect(subject.reload.to_runner_variable).to eq(expected) } + end + + it 'does not cache similar keys', :aggregate_failures do + group_var = create(:ci_group_variable, key: subject.key, value: 'group') + project_var = create(:ci_variable, key: subject.key, value: 'project') + + expect(subject.to_runner_variable).to include(key: subject.key, value: subject.value) + expect(group_var.to_runner_variable).to include(key: subject.key, value: 'group') + expect(project_var.to_runner_variable).to include(key: subject.key, value: 'project') + end + + it 'does not cache unpersisted values' do + new_variable = Ci::Variable.new(key: SecureRandom.hex, value: "12345") + old_value = new_variable.to_runner_variable + new_variable.value = '98765' + + expect(new_variable.to_runner_variable).not_to eq(old_value) + end + end end end |