Skip to content

Commit

Permalink
(MODULES-10246) Proxy settings allow empty string
Browse files Browse the repository at this point in the history
This PR enables the Yum Repo Core to accept an empty string as proxy
setting, to bypass any global proxy settings when accessing the
repository.

In case of EL 8, '_none_' will be replaced with '' (empty string).
  • Loading branch information
Dorin-Pleava committed Dec 16, 2019
1 parent 31c1736 commit c0499f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/puppet/type/yumrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,25 @@

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

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

parsed = URI.parse(value)
unless VALID_SCHEMES.include?(parsed.scheme)
raise _('Must be a valid URL')
end
end

munge do |value|
return '' if Facter.value(:operatingsystemmajrelease).to_i >= 8 && value.to_s == '_none_'
value.to_s
end
end

newproperty(:proxy_username) do
Expand Down
26 changes: 25 additions & 1 deletion spec/unit/type/yumrepo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,37 @@

describe 'proxy' do
it_behaves_like 'a yumrepo parameter that can be absent', :proxy
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy

it 'accepts _none_' do
described_class.new(
name: 'puppetlabs',
proxy: '_none_',
)
end
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy

it 'accepts an empty string' do
described_class.new(
name: 'puppetlabs',
proxy: '',
)
end

it 'munges \'_none_\' to empty string for EL >= 8' do
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('8')
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
expect(instance[:proxy]).to eq ''
end

it 'does not munges \'_none_\' to empty string for EL < 8' do
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('7')
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
expect(instance[:proxy]).to eq '_none_'
end

it 'does not raise any errors' do
expect { described_class.new(name: 'puppetlabs', proxy: '') }.not_to raise_error
end
end

describe 'proxy_username' do
Expand Down

0 comments on commit c0499f3

Please sign in to comment.