aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance/tests
diff options
context:
space:
mode:
Diffstat (limited to 'spec/acceptance/tests')
-rw-r--r--spec/acceptance/tests/resource/cron/should_allow_changing_parameters.rb74
-rw-r--r--spec/acceptance/tests/resource/cron/should_be_idempotent.rb38
-rw-r--r--spec/acceptance/tests/resource/cron/should_create_cron.rb36
-rw-r--r--spec/acceptance/tests/resource/cron/should_match_existing.rb36
-rw-r--r--spec/acceptance/tests/resource/cron/should_remove_cron.rb39
-rw-r--r--spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace.rb42
-rw-r--r--spec/acceptance/tests/resource/cron/should_remove_matching.rb40
-rw-r--r--spec/acceptance/tests/resource/cron/should_update_existing.rb42
8 files changed, 347 insertions, 0 deletions
diff --git a/spec/acceptance/tests/resource/cron/should_allow_changing_parameters.rb b/spec/acceptance/tests/resource/cron/should_allow_changing_parameters.rb
new file mode 100644
index 0000000..4a14371
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_allow_changing_parameters.rb
@@ -0,0 +1,74 @@
+test_name "Cron: should allow changing parameters after creation"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+
+agents.each do |agent|
+ step "ensure the user exist via puppet"
+ setup agent
+
+ step "Cron: basic - verify that it can be created"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/false", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do
+ assert_match( /ensure: created/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/.bin.false/, result.stdout, "err: #{agent}")
+ end
+
+ step "Cron: allow changing command"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do
+ assert_match(/command changed '.bin.false'.* to '.bin.true'/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/1 . . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+
+ step "Cron: allow changing time"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "1", minute => [1], ensure => present,}') do
+ assert_match(/hour: defined 'hour' as \['1'\]/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/1 1 . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+
+ step "Cron: allow changing time(array)"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => ["1","2"], minute => [1], ensure => present,}') do
+ assert_match(/hour: hour changed \['1'\].* to \['1', '2'\]/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/1 1,2 . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+
+ step "Cron: allow changing time(array modification)"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => ["3","2"], minute => [1], ensure => present,}') do
+ assert_match(/hour: hour changed \['1', '2'\].* to \['3', '2'\]/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/1 3,2 . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+ step "Cron: allow changing time(array modification to *)"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => "*", ensure => present,}') do
+ assert_match(/minute: undefined 'minute' from \['1'\]/,result.stdout, "err: #{agent}")
+ assert_match(/hour: undefined 'hour' from \['3', '2'\]/,result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/\* \* . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+
+end
diff --git a/spec/acceptance/tests/resource/cron/should_be_idempotent.rb b/spec/acceptance/tests/resource/cron/should_be_idempotent.rb
new file mode 100644
index 0000000..0d302c2
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_be_idempotent.rb
@@ -0,0 +1,38 @@
+test_name "Cron: check idempotency"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+
+agents.each do |agent|
+ step "ensure the user exist via puppet"
+ setup agent
+
+ step "Cron: basic - verify that it can be created"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do
+ assert_match( /ensure: created/, result.stdout, "err: #{agent}")
+ end
+ run_cron_on(agent,:list,'tstuser') do
+ assert_match(/. . . . . .bin.true/, result.stdout, "err: #{agent}")
+ end
+
+ step "Cron: basic - should not create again"
+ apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}') do
+ assert_no_match( /ensure: created/, result.stdout, "err: #{agent}")
+ end
+end
diff --git a/spec/acceptance/tests/resource/cron/should_create_cron.rb b/spec/acceptance/tests/resource/cron/should_create_cron.rb
new file mode 100644
index 0000000..7c3b53f
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_create_cron.rb
@@ -0,0 +1,36 @@
+test_name "should create cron"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ setup host
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser",
+ "command=/bin/true", "ensure=present")) do
+ assert_match(/created/, stdout, "Did not create crontab for tstuser on #{host}")
+ end
+
+ step "verify that crontab -l contains what you expected"
+ run_cron_on(host, :list, 'tstuser') do
+ assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Incorrect crontab for tstuser on #{host}")
+ end
+
+end
diff --git a/spec/acceptance/tests/resource/cron/should_match_existing.rb b/spec/acceptance/tests/resource/cron/should_match_existing.rb
new file mode 100644
index 0000000..a59d8ed
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_match_existing.rb
@@ -0,0 +1,36 @@
+test_name "puppet should match existing job"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:unit'
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ setup host
+
+ step "Create the existing cron job by hand..."
+ run_cron_on(host,:add,'tstuser',"* * * * * /bin/true")
+
+ step "Apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser",
+ "command=/bin/true", "ensure=present")) do
+ assert_match(/present/, stdout, "Failed creating crontab for tstuser on #{host}")
+ end
+
+ step "Verify that crontab -l contains what you expected"
+ run_cron_on(host, :list, 'tstuser') do
+ assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Did not find crontab for tstuser on #{host}")
+ end
+end
diff --git a/spec/acceptance/tests/resource/cron/should_remove_cron.rb b/spec/acceptance/tests/resource/cron/should_remove_cron.rb
new file mode 100644
index 0000000..1320272
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_remove_cron.rb
@@ -0,0 +1,39 @@
+test_name "puppet should remove a crontab entry as expected"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ setup host
+
+ step "create the existing job by hand..."
+ run_cron_on(host,:add,'tstuser',"* * * * * /bin/true")
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser",
+ "command=/bin/true", "ensure=absent")) do
+ assert_match(/crontest\D+ensure:\s+removed/, stdout, "Didn't remove crobtab entry for tstuser on #{host}")
+ end
+
+ step "verify that crontab -l contains what you expected"
+ run_cron_on(host, :list, 'tstuser') do
+ assert_no_match(/\/bin\/true/, stderr, "Error: Found entry for tstuser on #{host}")
+ end
+
+end
diff --git a/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace.rb b/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace.rb
new file mode 100644
index 0000000..33f7142
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_remove_leading_and_trailing_whitespace.rb
@@ -0,0 +1,42 @@
+test_name "(#656) leading and trailing whitespace in cron entries should should be stripped"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:unit'
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "create user account for testing cron entries"
+ setup host
+
+ step "apply the resource on the host using puppet resource"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command=' date > /dev/null '", "ensure=present")) do
+ assert_match(/created/, stdout, "Did not create crontab for tstuser on #{host}")
+ end
+
+ step "verify the added crontab entry has stripped whitespace"
+ run_cron_on(host, :list, 'tstuser') do
+ assert_match(/\* \* \* \* \* date > .dev.null/, stdout, "Incorrect crontab for tstuser on #{host}")
+ end
+
+ step "apply the resource with trailing whitespace and check nothing happened"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command='date > /dev/null '", "ensure=present")) do
+ assert_no_match(/ensure: created/, stdout, "Rewrote the line with trailing space in crontab for tstuser on #{host}")
+ end
+
+ step "apply the resource with leading whitespace and check nothing happened"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command=' date > /dev/null'", "ensure=present")) do
+ assert_no_match(/ensure: created/, stdout, "Rewrote the line with trailing space in crontab for tstuser on #{host}")
+ end
+end
diff --git a/spec/acceptance/tests/resource/cron/should_remove_matching.rb b/spec/acceptance/tests/resource/cron/should_remove_matching.rb
new file mode 100644
index 0000000..2857a4f
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_remove_matching.rb
@@ -0,0 +1,40 @@
+test_name "puppet should remove a crontab entry based on command matching"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ setup host
+
+ step "create the existing job by hand..."
+ run_cron_on(host,:add,'tstuser',"* * * * * /bin/true")
+
+ step "Remove cron resource"
+ on(host, puppet_resource("cron", "bogus", "user=tstuser",
+ "command=/bin/true", "ensure=absent")) do
+ assert_match(/bogus\D+ensure: removed/, stdout, "Removing cron entry failed for tstuser on #{host}")
+ end
+
+ step "verify that crontab -l contains what you expected"
+ run_cron_on(host,:list,'tstuser') do
+ count = stdout.scan("/bin/true").length
+ fail_test "found /bin/true the wrong number of times (#{count})" unless count == 0
+ end
+
+end
diff --git a/spec/acceptance/tests/resource/cron/should_update_existing.rb b/spec/acceptance/tests/resource/cron/should_update_existing.rb
new file mode 100644
index 0000000..a4bf177
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_update_existing.rb
@@ -0,0 +1,42 @@
+test_name "puppet should update existing crontab entry"
+confine :except, :platform => 'windows'
+confine :except, :platform => /^eos-/ # See PUP-5500
+confine :except, :platform => /^fedora-28/
+tag 'audit:medium',
+ 'audit:refactor', # Use block style `test_name`
+ 'audit:acceptance' # Could be done at the integration (or unit) layer though
+ # actual changing of resources could irreparably damage a
+ # host running this, or require special permissions.
+
+require 'puppet/acceptance/common_utils'
+extend Puppet::Acceptance::CronUtils
+
+teardown do
+ step "Cron: cleanup"
+ agents.each do |agent|
+ clean agent
+ end
+end
+
+agents.each do |host|
+ step "ensure the user exist via puppet"
+ setup host
+
+ step "create the existing job by hand..."
+ run_cron_on(host,:add,'tstuser',"* * * * * /bin/true")
+
+ step "verify that crontab -l contains what you expected"
+ run_cron_on(host,:list,'tstuser') do
+ assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Didn't find correct crobtab entry for tstuser on #{host}")
+ end
+
+ step "apply the resource change on the host"
+ on(host, puppet_resource("cron", "crontest", "user=tstuser", "command=/bin/true", "ensure=present", "hour='0-6'")) do
+ assert_match(/hour\s+=>\s+\['0-6'\]/, stdout, "Modifying cron entry failed for tstuser on #{host}")
+ end
+
+ step "verify that crontab -l contains what you expected"
+ run_cron_on(host,:list,'tstuser') do
+ assert_match(/\* 0-6 \* \* \* \/bin\/true/, stdout, "Didn't find correctly modified time entry in crobtab entry for tstuser on #{host}")
+ end
+end