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.
153 154 155 156 157 158 |
# File 'lib/resources/users.rb', line 153 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
250 251 252 |
# File 'lib/resources/users.rb', line 250 def deprecated(name, alternative = nil) warn "[DEPRECATION] #{name} is deprecated. #{alternative}" end |
#disabled? ⇒ Boolean
164 165 166 |
# File 'lib/resources/users.rb', line 164 def disabled? identity[:disabled] == true unless identity.nil? end |
#enabled? ⇒ Boolean
168 169 170 |
# File 'lib/resources/users.rb', line 168 def enabled? identity[:disabled] == false unless identity.nil? end |
#exists? ⇒ Boolean
160 161 162 |
# File 'lib/resources/users.rb', line 160 def exists? !identity.nil? && !identity[:username].nil? end |
#gid ⇒ Object
180 181 182 |
# File 'lib/resources/users.rb', line 180 def gid identity[:gid] unless identity.nil? end |
#groupname ⇒ Object Also known as: group
184 185 186 |
# File 'lib/resources/users.rb', line 184 def groupname identity[:groupname] unless identity.nil? end |
#groups ⇒ Object
189 190 191 |
# File 'lib/resources/users.rb', line 189 def groups identity[:groups] unless identity.nil? end |
#has_authorized_key?(_compare_key) ⇒ Boolean
245 246 247 248 |
# File 'lib/resources/users.rb', line 245 def (_compare_key) deprecated('has_authorized_key?') raise NotImplementedError end |
#has_home_directory?(compare_home) ⇒ Boolean
235 236 237 238 |
# File 'lib/resources/users.rb', line 235 def has_home_directory?(compare_home) deprecated('has_home_directory?', "Please use: its('home')") home == compare_home end |
#has_login_shell?(compare_shell) ⇒ Boolean
240 241 242 243 |
# File 'lib/resources/users.rb', line 240 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
230 231 232 233 |
# File 'lib/resources/users.rb', line 230 def has_uid?(compare_uid) deprecated('has_uid?') uid == compare_uid end |
#home ⇒ Object
193 194 195 |
# File 'lib/resources/users.rb', line 193 def home [:home] unless .nil? end |
#maxdays ⇒ Object
returns the maximum days between password changes
207 208 209 |
# File 'lib/resources/users.rb', line 207 def maxdays credentials[:maxdays] unless credentials.nil? end |
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec
223 224 225 226 |
# File 'lib/resources/users.rb', line 223 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
202 203 204 |
# File 'lib/resources/users.rb', line 202 def mindays credentials[:mindays] unless credentials.nil? end |
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec
217 218 219 220 |
# File 'lib/resources/users.rb', line 217 def minimum_days_between_password_change deprecated('minimum_days_between_password_change', "Please use: its('mindays')") mindays end |
#shell ⇒ Object
197 198 199 |
# File 'lib/resources/users.rb', line 197 def shell [:shell] unless .nil? end |
#to_s ⇒ Object
254 255 256 |
# File 'lib/resources/users.rb', line 254 def to_s "User #{@username}" end |
#uid ⇒ Object
176 177 178 |
# File 'lib/resources/users.rb', line 176 def uid identity[:uid] unless identity.nil? end |
#username ⇒ Object
172 173 174 |
# File 'lib/resources/users.rb', line 172 def username identity[:username] unless identity.nil? end |
#warndays ⇒ Object
returns the days for password change warning
212 213 214 |
# File 'lib/resources/users.rb', line 212 def warndays credentials[:warndays] unless credentials.nil? end |