Skip to content

Commit

Permalink
Refs #37604 - Normalize DNS forwarders to an array
Browse files Browse the repository at this point in the history
Previously the documentation showed an example that abused an internal
implementation detail that's no longer allowed with the stricter input
validation.
  • Loading branch information
ekohl committed Jul 15, 2024
1 parent 2ec4fbd commit cabd312
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# forwarders was always an array, but previously it was documented as
# --foreman-proxy-dns-forwarders "192.0.2.1; 192.0.2.2"
fp_mod = answers['foreman_proxy']
if fp_mod.is_a?(Hash) && fp_mod['forwarders']
fp_mod['forwarders'] = fp_mod['forwarders'].flat_map do |forwarder|
forwarder.split(';').map(&:strip)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# forwarders was always an array, but previously it was documented as
# --foreman-proxy-dns-forwarders "192.0.2.1; 192.0.2.2"
fp_mod = answers['foreman_proxy']
if fp_mod.is_a?(Hash) && fp_mod['forwarders']
fp_mod['forwarders'] = fp_mod['forwarders'].flat_map do |forwarder|
forwarder.split(';').map(&:strip)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# forwarders was always an array, but previously it was documented as
# --foreman-proxy-dns-forwarders "192.0.2.1; 192.0.2.2"
fp_mod = answers['foreman_proxy']
if fp_mod.is_a?(Hash) && fp_mod['forwarders']
fp_mod['forwarders'] = fp_mod['forwarders'].flat_map do |forwarder|
forwarder.split(';').map(&:strip)
end
end
33 changes: 33 additions & 0 deletions spec/migrations/20240715095211_normalize_dns_forwarders_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

migration '20240715095211_normalize_dns_forwarders' do
scenarios %w[foreman katello foreman-proxy-content] do
context 'valid array' do
let(:answers) do
{
'foreman_proxy' => {
'forwarders' => ['192.0.2.1', '192.0.2.2'],
},
}
end

it 'leaves the answers untouched' do
expect(migrated_answers['foreman_proxy']['forwarders']).to eq(['192.0.2.1', '192.0.2.2'])
end
end

context 'semicolon separated value' do
let(:answers) do
{
'foreman_proxy' => {
'forwarders' => ['192.0.2.1; 192.0.2.2'],
},
}
end

it 'leaves the answers untouched' do
expect(migrated_answers['foreman_proxy']['forwarders']).to eq(['192.0.2.1', '192.0.2.2'])
end
end
end
end

0 comments on commit cabd312

Please sign in to comment.