From 068d5de4f808946972551a25f43a1832805550f1 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Wed, 23 Sep 2015 12:23:04 -0400 Subject: [PATCH 1/4] Adds the 'root_user' Ohai attribute. This abstracts out the root user information just as the root group information is. It makes the appropriate name available via the root_user attribute. --- lib/ohai/plugins/root_user.rb | 28 ++++++++++++++++++++++ spec/unit/plugins/root_user_spec.rb | 36 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 lib/ohai/plugins/root_user.rb create mode 100644 spec/unit/plugins/root_user_spec.rb diff --git a/lib/ohai/plugins/root_user.rb b/lib/ohai/plugins/root_user.rb new file mode 100644 index 000000000..9e659fc55 --- /dev/null +++ b/lib/ohai/plugins/root_user.rb @@ -0,0 +1,28 @@ +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Ohai.plugin(:RootUser) do + provides 'root_user' + + collect_data do + case ::RbConfig::CONFIG['host_os'] + when /mswin|mingw32|windows/ + root_user 'SYSTEM' + else + root_user 'root' + end + end +end diff --git a/spec/unit/plugins/root_user_spec.rb b/spec/unit/plugins/root_user_spec.rb new file mode 100644 index 000000000..ab78fb666 --- /dev/null +++ b/spec/unit/plugins/root_user_spec.rb @@ -0,0 +1,36 @@ +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') + +describe Ohai::System, 'root_user' do + before(:each) do + @plugin = get_plugin('root_user') + @plugin.run + end + + describe 'with windows platform' do + it 'should return the user system' do + expect(@plugin[:root_user]).to eq('SYSTEM') + end + end + + describe 'with posix platform' do + it 'should return the user root' do + expect(@plugin[:root_user]).to eq('root') + end + end +end From 9c4a621f5c7c7788d3ca1aecb9ae0c0fefb72a8f Mon Sep 17 00:00:00 2001 From: Shahul Khajamohideen Date: Mon, 28 Dec 2015 13:30:37 -0500 Subject: [PATCH 2/4] Use os plugin to get root_user --- lib/ohai/plugins/root_user.rb | 5 +++-- spec/unit/plugins/root_user_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ohai/plugins/root_user.rb b/lib/ohai/plugins/root_user.rb index 9e659fc55..799624a97 100644 --- a/lib/ohai/plugins/root_user.rb +++ b/lib/ohai/plugins/root_user.rb @@ -16,10 +16,11 @@ Ohai.plugin(:RootUser) do provides 'root_user' + depends 'os' collect_data do - case ::RbConfig::CONFIG['host_os'] - when /mswin|mingw32|windows/ + case os + when 'windows' root_user 'SYSTEM' else root_user 'root' diff --git a/spec/unit/plugins/root_user_spec.rb b/spec/unit/plugins/root_user_spec.rb index ab78fb666..367d2d4ab 100644 --- a/spec/unit/plugins/root_user_spec.rb +++ b/spec/unit/plugins/root_user_spec.rb @@ -22,13 +22,13 @@ @plugin.run end - describe 'with windows platform' do + describe 'on windows', :windows_only do it 'should return the user system' do expect(@plugin[:root_user]).to eq('SYSTEM') end end - describe 'with posix platform' do + describe 'on unix based platforms', :unix_only do it 'should return the user root' do expect(@plugin[:root_user]).to eq('root') end From e935d76e3db4786afc7118ab7a9d99988b19ac74 Mon Sep 17 00:00:00 2001 From: Shahul Khajamohideen Date: Mon, 28 Dec 2015 13:42:21 -0500 Subject: [PATCH 3/4] Fix root_user plugin specs --- spec/unit/plugins/root_user_spec.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/spec/unit/plugins/root_user_spec.rb b/spec/unit/plugins/root_user_spec.rb index 367d2d4ab..ca8140380 100644 --- a/spec/unit/plugins/root_user_spec.rb +++ b/spec/unit/plugins/root_user_spec.rb @@ -17,20 +17,25 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, 'root_user' do - before(:each) do - @plugin = get_plugin('root_user') - @plugin.run - end - + let(:plugin) { get_plugin('root_user') } describe 'on windows', :windows_only do + before(:each) do + allow(plugin).to receive(:collect_os).and_return(:windows) + plugin.run + end + it 'should return the user system' do - expect(@plugin[:root_user]).to eq('SYSTEM') + expect(plugin[:root_user]).to eq('SYSTEM') end end - describe 'on unix based platforms', :unix_only do + describe 'on unix based platforms' do + before(:each) do + plugin.run + end + it 'should return the user root' do - expect(@plugin[:root_user]).to eq('root') + expect(plugin[:root_user]).to eq('root') end end end From 7c8747335c824dc04d485538b05f552d329481c3 Mon Sep 17 00:00:00 2001 From: Shahul Hameed Date: Mon, 28 Dec 2015 14:25:13 -0500 Subject: [PATCH 4/4] Use platform specific collect_data for root_user --- lib/ohai/plugins/root_user.rb | 14 ++++++-------- spec/unit/plugins/root_user_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/ohai/plugins/root_user.rb b/lib/ohai/plugins/root_user.rb index 799624a97..19f40c450 100644 --- a/lib/ohai/plugins/root_user.rb +++ b/lib/ohai/plugins/root_user.rb @@ -16,14 +16,12 @@ Ohai.plugin(:RootUser) do provides 'root_user' - depends 'os' - collect_data do - case os - when 'windows' - root_user 'SYSTEM' - else - root_user 'root' - end + collect_data(:windows) do + root_user 'SYSTEM' + end + + collect_data(:default) do + root_user 'root' end end diff --git a/spec/unit/plugins/root_user_spec.rb b/spec/unit/plugins/root_user_spec.rb index ca8140380..8ced199b8 100644 --- a/spec/unit/plugins/root_user_spec.rb +++ b/spec/unit/plugins/root_user_spec.rb @@ -18,9 +18,9 @@ describe Ohai::System, 'root_user' do let(:plugin) { get_plugin('root_user') } + describe 'on windows', :windows_only do before(:each) do - allow(plugin).to receive(:collect_os).and_return(:windows) plugin.run end @@ -29,7 +29,7 @@ end end - describe 'on unix based platforms' do + describe 'on unix based platforms', :unix_only do before(:each) do plugin.run end