inspec/lib/resources
Miah Johnson e33f4959e1 Allow crontab resource to read crontab at user specified paths. (#2328)
* add a emulated /etc/cron.d/crondotd file to the mocking system.

* test that we handle incoming paths correctly by rendering to_s.

* We take in both users and a path, so lets call that destination.

* To make the test pass we'll determine if we are dealing with a path or
a user and return the correct string.

* we will need the ability to determine if we are dealing with a path when either calling the crontab command or reading the file directly, so break that out into a path? method.

* remove author field.

* test contents of our crondotd file.

* we have to explicitly make @destination a String to use include?.

* when we get a path we use inspec.file to get conents, otherwise we run the crontab command.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add documentation for example usage with file path.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Make path? and path_or_user private methods

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add missing username filed to crondotd mock file

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Pass argument as a hash when testing file paths

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Expected results should include usernames when testing file paths

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add special string `@yearly` test to crondotd mock file

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add user to existing cron tests

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Rubocop says I need spaces after/before curly brackets

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add user to crondotd file tests and add @yearly test

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Modify initialize to take options hash and be backwards compatible.

Change initialize default argument to create a hash by default, though
it is still possible to pass in a 'user' string argument.

@user gets set with the argument value unless its a hash, in which case
it tries to set the value of the user key, otherwise it becomes nil.

@file gets set with the value of the path key, unless it doesn't exist
in which case it becomes nil.

All hash keys are symbolized to ensure consistent access.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Check if @path is nil to determine if we run crontab command or parse
file.

path? was removed as we're not overloading a @destination variable
anymore.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* if @user is nil assume current user otherwise crontab for @user

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Change to complete if rather than ternary.

We have three possible cases, current user, other user, or file path.
This accounts for all of them.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add user to the crontab FilterTable

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Remove path? and path_or_user

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Move crontab parsing to two methods, parse_user_crontab and
parse_system_crontab

Because a command in a crontab file could have spaces we must parse user
and system crontabs differently.

When we parse user crontabs the user field will either be nil, or the requested user.

Both user and path parsers handle special strings (@yearly, @weekly,
etc). And also account for position of user in these files (or adds it
in user case)

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Update examples with user: and path:

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add spaces after : in example docs

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Disable rubocop ClassLength check

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Moved rubocop ClassLength metric next to class instead of above the
module.

Remove unnecessary braces.

Add is_system_crontab? and is_user_crontab helper methods and use them.

Add tests to see if error conditions are raised when the resource is
invoked with missing parameters (user, or path), and on a unsupported
os.

Change initialize to group all hash functions together and raise errors
when user and path is unset. Also raise errors on unsupported operating
systems.

Change order of ternary and use is_system_crontab? rather than
@path.nil?

Signed-off-by: Miah Johnson <miah@chia-pet.org>
2017-12-07 13:50:07 +01:00
..
aide_conf.rb aide_conf resource: test configuration of the AIDE file integrity tool (#2063) 2017-08-25 22:13:43 +02:00
apache.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
apache_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
apt.rb improved regex for matching deb sources 2016-11-09 11:10:46 -06:00
audit_policy.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
auditd.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
auditd_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
auditd_rules.rb Add deprecation warning to auditd_rules resource (#2156) 2017-09-18 21:48:04 +02:00
bash.rb remodel bash and shell wrappers 2016-04-18 11:48:42 -04:00
bond.rb rename SimpleConfig / parse_config / parse_config_file options 2017-04-26 23:18:40 +02:00
bridge.rb Address rubocop violations 2017-02-08 16:49:16 -06:00
command.rb Update command resource to check for mock backend. (#2353) 2017-12-05 14:21:31 +01:00
cpan.rb cpan resource: check for Perl module installation (#2254) 2017-10-25 16:01:26 +02:00
cran.rb cran resource: check for R module installation (#2255) 2017-10-25 16:14:29 +02:00
crontab.rb Allow crontab resource to read crontab at user specified paths. (#2328) 2017-12-07 13:50:07 +01:00
csv.rb json resource (et. al.): allow inspec check to succeed when using command (#2317) 2017-11-27 11:13:02 -05:00
dh_params.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
directory.rb Fix directory resource output and exists check (#1950) 2017-06-23 07:44:15 -07:00
docker.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
docker_container.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
docker_image.rb docker_image resource: properly handle registries in image strings (#2356) 2017-12-01 10:24:15 +01:00
elasticsearch.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
etc_fstab.rb etc_fstab resource: properly namespace the resource, add nfs_file_systems documentation (#2190) 2017-10-12 11:30:33 +01:00
etc_group.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
etc_hosts.rb add bsd platform family to etc_hosts resource (#2192) 2017-10-04 22:42:05 +02:00
etc_hosts_allow_deny.rb etc_hosts_allow and etc_hosts_deny resources: test the content of the tcpwrappers configuration files (#2073) 2017-09-25 13:49:04 -04:00
file.rb file resource: fix NilClass error when using advanced windows permissions (#2344) 2017-11-28 09:18:49 +01:00
firewalld.rb firewalld resource: inspect the status and configuration of firewalld (#2074) 2017-09-27 14:05:35 +02:00
gem.rb Fix installed? check for gem resource 2017-05-22 15:34:01 -05:00
groups.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
grub_conf.rb correct the grub path for rhel 7 based os in grub_conf resource (#2332) 2017-11-27 11:39:20 -05:00
host.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
http.rb http resource: properly support HEAD request with remote worker (#2340) 2017-11-27 18:17:39 +01:00
iis_app.rb Adds support for iis_app InSpec testing (#1905) 2017-06-15 11:13:07 +02:00
iis_site.rb add fallback syntax for serverspec tests 2016-12-15 16:16:17 +01:00
inetd_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
ini.rb json resource (et. al.): allow inspec check to succeed when using command (#2317) 2017-11-27 11:13:02 -05:00
interface.rb small syntax fix to interface resource. 2017-05-31 00:20:42 -05:00
iptables.rb Placing all resources in the Inspec::Resources namespace 2016-03-08 13:40:16 -05:00
json.rb json resource: ensure params is not nil in even of read/parse failure (#2354) 2017-11-29 16:31:06 -05:00
kernel_module.rb kernel_module resource: added blacklisting, enabled, disabled, docs and unit tests (#1798) 2017-07-05 11:41:44 +02:00
kernel_parameter.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
key_rsa.rb Fix example in key_rsa.rb (#2364) 2017-12-04 11:59:30 -05:00
limits_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
login_def.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
mount.rb Add FreeBSD support for ZFS datasets and pools 2017-02-22 10:29:49 -07:00
mssql_session.rb quote username and hostname in mssql_session (#2151) 2017-09-18 21:49:20 +02:00
mysql.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
mysql_conf.rb Add clarifying docs for mysql_conf resource (#2138) 2017-09-13 08:16:35 -04:00
mysql_session.rb Fix https://github.com/chef/inspec/issues/2019 (#2020) 2017-07-18 08:28:56 -07:00
nginx.rb nginx resource: audit the nginx binary and how it was compiled (#1958) 2017-09-13 08:15:09 -04:00
nginx_conf.rb Add wildcard/multiple server support to nginx_conf resource (#2141) 2017-09-15 16:37:57 -04:00
npm.rb Placing all resources in the Inspec::Resources namespace 2016-03-08 13:40:16 -05:00
ntp_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
oneget.rb making the examples in the code consistent with rst docs 2016-09-21 11:33:17 +05:30
oracledb_session.rb sqlplus credentials could contain special symbols and need to be escaped (#2308) 2017-11-15 21:49:09 +01:00
os.rb making the examples in the code consistent with rst docs 2016-09-21 11:33:17 +05:30
os_env.rb fix case where skip is called for os_env (#2078) 2017-08-15 21:32:21 +02:00
package.rb package resource: assume a default Homebrew path (#2140) 2017-09-13 08:41:09 -04:00
packages.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
parse_config.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
passwd.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
pip.rb pip resource: support non-default pip locations, such as virtualenvs (#2097) 2017-08-30 22:04:22 +02:00
port.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
postgres.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
postgres_conf.rb Remove any "All Rights Reserved" references (#1969) 2017-06-28 04:14:19 -07:00
postgres_hba_conf.rb New postgres_hba_conf resource (#1964) 2017-07-03 20:13:51 +02:00
postgres_ident_conf.rb New postgres_ident_conf resource (#1963) 2017-07-03 20:01:40 +02:00
postgres_session.rb Properly return postgres query errors on failure (#2179) 2017-09-23 09:27:05 +02:00
powershell.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
processes.rb processes resource: support busybox ps (#2222) 2017-10-06 19:32:39 +02:00
rabbitmq_conf.rb add rabbitmq config resource 2017-04-12 20:51:12 +02:00
registry_key.rb Support array syntax for registry_key resource (#2160) 2017-09-19 18:26:53 +02:00
security_policy.rb security_policy resource: use PID for filename instead of random (#2368) 2017-12-04 15:31:06 -05:00
service.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
shadow.rb fix the shadow password example now that cmp can handle arrays 2016-04-20 11:57:34 -04:00
ssh_conf.rb Add nil check for sshd config file (#2217) 2017-10-06 15:41:48 +02:00
ssl.rb ssl resource: properly raise error when unable to determine if port is enabled (#2205) 2017-10-06 19:38:22 +02:00
sys_info.rb add support for hostname detection on macOS 2017-04-12 12:57:45 +02:00
toml.rb json resource (et. al.): allow inspec check to succeed when using command (#2317) 2017-11-27 11:13:02 -05:00
users.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
vbscript.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
virtualization.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
windows_feature.rb Update inspec for os[:family] change in Train 2016-08-04 13:32:35 +01:00
windows_hotfix.rb Replace WMI query with PowerShell cmdlet "get-hotfix" (#2252) 2017-10-18 12:24:11 +01:00
windows_task.rb Fixing errors reported in Travis 2016-11-20 20:32:48 +00:00
wmi.rb wmi resource: properly escape quotes in WMI query (#2342) 2017-11-29 12:01:44 +01:00
x509_certificate.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
xinetd.rb xinetd_conf resource: fix false positives with config file or directory doesn't exist (#2302) 2017-11-15 15:56:39 -05:00
xml.rb json resource (et. al.): allow inspec check to succeed when using command (#2317) 2017-11-27 11:13:02 -05:00
yaml.rb json resource (et. al.): allow inspec check to succeed when using command (#2317) 2017-11-27 11:13:02 -05:00
yum.rb Bump Rubocop to 0.49.1 (#2323) 2017-11-21 08:49:41 +01:00
zfs_dataset.rb Add FreeBSD support for ZFS datasets and pools 2017-02-22 10:29:49 -07:00
zfs_pool.rb Add FreeBSD support for ZFS datasets and pools 2017-02-22 10:29:49 -07:00