Skip to content

Commit

Permalink
Fix regex double escaping of rabbitmqctl list_policies
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Spreitzer authored and William Yardley committed Aug 17, 2017
1 parent 7b75b79 commit 462cc1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ def self.policies(name, vhost)
# 1 2 3? 4 5 6
# / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0
if line =~ /^(\S+)\s+(\S+)\s+(all|exchanges|queues)?\s*(\S+)\s+(\S+)\s+(\d+)$/
applyto = $3 || 'all'
@policies[vhost][$2] = {
n = $2
applyto = $3 || 'all'
priority = $6
definition = JSON.parse($5)
# be aware that the gsub will reset the captures
# from the regexp above
pattern = $4.to_s.gsub(/\\\\/, '\\')
@policies[vhost][n] = {
:applyto => applyto,
:pattern => $4,
:definition => JSON.parse($5),
:priority => $6}
:pattern => pattern,
:definition => definition,
:priority => priority}
else
raise Puppet::Error, "cannot parse line from list_policies:#{line}"
end
Expand Down
16 changes: 16 additions & 0 deletions spec/acceptance/policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,31 @@ class { '::rabbitmq':
'ha-sync-mode' => 'automatic',
},
}
rabbitmq_policy { 'eu-federation@myhost':
pattern => '^eu\\.',
priority => 0,
applyto => 'all',
definition => {
'federation-upstream-set' => 'all',
},
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)


# Apply twice to ensure no changes the second time.
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero

end

it 'should have the policy' do
shell('rabbitmqctl list_policies -p myhost') do |r|
expect(r.stdout).to match(/myhost.*ha-all.*ha-sync-mode/)
expect(r.stdout).to match(/myhost.*eu-federation/)
expect(r.exit_code).to be_zero
end
end
Expand Down

0 comments on commit 462cc1f

Please sign in to comment.