Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression test for special chars in comments #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/puppet/provider/sshd_config_match/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def create

def comment
augopen do |aug|
name = Regexp.escape(resource[:name])
comment = aug.get('$resource/Settings/#comment[1]')
comment&.sub!(%r{^#{resource[:name]}:\s*}i, '')
comment&.sub!(%r{^#{name}:\s*}i, '')
comment || ''
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/unit/puppet/provider/sshd_config_match/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@
end
end

context 'with condition containing regex chars' do
let(:tmptarget) { aug_fixture('empty') }
let(:target) { tmptarget.path }

it 'creates simple new entry' do
apply!(Puppet::Type.type(:sshd_config_match).new(
name: 'Host *',
target: target,
ensure: :present,
provider: 'augeas'
))

aug_open(target, 'Sshd.lns') do |aug|
expect(aug.get('Match/Condition/Host')).to eq('*')
end
end

it 'creates new comment before entry' do
apply!(Puppet::Type.type(:sshd_config_match).new(
name: 'Host *',
target: target,
ensure: :present,
comment: 'manage host *',
provider: 'augeas'
))

aug_open(target, 'Sshd.lns') do |aug|
expect(aug.get('Match[Condition/Host]/Settings/#comment')).to eq('Host *: manage host *')
end
end
end

context 'with full file' do
let(:tmptarget) { aug_fixture('full') }
let(:target) { tmptarget.path }
Expand Down
Loading