summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-12-07 08:04:44 -0800
committerTim Smith <tsmith@chef.io>2017-12-07 13:27:30 -0800
commit00cdaff936a3d50ed7ea4eb9e0afa368403a1646 (patch)
tree689cfef9e74fefc10f78cecc1e24f1ec9c525d22
parenta3642df60cc51c8b57bdfdc0cb12846215256c8f (diff)
downloadchef-00cdaff936a3d50ed7ea4eb9e0afa368403a1646.tar.gz
Validate that starttime is actually in HH:mm format
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_task.rb9
-rw-r--r--spec/unit/resource/windows_task_spec.rb10
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 37a818c7fe..b879cbe6e0 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -109,10 +109,11 @@ class Chef
end
def validate_start_time(start_time, frequency)
- if frequency == :once
- raise ArgumentError, "`start_time` needs to be provided with `frequency :once`" unless start_time
- elsif frequency == :none
- raise ArgumentError, "`start_time` property is not supported with `frequency :none`" if start_time
+ 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
+ else
+ raise ArgumentError, "`start_time` needs to be provided with `frequency :once`" if frequency == :once
end
end
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 712fc44933..d5c95235cd 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -130,6 +130,16 @@ describe Chef::Resource::WindowsTask do
resource.frequency :none
expect { resource.send(:validate_start_time, "12.00", :none) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_time` property is not supported with `frequency :none`")
end
+
+ it "raises error if start_time is not HH:mm format" do
+ resource.frequency :once
+ expect { resource.send(:validate_start_time, "2:30", :once) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_time` property must be in the HH:mm format.")
+ end
+
+ it "does not raise error if start_time is in HH:mm format" do
+ resource.frequency :once
+ expect { resource.send(:validate_start_time, "12:30", :once) }.not_to raise_error
+ end
end
context "#validate_start_day" do