inspec/test/unit/mock/files
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
..
9.5.main New postgres_ident_conf resource (#1963) 2017-07-03 20:01:40 +02:00
var.9.5.main New postgres_ident_conf resource (#1963) 2017-07-03 20:01:40 +02:00
xinetd.d filter xinetd fields by regex 2016-02-26 14:46:51 +01:00
aide.conf aide_conf resource: test configuration of the AIDE file integrity tool (#2063) 2017-08-25 22:13:43 +02:00
apache2.conf [resources/apache_conf]: add tests, fix bug 2015-12-07 10:50:48 +01:00
auditd.conf add audit_daemon resource test cases 2015-09-21 14:12:11 +02:00
bond0 move mock files to new sub-directory 2015-09-21 13:43:09 +02:00
crondotd Allow crontab resource to read crontab at user specified paths. (#2328) 2017-12-07 13:50:07 +01:00
default.toml Adding toml resource (#1924) 2017-06-15 16:54:12 -04:00
default.xml Add support for XML files (#2107) 2017-08-31 09:56:14 +02:00
dh_params.dh_pem Fix #1617 Add dh_params resource (#1618) 2017-04-04 10:34:09 -04:00
emptyfile Add nil check for sshd config file (#2217) 2017-10-06 15:41:48 +02:00
etcgroup Support mixed-case group entries (#2101) 2017-08-30 22:02:45 +02:00
example.csv Fix ObjectTraverser when accessing array values 2017-03-15 11:35:55 +01:00
fstab etc_fstab resource: test contents of the /etc/fstab file (#2064) 2017-09-11 15:55:03 +02:00
fstab_no_home etc_fstab resource: test contents of the /etc/fstab file (#2064) 2017-09-11 15:55:03 +02:00
fstab_one_mount etc_fstab resource: test contents of the /etc/fstab file (#2064) 2017-09-11 15:55:03 +02:00
grub.conf added tests for grub_conf resource 2016-04-17 10:46:29 -04:00
hosts etc_hosts resource: test the contents of the /etc/hosts file (#2065) 2017-08-31 09:51:39 -04:00
hosts.allow 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
hosts.deny 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
httpd.conf Added unit tests for apache_conf inclusion of symlinked files. 2017-02-24 16:13:22 +11:00
inetd.conf add unit test for inetd_conf 2015-09-21 14:05:42 +02:00
kitchen.yml Support symbol keys in ObjectTraverser (#2221) 2017-10-06 19:24:31 +02:00
limits.conf add unit test for limits.conf 2015-09-21 14:03:24 +02:00
login.defs add login_def resource unit test 2015-09-21 14:01:51 +02:00
mysql.conf add mysql unit tests 2015-09-22 02:15:42 +02:00
mysql2.conf add mysql unit tests 2015-09-22 02:15:42 +02:00
nginx.conf Add wildcard/multiple server support to nginx_conf resource (#2141) 2017-09-15 16:37:57 -04:00
nginx_confd_foobar.conf Add wildcard/multiple server support to nginx_conf resource (#2141) 2017-09-15 16:37:57 -04:00
nginx_confd_multiple.conf Add wildcard/multiple server support to nginx_conf resource (#2141) 2017-09-15 16:37:57 -04:00
nginx_failed.conf add nginx_conf resource (#1889) 2017-06-26 06:37:41 -07:00
nginx_mime.types add nginx_conf resource (#1889) 2017-06-26 06:37:41 -07:00
nginx_proxy.conf add nginx_conf resource (#1889) 2017-06-26 06:37:41 -07:00
ntp.conf add ntp unit test 2015-09-21 13:57:42 +02:00
passwd expose all fields + deprecate singular accessors 2016-02-18 16:10:42 +01:00
pg_hba.conf New postgres_hba_conf resource (#1964) 2017-07-03 20:13:51 +02:00
pg_ident.conf New postgres_ident_conf resource (#1963) 2017-07-03 20:01:40 +02:00
policyfile.lock.json extend json tests, remove dot-resolver 2015-10-27 15:58:02 +01:00
ports.conf [resources/apache_conf]: add tests, fix bug 2015-12-07 10:50:48 +01:00
postgresql.conf Fixes the postgres_conf parsing of complex paramerters (#1938) 2017-06-23 08:31:27 -07:00
rabbitmq.config add rabbitmq config resource 2017-04-12 20:51:12 +02:00
rootwrap.conf implement unit tests for ini resource 2015-11-24 16:46:17 +01:00
security.conf Added unit tests for apache_conf inclusion of symlinked files. 2017-02-24 16:13:22 +11:00
serve-cgi-bin.conf [resources/apache_conf]: add tests, fix bug 2015-12-07 10:50:48 +01:00
shadow add shadow resource for /etc/shadow 2016-02-19 14:26:04 +01:00
ssh_config ssh_config parse should be case insensitive 2016-08-16 10:01:10 +02:00
sshd_config move mock files to new sub-directory 2015-09-21 13:43:09 +02:00
ssl.conf added unit tests 2016-09-02 21:55:28 -04:00
status.conf In ApacheConf#include_files, check for abs paths 2016-09-20 09:11:09 -04:00
sysctl.conf add params and content method to parse_config 2016-08-05 12:13:56 +02:00
test_ca_public.key.pem Initial support for x509_certificate and rsa_key 2017-03-22 10:00:48 +01:00
test_certificate.rsa.crt.pem Initial support for x509_certificate and rsa_key 2017-03-22 10:00:48 +01:00
test_certificate.rsa.key.pem Initial support for x509_certificate and rsa_key 2017-03-22 10:00:48 +01:00
upstart_ssh_enabled.conf Modify Upstart enabled check to use config file (#2163) 2017-09-21 12:21:34 -04:00
xinetd.conf add xinetd_conf resource 2016-02-26 13:19:16 +01:00
xinetd.d_chargen-dgram catch newline issues in xinet.d (#2043) 2017-08-02 16:43:55 +02:00
xinetd.d_chargen-stream define protocol as done in CentOS 2017-01-31 14:47:21 +00:00
xinetd.d_echo Fix xinetd parsing of services from the same file. Expose resource.protocols 2017-01-31 12:40:29 +00:00