[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:06:30 UTC 2011
The following commit has been merged in the experimental branch:
commit 072becf6b51cb359d18b30d7eb01391f641dd840
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon Mar 21 14:31:18 2011 -0700
(#6806) Improve error checking and reporting for interface naming.
We didn't do enough input checking and sanitization, and missed some
edge-cases for naming interfaces. This adds testing, and cleans up some edge
cases to handle things better.
Reviewed-By: Pieter van de Bruggen <pieter at puppetlabs.com>
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index dfd75ef..d169067 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -55,12 +55,12 @@ class Puppet::Interface
remove_const(constantize(name)) rescue nil
end
- def self.unify_name(name)
- name.to_s.downcase.to_sym
- end
-
def self.constantize(name)
- name.to_s.split(/\W|_/).map { |x| x.capitalize }.join
+ unless name.to_s =~ /^[-_a-z]+$/i then
+ raise ArgumentError, "#{name.inspect} (#{name.class}) is not a valid interface name"
+ end
+
+ name.to_s.split(/[-_]/).map { |x| x.capitalize }.join
end
attr_accessor :default_format
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
old mode 100644
new mode 100755
index 4b6fd11..cfa0111
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -92,4 +92,31 @@ describe Puppet::Interface do
end
it "should be able to load all actions in all search paths"
+
+ describe "#constantize" do
+ faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"]
+ valid = {
+ "foo" => "Foo",
+ :foo => "Foo",
+ "foo_bar" => "FooBar",
+ :foo_bar => "FooBar",
+ "foo-bar" => "FooBar",
+ :"foo-bar" => "FooBar",
+ }
+
+ valid.each do |input, expect|
+ it "should map '#{input}' to '#{expect}'" do
+ result = Puppet::Interface.constantize(input)
+ result.should be_a String
+ result.to_s.should == expect
+ end
+ end
+
+ faulty.each do |input|
+ it "should fail when presented with #{input.inspect} (#{input.class})" do
+ expect { Puppet::Interface.constantize(input) }.
+ should raise_error ArgumentError, /not a valid interface name/
+ end
+ end
+ end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list