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
- #deprecated(name, alternative = nil) ⇒ Object
- #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.
150 151 152 153 154 155 |
# File 'lib/resources/users.rb', line 150 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
#deprecated(name, alternative = nil) ⇒ Object
247 248 249 |
# File 'lib/resources/users.rb', line 247 def deprecated(name, alternative = nil) warn "[DEPRECATION] #{name} is deprecated. #{alternative}" end |
#disabled? ⇒ Boolean
161 162 163 |
# File 'lib/resources/users.rb', line 161 def disabled? identity[:disabled] == true unless identity.nil? end |
#enabled? ⇒ Boolean
165 166 167 |
# File 'lib/resources/users.rb', line 165 def enabled? identity[:disabled] == false unless identity.nil? end |
#exists? ⇒ Boolean
157 158 159 |
# File 'lib/resources/users.rb', line 157 def exists? !identity.nil? && !identity[:username].nil? end |
#gid ⇒ Object
177 178 179 |
# File 'lib/resources/users.rb', line 177 def gid identity[:gid] unless identity.nil? end |
#groupname ⇒ Object Also known as: group
181 182 183 |
# File 'lib/resources/users.rb', line 181 def groupname identity[:groupname] unless identity.nil? end |
#groups ⇒ Object
186 187 188 |
# File 'lib/resources/users.rb', line 186 def groups identity[:groups] unless identity.nil? end |
#has_authorized_key?(_compare_key) ⇒ Boolean
242 243 244 245 |
# File 'lib/resources/users.rb', line 242 def (_compare_key) deprecated('has_authorized_key?') fail NotImplementedError end |
#has_home_directory?(compare_home) ⇒ Boolean
232 233 234 235 |
# File 'lib/resources/users.rb', line 232 def has_home_directory?(compare_home) deprecated('has_home_directory?', "Please use: its('home')") home == compare_home end |
#has_login_shell?(compare_shell) ⇒ Boolean
237 238 239 240 |
# File 'lib/resources/users.rb', line 237 def has_login_shell?(compare_shell) deprecated('has_login_shell?', "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
227 228 229 230 |
# File 'lib/resources/users.rb', line 227 def has_uid?(compare_uid) deprecated('has_uid?') uid == compare_uid end |
#home ⇒ Object
190 191 192 |
# File 'lib/resources/users.rb', line 190 def home [:home] unless .nil? end |
#maxdays ⇒ Object
returns the maximum days between password changes
204 205 206 |
# File 'lib/resources/users.rb', line 204 def maxdays credentials[:maxdays] unless credentials.nil? end |
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec
220 221 222 223 |
# File 'lib/resources/users.rb', line 220 def maximum_days_between_password_change deprecated('maximum_days_between_password_change', "Please use: its('maxdays')") maxdays end |
#mindays ⇒ Object
returns the minimum days between password changes
199 200 201 |
# File 'lib/resources/users.rb', line 199 def mindays credentials[:mindays] unless credentials.nil? end |
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec
214 215 216 217 |
# File 'lib/resources/users.rb', line 214 def minimum_days_between_password_change deprecated('minimum_days_between_password_change', "Please use: its('mindays')") mindays end |
#shell ⇒ Object
194 195 196 |
# File 'lib/resources/users.rb', line 194 def shell [:shell] unless .nil? end |
#to_s ⇒ Object
251 252 253 |
# File 'lib/resources/users.rb', line 251 def to_s "User #{@username}" end |
#uid ⇒ Object
173 174 175 |
# File 'lib/resources/users.rb', line 173 def uid identity[:uid] unless identity.nil? end |
#username ⇒ Object
169 170 171 |
# File 'lib/resources/users.rb', line 169 def username identity[:username] unless identity.nil? end |
#warndays ⇒ Object
returns the days for password change warning
209 210 211 |
# File 'lib/resources/users.rb', line 209 def warndays credentials[:warndays] unless credentials.nil? end |