inspec/test/integration/default/user_spec.rb

99 lines
2.1 KiB
Ruby
Raw Normal View History

2015-10-22 21:54:24 +00:00
# encoding: utf-8
2016-01-28 13:51:54 +00:00
if ['centos', 'redhat', 'fedora', 'opensuse', 'debian', 'ubuntu'].include?(os[:family])
2015-10-22 21:54:24 +00:00
userinfo = {
name: 'root',
group: 'root',
uid: 0,
gid: 0,
groups: ["root"],
home: '/root',
shell: '/bin/bash',
}
# different groupset for centos 5
2015-12-19 00:45:26 +00:00
userinfo[:groups] = ["root", "bin", "daemon", "sys", "adm", "disk", "wheel"] \
if os[:release].to_i == 5
2016-01-28 13:51:54 +00:00
elsif ['freebsd'].include?(os[:family])
2015-10-22 21:54:24 +00:00
userinfo = {
name: 'root',
group: 'wheel',
uid: 0,
gid: 0,
2016-01-28 13:51:54 +00:00
groups: "wheel", # at least this group should be there
2015-10-22 21:54:24 +00:00
home: '/root',
shell: '/bin/csh',
}
2016-01-28 13:51:54 +00:00
elsif os.windows?
userinfo = {
name: 'Administrator',
group: nil,
uid: nil,
gid: nil,
groups: nil,
home: nil,
shell: nil,
}
2016-01-28 13:51:54 +00:00
elsif os[:family] == 'aix'
2015-12-19 00:45:26 +00:00
userinfo = {
name: 'bin',
group: 'bin',
uid: 2,
gid: 2,
2016-01-28 13:51:54 +00:00
groups: "adm", # at least this group should be there
2015-12-19 00:45:26 +00:00
home: '/bin',
shell: nil,
#mindays: 0,
#maxdays: 0,
warndays: 0,
}
2016-01-28 13:51:54 +00:00
elsif os.solaris?
if os[:release].to_i > 10
userinfo = {
name: 'root',
group: 'root',
uid: 0,
gid: 0,
groups: "sys", # at least this group should be there
home: '/root',
shell: '/usr/bin/bash',
}
else
userinfo = {
name: 'root',
group: 'root',
uid: 0,
gid: 0,
groups: "sys", # at least this group should be there
home: '/',
shell: '/sbin/sh',
}
end
2015-10-22 21:54:24 +00:00
else
userinfo = {}
end
2016-01-28 13:51:54 +00:00
if os.windows?
describe user(userinfo[:name]) do
it { should exist }
# should return the SID of the user
its('uid') { should_not eq nil}
end
else
describe user(userinfo[:name]) do
it { should exist }
2015-12-19 00:45:26 +00:00
userinfo.each do |k, v|
next if k.to_sym == :name
2016-01-28 13:51:54 +00:00
# check that the user is part of the groups
if k.to_s == 'groups'
2016-05-10 17:23:11 +00:00
# TODO: do not run those tests on docker yet
its(k) { should include v } unless ENV['DOCKER']
2016-01-28 13:51:54 +00:00
# default eq comparison
else
its(k) { should eq v }
end
2015-12-19 00:45:26 +00:00
end
end
2015-10-22 21:54:24 +00:00
end