2015-10-06 16:55:44 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-10-05 09:21:25 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-10-05 09:21:25 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::User' do
|
2015-10-05 09:21:25 +00:00
|
|
|
|
|
|
|
# ubuntu 14.04 with upstart
|
|
|
|
it 'read user on ubuntu' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('user', 'root')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'root'
|
|
|
|
_(resource.groups).must_equal ['root']
|
|
|
|
_(resource.home).must_equal '/root'
|
|
|
|
_(resource.shell).must_equal '/bin/bash'
|
2015-10-05 09:40:34 +00:00
|
|
|
_(resource.mindays).must_equal 0
|
|
|
|
_(resource.maxdays).must_equal 99999
|
|
|
|
_(resource.warndays).must_equal 7
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
|
2015-11-24 15:18:55 +00:00
|
|
|
# ubuntu 14.04 test with ldap user
|
|
|
|
it 'read user on ubuntu' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('user', 'jfolmer')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'domain users'
|
|
|
|
_(resource.groups).must_equal ['domain users', 'domain admins', 'denied rodc password replication group']
|
|
|
|
_(resource.home).must_equal '/jfolmer'
|
|
|
|
_(resource.shell).must_equal '/bin/bash'
|
|
|
|
_(resource.mindays).must_equal 0
|
|
|
|
_(resource.maxdays).must_equal 99999
|
|
|
|
_(resource.warndays).must_equal 7
|
|
|
|
end
|
|
|
|
|
2015-10-05 09:21:25 +00:00
|
|
|
# serverspec compatibility tests (do not test matcher)
|
|
|
|
it 'verify serverspec compatibility' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('user', 'root')
|
|
|
|
_(resource.has_uid?(0)).must_equal true
|
|
|
|
_(resource.has_home_directory?('/root')).must_equal true
|
|
|
|
_(resource.has_login_shell?('/bin/bash')).must_equal true
|
2015-10-05 09:40:34 +00:00
|
|
|
_(resource.minimum_days_between_password_change).must_equal 0
|
|
|
|
_(resource.maximum_days_between_password_change).must_equal 99999
|
2015-10-05 09:21:25 +00:00
|
|
|
# _(resource.has_authorized_key?('abc')).must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'read user on centos7' do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource('user', 'root')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'root'
|
|
|
|
_(resource.groups).must_equal ['root']
|
|
|
|
_(resource.home).must_equal '/root'
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.shell).must_equal '/bin/bash'
|
|
|
|
_(resource.mindays).must_equal 0
|
|
|
|
_(resource.maxdays).must_equal 99999
|
|
|
|
_(resource.warndays).must_equal 7
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'read user on centos7' do
|
|
|
|
resource = MockLoader.new(:wrlinux).load_resource('user', 'root')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'root'
|
|
|
|
_(resource.groups).must_equal ['root']
|
|
|
|
_(resource.home).must_equal '/root'
|
2015-10-05 09:21:25 +00:00
|
|
|
_(resource.shell).must_equal '/bin/bash'
|
2015-10-05 09:40:34 +00:00
|
|
|
_(resource.mindays).must_equal 0
|
|
|
|
_(resource.maxdays).must_equal 99999
|
|
|
|
_(resource.warndays).must_equal 7
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
|
2016-04-21 08:31:56 +00:00
|
|
|
it 'read user on hpux' do
|
|
|
|
resource = MockLoader.new(:hpux).load_resource('user', 'root')
|
|
|
|
_(resource.home).must_equal '/'
|
|
|
|
_(resource.shell).must_equal '/sbin/sh'
|
|
|
|
end
|
|
|
|
|
2015-10-05 09:21:25 +00:00
|
|
|
it 'read user on freebsd' do
|
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('user', 'root')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'root'
|
|
|
|
_(resource.groups).must_equal ['root']
|
|
|
|
_(resource.home).must_equal '/root'
|
|
|
|
_(resource.shell).must_equal '/bin/csh'
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.mindays).must_be_nil
|
|
|
|
_(resource.maxdays).must_be_nil
|
|
|
|
_(resource.warndays).must_be_nil
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'read user on OSX' do
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('user', 'chartmann')
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.group).must_equal 'staff'
|
|
|
|
_(resource.groups).must_equal ['staff', 'com.apple.sharepoint.group.1', 'everyone']
|
|
|
|
_(resource.home).must_equal '/Users/chartmann'
|
|
|
|
_(resource.shell).must_equal '/bin/zsh'
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.mindays).must_be_nil
|
|
|
|
_(resource.maxdays).must_be_nil
|
|
|
|
_(resource.warndays).must_be_nil
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
|
2017-04-21 07:45:58 +00:00
|
|
|
it 'read administrator user on Windows' do
|
2016-09-25 22:50:40 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource('user', 'Administrator')
|
2016-08-26 07:40:24 +00:00
|
|
|
_(resource.uid).wont_be_nil
|
2015-10-05 09:21:25 +00:00
|
|
|
_(resource.exists?).must_equal true
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.group).must_be_nil
|
2017-04-20 14:02:21 +00:00
|
|
|
_(resource.groups).must_equal ['Administrators', 'Users']
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.home).must_be_nil
|
|
|
|
_(resource.shell).must_be_nil
|
|
|
|
_(resource.mindays).must_be_nil
|
|
|
|
_(resource.maxdays).must_be_nil
|
|
|
|
_(resource.warndays).must_be_nil
|
2016-09-09 13:03:35 +00:00
|
|
|
_(resource.disabled?).must_equal false
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
|
2017-04-21 07:45:58 +00:00
|
|
|
it 'read guest user on Windows' do
|
|
|
|
resource = MockLoader.new(:windows).load_resource('user', 'Guest')
|
|
|
|
_(resource.uid).wont_be_nil
|
|
|
|
_(resource.exists?).must_equal true
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.group).must_be_nil
|
2017-04-21 07:45:58 +00:00
|
|
|
_(resource.groups).must_equal ['Users']
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.home).must_be_nil
|
|
|
|
_(resource.shell).must_be_nil
|
|
|
|
_(resource.mindays).must_be_nil
|
|
|
|
_(resource.maxdays).must_be_nil
|
|
|
|
_(resource.warndays).must_be_nil
|
2017-04-21 07:45:58 +00:00
|
|
|
_(resource.disabled?).must_equal true
|
|
|
|
end
|
|
|
|
|
2016-09-25 22:50:40 +00:00
|
|
|
it 'read disabled user on Windows' do
|
|
|
|
resource = MockLoader.new(:windows).load_resource('user', 'Guest')
|
|
|
|
_(resource.uid).wont_be_nil
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.disabled?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-10-05 09:21:25 +00:00
|
|
|
it 'read user on undefined os' do
|
2016-09-25 22:50:40 +00:00
|
|
|
resource = MockLoader.new(:undefined).load_resource('user', 'root')
|
2015-10-05 09:21:25 +00:00
|
|
|
_(resource.exists?).must_equal false
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.group).must_be_nil
|
|
|
|
_(resource.groups).must_be_nil
|
|
|
|
_(resource.home).must_be_nil
|
|
|
|
_(resource.shell).must_be_nil
|
|
|
|
_(resource.mindays).must_be_nil
|
|
|
|
_(resource.maxdays).must_be_nil
|
|
|
|
_(resource.warndays).must_be_nil
|
2015-10-05 09:21:25 +00:00
|
|
|
end
|
|
|
|
end
|