Class: Inspec::Resources::User
- Inherits:
-
Object
- Object
- Inspec::Resources::User
- Includes:
- UserManagementSelector
- Defined in:
- lib/inspec/resources/users.rb
Overview
The ‘user` resource handles the special case where only one resource is required
describe user(‘root’) do
it { should exist }
its('uid') { should eq 0 }
its('gid') { should eq 0 }
its('group') { should eq 'root' }
its('groups') { should eq ['root', 'wheel']}
its('home') { should eq '/root' }
its('shell') { should eq '/bin/bash' }
its('mindays') { should eq 0 }
its('maxdays') { should eq 99 }
its('warndays') { should eq 5 }
its('passwordage') { should be >= 0 }
its('maxbadpasswords') { should eq nil } // not yet supported on linux
its('badpasswordattempts') { should eq 0 }
end describe user(‘Administrator’) do
it { should exist }
its('uid') { should eq "S-1-5-21-1759981009-4135989804-1844563890-500" }
its('gid') { should eq nil } // not supported on Windows
its('group') { should eq nil } // not supported on Windows
its('groups') { should eq ['Administrators', 'Users']}
its('home') { should eq '' }
its('shell') { should eq nil } // not supported on Windows
its('mindays') { should eq 0 }
its('maxdays') { should eq 42 }
its('warndays') { should eq nil }
its('passwordage') { should eq 355 }
its('maxbadpasswords') { should eq 0 }
its('badpasswordattempts') { should eq 0 }
end
The following Serverspec matchers are deprecated in favor for direct value access
describe user(‘root’) do
it { should belong_to_group 'root' }
it { should have_uid 0 }
it { should have_home_directory '/root' }
it { should have_login_shell '/bin/bash' }
its('minimum_days_between_password_change') { should eq 0 }
its('maximum_days_between_password_change') { should eq 99 }
end
ServerSpec tests that are not supported:
describe user(‘root’) do
it { should 'ssh-rsa ADg54...3434 [email protected]' }
its(:encrypted_password) { should eq 1234 }
end
Instance Method Summary collapse
- #badpasswordattempts ⇒ Object
- #disabled? ⇒ Boolean
- #domain ⇒ Object
- #enabled? ⇒ Boolean
- #exists? ⇒ Boolean
- #gid ⇒ Object
- #groupname ⇒ Object (also: #group)
- #groups ⇒ Object
- #has_authorized_key?(_compare_key) ⇒ Boolean
- #has_home_directory?(compare_home) ⇒ Boolean
- #has_login_shell?(compare_shell) ⇒ Boolean
-
#has_uid?(compare_uid) ⇒ Boolean
implements rspec has matcher, to be compatible with serverspec @see: github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/has.rb.
- #home ⇒ Object
-
#initialize(username = nil) ⇒ User
constructor
A new instance of User.
- #maxbadpasswords ⇒ Object
-
#maxdays ⇒ Object
returns the maximum days between password changes.
-
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec.
-
#mindays ⇒ Object
returns the minimum days between password changes.
-
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec.
- #passwordage ⇒ Object
- #shell ⇒ Object
- #to_s ⇒ Object
- #uid ⇒ Object
- #userflags ⇒ Object
- #username ⇒ Object
-
#warndays ⇒ Object
returns the days for password change warning.
Methods included from UserManagementSelector
Constructor Details
#initialize(username = nil) ⇒ User
Returns a new instance of User.
170 171 172 173 174 175 |
# File 'lib/inspec/resources/users.rb', line 170 def initialize(username = nil) @username = username # select user provider @user_provider = select_user_manager(inspec.os) return skip_resource "The `user` resource is not supported on your OS yet." if @user_provider.nil? end |
Instance Method Details
#badpasswordattempts ⇒ Object
241 242 243 |
# File 'lib/inspec/resources/users.rb', line 241 def badpasswordattempts credentials[:badpasswordattempts] unless credentials.nil? end |
#disabled? ⇒ Boolean
181 182 183 |
# File 'lib/inspec/resources/users.rb', line 181 def disabled? identity[:disabled] == true unless identity.nil? end |
#domain ⇒ Object
218 219 220 |
# File 'lib/inspec/resources/users.rb', line 218 def domain [:domain] unless .nil? end |
#enabled? ⇒ Boolean
185 186 187 |
# File 'lib/inspec/resources/users.rb', line 185 def enabled? identity[:disabled] == false unless identity.nil? end |
#exists? ⇒ Boolean
177 178 179 |
# File 'lib/inspec/resources/users.rb', line 177 def exists? !identity.nil? && !identity[:username].nil? end |
#gid ⇒ Object
197 198 199 |
# File 'lib/inspec/resources/users.rb', line 197 def gid identity[:gid] unless identity.nil? end |
#groupname ⇒ Object Also known as: group
201 202 203 |
# File 'lib/inspec/resources/users.rb', line 201 def groupname identity[:groupname] unless identity.nil? end |
#groups ⇒ Object
206 207 208 |
# File 'lib/inspec/resources/users.rb', line 206 def groups identity[:groups] unless identity.nil? end |
#has_authorized_key?(_compare_key) ⇒ Boolean
282 283 284 285 |
# File 'lib/inspec/resources/users.rb', line 282 def (_compare_key) Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_authorized_key?` matcher is deprecated. There is no currently implemented alternative") raise NotImplementedError end |
#has_home_directory?(compare_home) ⇒ Boolean
272 273 274 275 |
# File 'lib/inspec/resources/users.rb', line 272 def has_home_directory?(compare_home) Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_home_directory?` matcher is deprecated. Please use `its('home')`.") home == compare_home end |
#has_login_shell?(compare_shell) ⇒ Boolean
277 278 279 280 |
# File 'lib/inspec/resources/users.rb', line 277 def has_login_shell?(compare_shell) Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_login_shell?` matcher is deprecated. Please use `its('shell')`.") shell == compare_shell end |
#has_uid?(compare_uid) ⇒ Boolean
implements rspec has matcher, to be compatible with serverspec @see: github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/has.rb
267 268 269 270 |
# File 'lib/inspec/resources/users.rb', line 267 def has_uid?(compare_uid) Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_uid?` matcher is deprecated.") uid == compare_uid end |
#home ⇒ Object
210 211 212 |
# File 'lib/inspec/resources/users.rb', line 210 def home [:home] unless .nil? end |
#maxbadpasswords ⇒ Object
245 246 247 |
# File 'lib/inspec/resources/users.rb', line 245 def maxbadpasswords credentials[:maxbadpasswords] unless credentials.nil? end |
#maxdays ⇒ Object
returns the maximum days between password changes
232 233 234 |
# File 'lib/inspec/resources/users.rb', line 232 def maxdays credentials[:maxdays] unless credentials.nil? end |
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec
260 261 262 263 |
# File 'lib/inspec/resources/users.rb', line 260 def maximum_days_between_password_change Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `maximum_days_between_password_change` property is deprecated. Please use `maxdays`.") maxdays end |
#mindays ⇒ Object
returns the minimum days between password changes
227 228 229 |
# File 'lib/inspec/resources/users.rb', line 227 def mindays credentials[:mindays] unless credentials.nil? end |
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec
254 255 256 257 |
# File 'lib/inspec/resources/users.rb', line 254 def minimum_days_between_password_change Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `minimum_days_between_password_change` property is deprecated. Please use `mindays`.") mindays end |
#passwordage ⇒ Object
249 250 251 |
# File 'lib/inspec/resources/users.rb', line 249 def passwordage credentials[:passwordage] unless credentials.nil? end |
#shell ⇒ Object
214 215 216 |
# File 'lib/inspec/resources/users.rb', line 214 def shell [:shell] unless .nil? end |
#to_s ⇒ Object
287 288 289 |
# File 'lib/inspec/resources/users.rb', line 287 def to_s "User #{@username}" end |
#uid ⇒ Object
193 194 195 |
# File 'lib/inspec/resources/users.rb', line 193 def uid identity[:uid] unless identity.nil? end |
#userflags ⇒ Object
222 223 224 |
# File 'lib/inspec/resources/users.rb', line 222 def userflags [:userflags] unless .nil? end |
#username ⇒ Object
189 190 191 |
# File 'lib/inspec/resources/users.rb', line 189 def username identity[:username] unless identity.nil? end |
#warndays ⇒ Object
returns the days for password change warning
237 238 239 |
# File 'lib/inspec/resources/users.rb', line 237 def warndays credentials[:warndays] unless credentials.nil? end |