diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-07 11:11:45 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-12-07 13:27:30 -0800 |
commit | 6ad0ac95c33969a16b79fd32cd987fe68c150266 (patch) | |
tree | 5baa154afc57c7c6e5ba74e1e9bdd682d40a3bd3 | |
parent | c1e6bb1a47d821dbbab59eaf16a46c3ff02f0ccf (diff) | |
download | chef-6ad0ac95c33969a16b79fd32cd987fe68c150266.tar.gz |
Validate the start_date is correctly passed
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/windows_task.rb | 5 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 9cac33d17d..7e9025aea1 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -108,12 +108,15 @@ class Chef if [:once, :on_logon, :onstart, :on_idle, :none].include? frequency raise ArgumentError, "`start_day` property is not supported with frequency: #{frequency}" end + + # make sure the start_day is in MM/DD/YYYY format: http://rubular.com/r/cgjHemtWl5 + raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/.match?(start_day) end def validate_start_time(start_time, frequency) if start_time raise ArgumentError, "`start_time` property is not supported with `frequency :none`" if frequency == :none - raise ArgumentError, "`start_time` property must be in the HH:mm format." unless /^[0-2][0-3]:[0-5][0-9]$/ =~ start_time + raise ArgumentError, "`start_time` property must be in the HH:mm format." unless /^[0-2][0-3]:[0-5][0-9]$/.match?(start_time) else raise ArgumentError, "`start_time` needs to be provided with `frequency :once`" if frequency == :once end diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index 65b4111e8e..725aa0fd86 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -169,7 +169,7 @@ describe Chef::Resource::WindowsTask do context "#validate_start_day" do it "raise error if start_day is passed with frequency :on_logon" do resource.frequency :on_logon - expect { resource.send(:validate_start_day, "Wed", :on_logon) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property is not supported with frequency: on_logon") + expect { resource.send(:validate_start_day, "02/07/1984", :on_logon) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property is not supported with frequency: on_logon") end end |