From 20f892fe659c066649b6297175f0508ef7e95c94 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Wed, 13 Jun 2018 21:22:49 +0200 Subject: [PATCH] (PUP-8943) Match full selmodule name in exists? check Add a beginning-of-line marker to the regex to match the complete selmodule name. If not matching the beginning of the line, a modulename of `foo` also matches for a moudlename of `myfoo`. This is ported from https://github.com/puppetlabs/puppet/pull/6883 --- lib/puppet/provider/selmodule/semodule.rb | 2 +- spec/unit/provider/selmodule_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/selmodule/semodule.rb b/lib/puppet/provider/selmodule/semodule.rb index b292305..c3c92ee 100644 --- a/lib/puppet/provider/selmodule/semodule.rb +++ b/lib/puppet/provider/selmodule/semodule.rb @@ -22,7 +22,7 @@ def exists? debug "Checking for module #{@resource[:name]}" execpipe("#{command(:semodule)} --list") do |out| out.each_line do |line| - if line =~ %r{#{@resource[:name]}\b} + if line =~ %r{^#{@resource[:name]}\b} return :true end end diff --git a/spec/unit/provider/selmodule_spec.rb b/spec/unit/provider/selmodule_spec.rb index c994ba3..1d05a8f 100644 --- a/spec/unit/provider/selmodule_spec.rb +++ b/spec/unit/provider/selmodule_spec.rb @@ -27,6 +27,12 @@ expect(provider.exists?).to be_nil end + it 'returns nil if module with same suffix is loaded' do + allow(provider).to receive(:command).with(:semodule).and_return '/usr/sbin/semodule' + allow(provider).to receive(:execpipe).with('/usr/sbin/semodule --list').and_yield StringIO.new("bar\t1.2.3\nmyfoo\t1.0.0\n") + expect(provider.exists?).to be_nil + end + it 'returns nil if no modules are loaded' do allow(provider).to receive(:command).with(:semodule).and_return '/usr/sbin/semodule' allow(provider).to receive(:execpipe).with('/usr/sbin/semodule --list').and_yield StringIO.new('')