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

WIP: Adds the 'root_user' Ohai attribute. #624

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 28 additions & 0 deletions lib/ohai/plugins/root_user.rb
Original file line number Diff line number Diff line change
@@ -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']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more resilient to have this plugin declare a dependency on the 'os' attribute and then case os. On Windows, os returns 'windows' (see: https://github.com/chef/ohai/blob/master/lib/ohai/mixin/os.rb#L50).

when /mswin|mingw32|windows/
root_user 'SYSTEM'
else
root_user 'root'
end
end
end
36 changes: 36 additions & 0 deletions spec/unit/plugins/root_user_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to stub ::RbConfig::CONFIG['host_os'] to return the platform string you'd expect. Otherwise, this spec will always fail on non-Windows systems (and the other check will always fail on Windows).

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