Class: Inspec::Resources::User
- Inherits:
- 
      Object
      
        - Object
- Inspec::Resources::User
 
- Includes:
- UserManagementSelector
- Defined in:
- lib/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 }
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
- #disabled? ⇒ Boolean
- #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. 
- 
  
    
      #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. 
- #shell ⇒ Object
- #to_s ⇒ Object
- #uid ⇒ 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.
| 151 152 153 154 155 156 | # File 'lib/resources/users.rb', line 151 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
#disabled? ⇒ Boolean
| 162 163 164 | # File 'lib/resources/users.rb', line 162 def disabled? identity[:disabled] == true unless identity.nil? end | 
#enabled? ⇒ Boolean
| 166 167 168 | # File 'lib/resources/users.rb', line 166 def enabled? identity[:disabled] == false unless identity.nil? end | 
#exists? ⇒ Boolean
| 158 159 160 | # File 'lib/resources/users.rb', line 158 def exists? !identity.nil? && !identity[:username].nil? end | 
#gid ⇒ Object
| 178 179 180 | # File 'lib/resources/users.rb', line 178 def gid identity[:gid] unless identity.nil? end | 
#groupname ⇒ Object Also known as: group
| 182 183 184 | # File 'lib/resources/users.rb', line 182 def groupname identity[:groupname] unless identity.nil? end | 
#groups ⇒ Object
| 187 188 189 | # File 'lib/resources/users.rb', line 187 def groups identity[:groups] unless identity.nil? end | 
#has_authorized_key?(_compare_key) ⇒ Boolean
| 243 244 245 246 | # File 'lib/resources/users.rb', line 243 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
| 233 234 235 236 | # File 'lib/resources/users.rb', line 233 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
| 238 239 240 241 | # File 'lib/resources/users.rb', line 238 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
| 228 229 230 231 | # File 'lib/resources/users.rb', line 228 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
| 191 192 193 | # File 'lib/resources/users.rb', line 191 def home [:home] unless .nil? end | 
#maxdays ⇒ Object
returns the maximum days between password changes
| 205 206 207 | # File 'lib/resources/users.rb', line 205 def maxdays credentials[:maxdays] unless credentials.nil? end | 
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec
| 221 222 223 224 | # File 'lib/resources/users.rb', line 221 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
| 200 201 202 | # File 'lib/resources/users.rb', line 200 def mindays credentials[:mindays] unless credentials.nil? end | 
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec
| 215 216 217 218 | # File 'lib/resources/users.rb', line 215 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 | 
#shell ⇒ Object
| 195 196 197 | # File 'lib/resources/users.rb', line 195 def shell [:shell] unless .nil? end | 
#to_s ⇒ Object
| 248 249 250 | # File 'lib/resources/users.rb', line 248 def to_s "User #{@username}" end | 
#uid ⇒ Object
| 174 175 176 | # File 'lib/resources/users.rb', line 174 def uid identity[:uid] unless identity.nil? end | 
#username ⇒ Object
| 170 171 172 | # File 'lib/resources/users.rb', line 170 def username identity[:username] unless identity.nil? end | 
#warndays ⇒ Object
returns the days for password change warning
| 210 211 212 | # File 'lib/resources/users.rb', line 210 def warndays credentials[:warndays] unless credentials.nil? end |