From 29925fb28a09075ea4c4105674dca2415e1c7800 Mon Sep 17 00:00:00 2001 From: Dorin Pleava Date: Thu, 6 Aug 2020 15:14:37 +0300 Subject: (MODULES-7786) Allow leading zeroes for cron params When applying a cron manigest that contains leading zeroes in a periodic attribute (hour, minute, month, monthday, weekday), puppet will strip down the zeroes even if they are accepted by the system cron. Now puppet will only convert to integer the periodic attributes when validating them, but will not change the input from the manifest. --- spec/unit/type/cron_spec.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'spec/unit/type') diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb index 32bde11..1ce66a4 100644 --- a/spec/unit/type/cron_spec.rb +++ b/spec/unit/type/cron_spec.rb @@ -127,6 +127,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do # As it turns out cron does not complaining about steps that exceed the valid range # expect { described_class.new(:name => 'foo', :minute => '*/120' ) }.to raise_error(Puppet::Error, /is not a valid minute/) end + + it 'supports values with leading zeros' do + expect { described_class.new(name: 'foo', minute: ['0', '0011', '044']) }.not_to raise_error + expect { described_class.new(name: 'foo', minute: '022') }.not_to raise_error + end + + it 'does not remove leading zeroes' do + expect(described_class.new(name: 'foo', minute: '0045')[:minute]).to eq(['0045']) + end end describe 'hour' do @@ -194,6 +203,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do # As it turns out cron does not complaining about steps that exceed the valid range # expect { described_class.new(:name => 'foo', :hour => '*/26' ) }.to raise_error(Puppet::Error, /is not a valid hour/) end + + it 'supports values with leading zeros' do + expect { described_class.new(name: 'foo', hour: ['007', '1', '0023']) }.not_to raise_error + expect { described_class.new(name: 'foo', hour: '022') }.not_to raise_error + end + + it 'does not remove leading zeroes' do + expect(described_class.new(name: 'foo', hour: '005')[:hour]).to eq(['005']) + end end describe 'weekday' do @@ -277,6 +295,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do # As it turns out cron does not complaining about steps that exceed the valid range # expect { described_class.new(:name => 'foo', :weekday => '*/9' ) }.to raise_error(Puppet::Error, /is not a valid weekday/) end + + it 'supports values with leading zeros' do + expect { described_class.new(name: 'foo', weekday: ['Mon', 'Wed', '05']) }.not_to raise_error + expect { described_class.new(name: 'foo', weekday: '007') }.not_to raise_error + end + + it 'does not remove leading zeroes' do + expect(described_class.new(name: 'foo', weekday: '006')[:weekday]).to eq(['006']) + end end describe 'month' do @@ -376,6 +403,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do # As it turns out cron does not complaining about steps that exceed the valid range # expect { described_class.new(:name => 'foo', :month => '*/13' ) }.to raise_error(Puppet::Error, /is not a valid month/) end + + it 'supports values with leading zeros' do + expect { described_class.new(name: 'foo', month: ['007', '1', '0012']) }.not_to raise_error + expect { described_class.new(name: 'foo', month: ['Jan', '04', '0009']) }.not_to raise_error + end + + it 'does not remove leading zeroes' do + expect(described_class.new(name: 'foo', month: '09')[:month]).to eq(['09']) + end end describe 'monthday' do @@ -441,6 +477,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do # As it turns out cron does not complaining about steps that exceed the valid range # expect { described_class.new(:name => 'foo', :monthday => '*/32' ) }.to raise_error(Puppet::Error, /is not a valid monthday/) end + + it 'supports values with leading zeros' do + expect { described_class.new(name: 'foo', monthday: ['007', '1', '0023']) }.not_to raise_error + expect { described_class.new(name: 'foo', monthday: '022') }.not_to raise_error + end + + it 'does not remove leading zeroes' do + expect(described_class.new(name: 'foo', monthday: '01')[:monthday]).to eq(['01']) + end end describe 'special' do -- cgit v1.2.3