Skip to content
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