Puppet was mis-parsing sshkey aliases when the last alias is an empty
string.
This is due to the counter-intuitive behavior of Ruby's String#split.

Signed-off-by: Jesse Wolfe <[email protected]>
---
 lib/puppet/provider/sshkey/parsed.rb |    8 +++-----
 spec/unit/provider/sshkey/parsed.rb  |   19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 5 deletions(-)
 create mode 100755 spec/unit/provider/sshkey/parsed.rb

diff --git a/lib/puppet/provider/sshkey/parsed.rb 
b/lib/puppet/provider/sshkey/parsed.rb
index 0dc791b..4673b57 100755
--- a/lib/puppet/provider/sshkey/parsed.rb
+++ b/lib/puppet/provider/sshkey/parsed.rb
@@ -19,11 +19,9 @@ Puppet::Type.type(:sshkey).provide(:parsed,
 
     record_line :parsed, :fields => %w{name type key},
         :post_parse => proc { |hash|
-            if hash[:name] =~ /,/
-                names = hash[:name].split(",")
-                hash[:name] = names.shift
-                hash[:alias] = names
-            end
+            names = hash[:name].split(",", -1)
+            hash[:name]  = names.shift
+            hash[:alias] = names
         },
         :pre_gen => proc { |hash|
             if hash[:alias]
diff --git a/spec/unit/provider/sshkey/parsed.rb 
b/spec/unit/provider/sshkey/parsed.rb
new file mode 100755
index 0000000..c97656f
--- /dev/null
+++ b/spec/unit/provider/sshkey/parsed.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:sshkey).provider(:parsed)
+
+describe provider_class do
+    before do
+        @sshkey_class = Puppet::Type.type(:sshkey)
+        @provider_class = @sshkey_class.provider(:parsed)
+    end
+
+    it "should not drop an empty alias" do 
+        line = 'test,alias, ssh-rsa 
AAAAB3NzaC1yc2EAAAABIwAAAQEAzwHhxXvIrtfIwrudFqc8yQcIfMudrgpnuh1F3AV6d2BrLgu/yQE7W5UyJMUjfj427sQudRwKW45O0Jsnr33F4mUw+GIMlAAmp9g24/OcrTiB8ZUKIjoPy/cO4coxGi8/NECtRzpD/ZUPFh6OEpyOwJPMb7/EC2Az6Otw4StHdXUYw22zHazBcPFnv6zCgPx1hA7QlQDWTu4YcL0WmTYQCtMUb3FUqrcFtzGDD0ytosgwSd+JyN5vj5UwIABjnNOHPZ62EY1OFixnfqX/+dUwrFSs5tPgBF/KkC6R7tmbUfnBON6RrGEmu+ajOTOLy23qUZB4CQ53V7nyAWhzqSK+hw=='
+        parsed = @provider_class.parse_line(line)
+        parsed[:alias].should == ["alias",""]
+    end
+
+end
-- 
1.6.3.3

--

You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.


Reply via email to