2015-10-24 09:12:15 +00:00
|
|
|
# encoding: utf-8
|
2016-11-03 21:23:42 +00:00
|
|
|
|
2016-10-24 16:04:29 +00:00
|
|
|
if os[:family] == 'windows'
|
|
|
|
filedata = {
|
|
|
|
user: os_env('COMPUTERNAME').content + '\TestUser'
|
|
|
|
}
|
|
|
|
elsif os[:name] == 'freebsd'
|
2015-10-25 20:36:49 +00:00
|
|
|
filedata = {
|
|
|
|
user: 'root',
|
|
|
|
group: 'wheel',
|
|
|
|
dir_content: "\u0003\u0000",
|
|
|
|
dir_md5sum: '598f4fe64aefab8f00bcbea4c9239abf',
|
|
|
|
dir_sha256sum: '9b4fb24edd6d1d8830e272398263cdbf026b97392cc35387b991dc0248a628f9',
|
|
|
|
}
|
2016-09-01 16:27:00 +00:00
|
|
|
elsif os[:name] == 'aix'
|
2015-12-21 22:08:17 +00:00
|
|
|
filedata = {
|
|
|
|
user: 'root',
|
|
|
|
group: 'system',
|
|
|
|
dir_content: nil,
|
|
|
|
dir_md5sum: nil,
|
|
|
|
dir_sha256sum: nil,
|
|
|
|
}
|
2016-01-28 13:51:54 +00:00
|
|
|
elsif os.solaris?
|
|
|
|
filedata = {
|
|
|
|
user: 'root',
|
|
|
|
group: 'sys',
|
|
|
|
dir_content: nil,
|
|
|
|
dir_md5sum: nil,
|
|
|
|
dir_sha256sum: nil,
|
|
|
|
}
|
2015-10-25 20:36:49 +00:00
|
|
|
else
|
|
|
|
filedata = {
|
|
|
|
user: 'root',
|
|
|
|
group: 'root',
|
|
|
|
dir_content: nil,
|
|
|
|
dir_md5sum: nil,
|
|
|
|
dir_sha256sum: nil,
|
|
|
|
}
|
2015-10-24 09:12:15 +00:00
|
|
|
end
|
|
|
|
|
2015-10-25 20:36:49 +00:00
|
|
|
if os.unix?
|
|
|
|
|
|
|
|
# test regular file
|
|
|
|
describe file('/tmp/file') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_file }
|
|
|
|
|
|
|
|
it { should_not be_directory }
|
|
|
|
it { should_not be_block_device }
|
|
|
|
it { should_not be_character_device }
|
|
|
|
it { should_not be_pipe }
|
|
|
|
it { should_not be_socket }
|
|
|
|
it { should_not be_symlink }
|
|
|
|
it { should_not be_mounted }
|
|
|
|
|
|
|
|
# check owner
|
|
|
|
it { should be_owned_by filedata[:user] }
|
|
|
|
it { should be_grouped_into filedata[:group] }
|
|
|
|
|
|
|
|
# it { should have_mode }
|
|
|
|
its('mode') { should eq 00765 }
|
|
|
|
it { should be_mode 00765 }
|
2016-08-30 17:23:47 +00:00
|
|
|
its('mode') { should cmp '0765' }
|
|
|
|
its('mode') { should_not cmp '0777' }
|
2016-07-10 18:40:06 +00:00
|
|
|
its('suid') { should eq false }
|
|
|
|
its('sgid') { should eq false }
|
|
|
|
its('sticky') { should eq false }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
it { should be_readable }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_readable.by('owner') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by: 'owner') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_readable.by('group') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by: 'group') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_readable.by('other') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by: 'other') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_readable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by_user: filedata[:user]) }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should_not be_readable.by_user('noroot') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('read', by_user: 'noroot') }
|
2015-10-25 20:36:49 +00:00
|
|
|
# for server spec compatibility
|
|
|
|
it { should be_readable.by('others') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by: 'others') }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
it { should be_writable }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_writable.by('owner') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write', by: 'owner') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_writable.by('group') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write', by: 'group') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should_not be_writable.by('other') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('write', by: 'other') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_writable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write', by_user: filedata[:user]) }
|
2015-10-25 20:36:49 +00:00
|
|
|
# it { should_not be_writable.by_user('noroot') }
|
|
|
|
# for server spec compatibility
|
|
|
|
it { should_not be_writable.by('others') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('write', by: 'others') }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
it { should be_executable }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_executable.by('owner') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by: 'owner') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should_not be_executable.by('group') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('execute', by: 'group') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_executable.by('other') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by: 'other') }
|
2015-10-25 20:36:49 +00:00
|
|
|
it { should be_executable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by_user: filedata[:user]) }
|
2015-10-25 20:36:49 +00:00
|
|
|
# it { should_not be_executable.by_user('noroot') }
|
|
|
|
# for server spec compatibility
|
|
|
|
it { should be_executable.by('others') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by: 'others') }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
# test extended linux attributes
|
|
|
|
# it { should be_immutable }
|
|
|
|
|
|
|
|
its('content') { should eq 'hello world' }
|
|
|
|
its('content') { should match('world') }
|
2016-11-03 19:32:43 +00:00
|
|
|
its('content') { should include('hello') }
|
2015-10-25 20:36:49 +00:00
|
|
|
its('size') { should eq 11 }
|
|
|
|
its('md5sum') { should eq '5eb63bbbe01eeed093cb22bb8f5acdc3' }
|
|
|
|
its('sha256sum') { should eq 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' }
|
|
|
|
its('product_version') { should eq nil }
|
|
|
|
its('file_version') { should eq nil }
|
2016-04-29 17:28:34 +00:00
|
|
|
its('basename') { should cmp 'file' }
|
|
|
|
its('path') { should cmp '/tmp/file' }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
its('owner') { should eq filedata[:user] }
|
|
|
|
its('group') { should eq filedata[:group] }
|
|
|
|
its('type') { should eq :file }
|
|
|
|
end
|
|
|
|
|
2016-11-03 21:23:42 +00:00
|
|
|
# see mount_spec.rb for file mount tests
|
|
|
|
# describe file('/mnt/iso-disk') do
|
|
|
|
# it { should be_mounted }
|
|
|
|
# ...
|
|
|
|
# end
|
|
|
|
|
2016-09-01 16:27:00 +00:00
|
|
|
describe file('/tmp/sfile') do
|
File Resource: add be_setgid, be_setuid, be_sticky matchers (#2104)
* Provisioner script to setup resource tests for setgid/setuid/sticky bit tests. This appears to be the correct mechanism per docker_run, but I don't see any other provisioner scripts, so I suspect there is a different Chef-internal mechanism at play here.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* TDD Red for setgid/setuid/sticky File matchers
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Add documentation for file resource sgid, sticky, and suid matchers
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Add matchers to File for setgid, setuid, and sticky by aliasing existing predicates; TDD green
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Rubocop prefers alias to alias_method.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Lint before pushing, of course
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Correct spelling of setgid and setuid matchers in docs
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Add be_setgid, be_setuid, be_sticky matcher integration tests for File.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Revert "Provisioner script to setup resource tests for setgid/setuid/sticky bit tests. This appears to be the correct mechanism per docker_run, but I don't see any other provisioner scripts, so I suspect there is a different Chef-internal mechanism at play here."
This reverts commit 42e672f3b1cea824451f23bb825b486baaa77c02.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
* Revert "TDD Red for setgid/setuid/sticky File matchers"
This reverts commit a4f891fc7e47bad3096b6a1afd6e8f92fb3f8077.
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2017-09-03 18:43:13 +00:00
|
|
|
it { should be_setgid }
|
|
|
|
it { should be_setuid }
|
|
|
|
it { should be_sticky }
|
|
|
|
|
|
|
|
# These may eventually be deprecated
|
2016-07-10 18:40:06 +00:00
|
|
|
its('suid') { should eq true }
|
|
|
|
its('sgid') { should eq true }
|
|
|
|
its('sticky') { should eq true }
|
|
|
|
end
|
|
|
|
|
2015-10-25 20:36:49 +00:00
|
|
|
describe file('/tmp/folder') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_directory }
|
|
|
|
|
|
|
|
it { should_not be_file }
|
|
|
|
it { should_not be_block_device }
|
|
|
|
it { should_not be_character_device }
|
|
|
|
it { should_not be_pipe }
|
|
|
|
it { should_not be_socket }
|
|
|
|
it { should_not be_symlink }
|
|
|
|
|
|
|
|
its('content') { should eq filedata[:dir_content] }
|
|
|
|
its('md5sum') { should eq filedata[:dir_md5sum] }
|
|
|
|
its('sha256sum') { should eq filedata[:dir_sha256sum] }
|
|
|
|
its('product_version') { should eq nil }
|
|
|
|
its('file_version') { should eq nil }
|
2016-04-29 17:28:34 +00:00
|
|
|
its('basename') { should cmp 'folder' }
|
|
|
|
its('path') { should cmp '/tmp/folder' }
|
2015-10-25 20:36:49 +00:00
|
|
|
|
|
|
|
its('owner') { should eq filedata[:user] }
|
|
|
|
its('group') { should eq filedata[:group] }
|
|
|
|
its('type') { should eq :directory }
|
|
|
|
end
|
2016-01-28 13:51:54 +00:00
|
|
|
end
|
2015-10-25 20:36:49 +00:00
|
|
|
|
2016-01-28 13:51:54 +00:00
|
|
|
if os.windows?
|
2016-04-29 17:28:34 +00:00
|
|
|
describe file('C:\Windows') do
|
2015-12-31 00:10:39 +00:00
|
|
|
it { should exist }
|
|
|
|
it { should be_directory }
|
2016-04-29 17:28:34 +00:00
|
|
|
its('basename') { should cmp 'Windows' }
|
|
|
|
its('path') { should cmp "C:\\Windows" }
|
2015-12-31 00:10:39 +00:00
|
|
|
end
|
2016-03-18 20:32:43 +00:00
|
|
|
|
2016-10-24 16:04:29 +00:00
|
|
|
describe file('C:/Test Directory/test file.txt') do
|
2016-03-18 20:32:43 +00:00
|
|
|
it { should exist }
|
|
|
|
it { should be_file }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_readable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_writable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_executable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_readable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('read', by_user: filedata[:user]) }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_writable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('write', by_user: filedata[:user]) }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_executable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('execute', by_user: filedata[:user]) }
|
2016-03-18 20:32:43 +00:00
|
|
|
end
|
|
|
|
|
2016-10-24 16:04:29 +00:00
|
|
|
describe file('C:/Test Directory') do
|
2016-03-18 20:32:43 +00:00
|
|
|
it { should exist }
|
|
|
|
it { should be_directory }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_readable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('read', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_writable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('write', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should be_executable.by_user('NT AUTHORITY\SYSTEM') }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('execute', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_readable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('read', by_user: filedata[:user]) }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_writable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('write', by_user: filedata[:user]) }
|
2016-10-24 16:04:29 +00:00
|
|
|
it { should_not be_executable.by_user(filedata[:user]) }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should_not be_allowed('execute', by_user: filedata[:user]) }
|
2016-03-18 20:32:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe file("C:/Program Files (x86)/Windows NT/Accessories/wordpad.exe") do
|
|
|
|
it { should exist }
|
|
|
|
# Only works on Windows 2012 R2
|
|
|
|
its('file_version') { should eq '6.3.9600.17415' }
|
|
|
|
end
|
2016-08-16 12:57:34 +00:00
|
|
|
|
|
|
|
# read the owner of a file
|
|
|
|
describe directory('C:/opscode/chef') do
|
|
|
|
its('owner') { should cmp 'NT AUTHORITY\SYSTEM' }
|
|
|
|
it { should be_owned_by 'NT AUTHORITY\SYSTEM' }
|
2017-10-17 13:01:51 +00:00
|
|
|
it { should be_allowed('full-control', by_user: 'NT AUTHORITY\SYSTEM') }
|
|
|
|
it { should be_allowed('modify', by_user: 'NT AUTHORITY\SYSTEM') }
|
2016-08-16 12:57:34 +00:00
|
|
|
end
|
2015-10-24 09:12:15 +00:00
|
|
|
end
|