diff options
author | Mario Haustein <mario.haustein@hrz.tu-chemnitz.de> | 2021-12-15 19:43:05 +0100 |
---|---|---|
committer | Mario Haustein <mario.haustein@hrz.tu-chemnitz.de> | 2022-05-31 17:57:36 +0200 |
commit | 3ac8ac4dac3b96de58c8ee3d6c5f21ffcde67303 (patch) | |
tree | d8386ec995a206fbe8d71a1dee3a4a6a055597e9 | |
parent | f9f2b6fb6b4c6da3584bffe6880dfec25328c489 (diff) | |
download | chef-3ac8ac4dac3b96de58c8ee3d6c5f21ffcde67303.tar.gz |
Fix cron_d job name character set
This commit restrict the cron_d job name property to the character set
according to the cron specification:
> Additionally, cron reads the files in /etc/cron.d [...] Files must
> conform to the same naming convention as used by run-parts(8): they
> must consist solely of upper- and lower-case letters, digits,
> underscores, and hyphens.
closes #12165
Signed-off-by: Mario Haustein <mario.haustein@hrz.tu-chemnitz.de>
-rw-r--r-- | lib/chef/resource/cron/cron_d.rb | 1 | ||||
-rw-r--r-- | spec/unit/resource/cron_d_spec.rb | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/chef/resource/cron/cron_d.rb b/lib/chef/resource/cron/cron_d.rb index 9bd53d38b2..d7e8d7f5e3 100644 --- a/lib/chef/resource/cron/cron_d.rb +++ b/lib/chef/resource/cron/cron_d.rb @@ -92,6 +92,7 @@ class Chef property :cron_name, String, description: "An optional property to set the cron name if it differs from the resource block's name.", + regex: /^[a-zA-Z0-9_-]+$/, name_property: true property :cookbook, String, desired_state: false, skip_docs: true diff --git a/spec/unit/resource/cron_d_spec.rb b/spec/unit/resource/cron_d_spec.rb index c798265d06..d1f70f84d6 100644 --- a/spec/unit/resource/cron_d_spec.rb +++ b/spec/unit/resource/cron_d_spec.rb @@ -34,6 +34,14 @@ describe Chef::Resource::CronD do expect(resource.cron_name).to eql("cronify") end + it "the cron_name property is valid" do + expect { resource.cron_name "cron-job" }.not_to raise_error + expect { resource.cron_name "cron_job_0" }.not_to raise_error + expect { resource.cron_name "CronJob" }.not_to raise_error + expect { resource.cron_name "cron!" }.to raise_error(ArgumentError) + expect { resource.cron_name "cron job" }.to raise_error(ArgumentError) + end + it "the mode property defaults to '0600'" do expect(resource.mode).to eql("0600") end |