From aaf7d02fe45daf01fcf832b4e7d7744ae4892237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 4 May 2023 11:15:33 -1000 Subject: [PATCH] Fix validate_domain_name called without parameters In #1345, the validate_domain_name() function was rewritten to the Puppet 4.x syntax, but the behaviour was slightly changed since we previously did not allow passing no parameter at all. Add code to assert as least one paramatter is passed to restore the previous behavior and raise an error when called without parameter. --- lib/puppet/functions/validate_domain_name.rb | 8 +++++++- spec/functions/validate_domain_name_spec.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puppet/functions/validate_domain_name.rb b/lib/puppet/functions/validate_domain_name.rb index c2833043f..b2364a83c 100644 --- a/lib/puppet/functions/validate_domain_name.rb +++ b/lib/puppet/functions/validate_domain_name.rb @@ -24,5 +24,11 @@ repeated_param 'Variant[Stdlib::Fqdn, Stdlib::Dns::Zone]', :values end - def validate_domain_name(*_values); end + def validate_domain_name(*args) + assert_arg_count(args) + end + + def assert_arg_count(args) + raise(ArgumentError, 'validate_domain_name(): Wrong number of arguments need at least one') if args.empty? + end end diff --git a/spec/functions/validate_domain_name_spec.rb b/spec/functions/validate_domain_name_spec.rb index 78aea8218..3132c64d7 100644 --- a/spec/functions/validate_domain_name_spec.rb +++ b/spec/functions/validate_domain_name_spec.rb @@ -5,6 +5,7 @@ describe 'validate_domain_name' do describe 'signature validation' do it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) } end describe 'valid inputs' do