Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9749558
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/lib/facter/sudoversion.rb b/lib/facter/sudoversion.rb
index c2c8351..cf80bdf 100644
--- a/lib/facter/sudoversion.rb
+++ b/lib/facter/sudoversion.rb
@@ -1,10 +1,13 @@
require 'puppet'
-Facter.add('sudoversion') do
+Facter.add(:sudoversion) do
setcode do
- if Facter::Util::Resolution.which('rpm')
+ if Facter::Util::Resolution.which('sudo')
+ sudoversion = Facter::Util::Resolution.exec('sudo -V 2>&1')
+ %r{^Sudo version ([\w\.]+)}.match(sudoversion)[1]
+ elsif Facter::Util::Resolution.which('rpm')
Facter::Util::Resolution.exec('rpm -q sudo --qf \'%{VERSION}\'')
- elsif Facter::Util::Resolution.which('sudo') && Facter::Util::Resolution.which('awk')
- Facter::Util::Resolution.exec('sudo -V | awk \'/Sudo version/ {print $3}\'')
+ elsif Facter::Util::Resolution.which('dpkg-query')
+ Facter::Util::Resolution.exec('dpkg-query -W -f=\'${Version}\n\' sudo')
end
end
end
diff --git a/spec/unit/sudoversion_spec.rb b/spec/unit/sudoversion_spec.rb
new file mode 100644
index 0000000..f1e194e
--- /dev/null
+++ b/spec/unit/sudoversion_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Facter::Util::Fact do
+ before do
+ Facter.clear
+ end
+
+ describe 'sudoversion' do
+ context 'with value' do
+ before :each do
+ Facter::Util::Resolution.stubs(:which).with('sudo').returns(true)
+ Facter::Util::Resolution.stubs(:exec).with('sudo -V 2>&1').returns('Sudo version 1.7.10p9')
+ end
+ it do
+ expect(Facter.fact(:sudoversion).value).to eq('1.7.10p9')
+ end
+ end
+ end
+end
+
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Aug 25, 5:57 PM (4 d, 10 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3328178
Attached To
rSPSUDO puppet-saz-sudo
Event Timeline
Log In to Comment