Skip to content

Commit 4ec747e

Browse files
authored
Merge pull request #22 from Dorin-Pleava/MODULES-10246/yum_repo_core_proxy_accepts_empty_string
(MODULES-10246) Proxy settings allow empty string
2 parents 31c1736 + 91efedf commit 4ec747e

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cache: bundler
55
before_install:
66
- bundle -v
77
- rm -f Gemfile.lock
8-
- gem update --system $RUBYGEMS_VERSION
8+
- yes | gem update --system $RUBYGEMS_VERSION
99
- gem --version
1010
- bundle -v
1111
script:

lib/puppet/type/yumrepo.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,25 @@
304304

305305
newproperty(:proxy) do
306306
desc "URL of a proxy server that Yum should use when accessing this repository.
307-
This attribute can also be set to `'_none_'`, which will make Yum bypass any
308-
global proxy settings when accessing this repository.
307+
This attribute can also be set to '_none_' (or '' for EL >= 8 only),
308+
which will make Yum bypass any global proxy settings when accessing this repository.
309309
#{ABSENT_DOC}"
310310

311311
newvalues(%r{.*}, :absent)
312312
validate do |value|
313313
next if value.to_s =~ %r{^(absent|_none_)$}
314-
parsed = URI.parse(value)
314+
next if value.to_s.empty? && Facter.value(:operatingsystemmajrelease).to_i >= 8
315315

316+
parsed = URI.parse(value)
316317
unless VALID_SCHEMES.include?(parsed.scheme)
317318
raise _('Must be a valid URL')
318319
end
319320
end
321+
322+
munge do |value|
323+
return '' if Facter.value(:operatingsystemmajrelease).to_i >= 8 && value.to_s == '_none_'
324+
value.to_s
325+
end
320326
end
321327

322328
newproperty(:proxy_username) do

spec/unit/type/yumrepo_spec.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,37 @@
312312

313313
describe 'proxy' do
314314
it_behaves_like 'a yumrepo parameter that can be absent', :proxy
315+
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy
316+
315317
it 'accepts _none_' do
316318
described_class.new(
317319
name: 'puppetlabs',
318320
proxy: '_none_',
319321
)
320322
end
321-
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy
323+
324+
it 'accepts an empty string' do
325+
described_class.new(
326+
name: 'puppetlabs',
327+
proxy: '',
328+
)
329+
end
330+
331+
it "munges '_none_' to empty string for EL >= 8" do
332+
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('8')
333+
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
334+
expect(instance[:proxy]).to eq ''
335+
end
336+
337+
it "does not munges '_none_' to empty string for EL < 8" do
338+
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('7')
339+
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
340+
expect(instance[:proxy]).to eq '_none_'
341+
end
342+
343+
it 'does not raise any errors' do
344+
expect { described_class.new(name: 'puppetlabs', proxy: '') }.not_to raise_error
345+
end
322346
end
323347

324348
describe 'proxy_username' do

0 commit comments

Comments
 (0)