2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe Gitlab::Ci::Config::Entry::Key do
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:entry) { described_class.new(config) }
|
|
|
|
|
|
|
|
describe 'validations' do
|
2018-03-17 18:26:18 +05:30
|
|
|
shared_examples 'key with slash' do
|
|
|
|
it 'is invalid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports errors with config value' do
|
|
|
|
expect(entry.errors).to include 'key config cannot contain the "/" character'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'key with only dots' do
|
|
|
|
it 'is invalid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports errors with config value' do
|
|
|
|
expect(entry.errors).to include 'key config cannot be "." or ".."'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when entry config value is correct' do
|
|
|
|
let(:config) { 'test' }
|
|
|
|
|
|
|
|
describe '#value' do
|
|
|
|
it 'returns key value' do
|
|
|
|
expect(entry.value).to eq 'test'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:config) { ['incorrect'] }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'saves errors' do
|
|
|
|
expect(entry.errors)
|
|
|
|
.to include 'key config should be a string or symbol'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when entry value contains slash' do
|
|
|
|
let(:config) { 'key/with/some/slashes' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with slash'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value contains URI encoded slash (%2F)' do
|
|
|
|
let(:config) { 'key%2Fwith%2Fsome%2Fslashes' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with slash'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is a dot' do
|
|
|
|
let(:config) { '.' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with only dots'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is two dots' do
|
|
|
|
let(:config) { '..' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with only dots'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is a URI encoded dot (%2E)' do
|
|
|
|
let(:config) { '%2e' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with only dots'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is two URI encoded dots (%2E)' do
|
|
|
|
let(:config) { '%2E%2e' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with only dots'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is one dot and one URI encoded dot' do
|
|
|
|
let(:config) { '.%2e' }
|
|
|
|
|
|
|
|
it_behaves_like 'key with only dots'
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '.default' do
|
|
|
|
it 'returns default key' do
|
|
|
|
expect(described_class.default).to eq 'default'
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|