diff options
author | Luke Kanies <luke@madstop.com> | 2009-03-03 21:36:56 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-03-05 08:22:10 +1100 |
commit | 61661b1c46fafeabf1bdbc4778762831d7178d91 (patch) | |
tree | 270f8dcb07cf818435a2f3c0e130d4a3b4436bb7 | |
parent | d5850dc40f20b6ea9429588c476eb0dca2d205b7 (diff) | |
download | puppet-61661b1c46fafeabf1bdbc4778762831d7178d91.tar.gz puppet-61661b1c46fafeabf1bdbc4778762831d7178d91.tar.xz puppet-61661b1c46fafeabf1bdbc4778762831d7178d91.zip |
Fixing #1991 - ldap booleans get converted to booleans
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/indirector/node/ldap.rb | 25 | ||||
-rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 759db3a5c..ab5d47b1c 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -103,6 +103,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end end + result[:parameters] = convert_parameters(result[:parameters]) + result end @@ -143,6 +145,29 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap node.environment = information[:environment] if information[:environment] end + def convert_parameters(parameters) + result = {} + parameters.each do |param, value| + if value.is_a?(Array) + result[param] = value.collect { |v| convert(v) } + else + result[param] = convert(value) + end + end + result + end + + # Convert any values if necessary. + def convert(value) + case value + when Integer, Fixnum, Bignum; value + when "true"; true + when "false"; false + else + value + end + end + # Find information for our parent and merge it into the current info. def find_and_merge_parent(parent, information) unless parent_info = name2hash(parent) diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index ed8809e73..d407796c6 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -91,6 +91,26 @@ describe Puppet::Node::Ldap do @searcher.entry2hash(@entry)[:parameters]["foo"].should == "one" end + it "should convert 'true' values to the boolean 'true'" do + @entry.stubs(:to_hash).returns({"one" => ["true"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == true + end + + it "should convert 'false' values to the boolean 'false'" do + @entry.stubs(:to_hash).returns({"one" => ["false"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == false + end + + it "should convert 'true' values to the boolean 'true' inside an array" do + @entry.stubs(:to_hash).returns({"one" => ["true", "other"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == [true, "other"] + end + + it "should convert 'false' values to the boolean 'false' inside an array" do + @entry.stubs(:to_hash).returns({"one" => ["false", "other"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == [false, "other"] + end + it "should add the parent's name if present" do @entry.stubs(:vals).with("parentnode").returns(%w{foo}) @searcher.entry2hash(@entry)[:parent].should == "foo" |