[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Daniel Pittman daniel at puppetlabs.com
Tue May 10 08:18:45 UTC 2011


The following commit has been merged in the experimental branch:
commit 97ae812f0a67ef01daed4e9220981e2bc7c70603
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Fri Apr 29 13:29:17 2011 -0700

    (#7248) Fail if two aliases of one option are passed...
    
    From the command line, and other facades, it is fairly difficult to call an
    action with two aliases of the same option in the invocation, but from the
    Ruby API it would be relatively easy to achieve.
    
    This is now checked, and raises an error, so that we don't accidentally have
    strange or unusual behaviour coming out of the whole system.
    
    Reviewed-By: Pieter van de Bruggen <pieter at puppetlabs.com>

diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 9c9741b..b842c28 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -255,6 +255,20 @@ WRAPPER
   end
 
   def validate_args(args)
+    # Check for multiple aliases for the same option...
+    args.last.keys.each do |name|
+      # #7290: If this isn't actually an option, ignore it for now.  We should
+      # probably fail, but that wasn't our API, and I don't want to perturb
+      # behaviour this late in the RC cycle. --daniel 2011-04-29
+      if option = get_option(name) then
+        overlap = (option.aliases & args.last.keys)
+        unless overlap.length == 1 then
+          raise ArgumentError, "Multiple aliases for the same option passed: #{overlap.join(', ')}"
+        end
+      end
+    end
+
+    # Check for missing mandatory options.
     required = options.map do |name|
       get_option(name)
     end.select(&:required?).collect(&:name) - args.last.keys
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index 23d0de4..f6796a8 100755
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -445,4 +445,23 @@ describe Puppet::Interface::Action do
     it "should fail if a second block is given for the same type"
     it "should return the block if asked"
   end
+
+  context "#validate_args" do
+    subject do
+      Puppet::Interface.new(:validate_args, '1.0.0') do
+        script :test do true end
+      end
+    end
+
+    it "should fail if a required option is not passed" do
+      subject.option "--foo" do required end
+      expect { subject.test }.to raise_error ArgumentError, /options are required/
+    end
+
+    it "should fail if two aliases to one option are passed" do
+      subject.option "--foo", "-f"
+      expect { subject.test :foo => true, :f => true }.
+        to raise_error ArgumentError, /Multiple aliases for the same option/
+    end
+  end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list