diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb index 59a1a12f8..41b3dde55 100755 --- a/lib/puppet/type/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -1,72 +1,72 @@ module Puppet newtype(:sshkey) do @doc = "Installs and manages ssh host keys. At this point, this type only knows how to install keys into `/etc/ssh/ssh_known_hosts`. See the `ssh_authorized_key` type to manage authorized keys." ensurable newproperty(:type) do desc "The encryption type used. Probably ssh-dss or ssh-rsa." - newvalue("ssh-dss") - newvalue("ssh-rsa") - aliasvalue(:dsa, "ssh-dss") - aliasvalue(:rsa, "ssh-rsa") + newvalues :'ssh-dss', :'ssh-rsa', :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521' + + aliasvalue(:dsa, :'ssh-dss') + aliasvalue(:rsa, :'ssh-rsa') end newproperty(:key) do desc "The key itself; generally a long string of hex digits." end # FIXME This should automagically check for aliases to the hosts, just # to see if we can automatically glean any aliases. newproperty(:host_aliases) do desc 'Any aliases the host might have. Multiple values must be specified as an array.' attr_accessor :meta def insync?(is) is == @should end # We actually want to return the whole array here, not just the first # value. def should defined?(@should) ? @should : nil end validate do |value| if value =~ /\s/ raise Puppet::Error, "Aliases cannot include whitespace" end if value =~ /,/ raise Puppet::Error, "Aliases must be provided as an array, not a comma-separated list" end end end newparam(:name) do desc "The host name that the key is associated with." isnamevar validate do |value| raise Puppet::Error, "Resourcename cannot include whitespaces" if value =~ /\s/ raise Puppet::Error, "No comma in resourcename allowed. If you want to specify aliases use the host_aliases property" if value.include?(',') end end newproperty(:target) do desc "The file in which to store the ssh key. Only used by the `parsed` provider." defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) @resource.class.defaultprovider.default_target else nil end } end end end diff --git a/spec/unit/type/sshkey_spec.rb b/spec/unit/type/sshkey_spec.rb index ba3406976..ae4967856 100755 --- a/spec/unit/type/sshkey_spec.rb +++ b/spec/unit/type/sshkey_spec.rb @@ -1,70 +1,68 @@ #!/usr/bin/env rspec require 'spec_helper' sshkey = Puppet::Type.type(:sshkey) describe sshkey do before do @class = sshkey end it "should have :name its namevar" do @class.key_attributes.should == [:name] end describe "when validating attributes" do [:name, :provider].each do |param| it "should have a #{param} parameter" do @class.attrtype(param).should == :param end end [:host_aliases, :ensure, :key, :type].each do |property| it "should have a #{property} property" do @class.attrtype(property).should == :property end end end describe "when validating values" do - it "should support ssh-dss as a type value" do - proc { @class.new(:name => "foo", :type => "ssh-dss") }.should_not raise_error + [:'ssh-dss', :'ssh-rsa', :rsa, :dsa, :'ecdsa-sha2-nistp256', :'ecdsa-sha2-nistp384', :'ecdsa-sha2-nistp521'].each do |keytype| + it "should support #{keytype} as a type value" do + proc { @class.new(:name => "foo", :type => keytype) }.should_not raise_error + end end - it "should support ssh-rsa as a type value" do - proc { @class.new(:name => "whev", :type => "ssh-rsa") }.should_not raise_error + it "should alias :rsa to :ssh-rsa" do + key = @class.new(:name => "foo", :type => :rsa) + key.should(:type).should == :'ssh-rsa' end - it "should alias :dsa to ssh-dss as a value for type" do - key = @class.new(:name => "whev", :type => :dsa) + it "should alias :dsa to :ssh-dss" do + key = @class.new(:name => "foo", :type => :dsa) key.should(:type).should == :'ssh-dss' end - it "should alias :rsa to ssh-rsa as a value for type" do - key = @class.new(:name => "whev", :type => :rsa) - key.should(:type).should == :'ssh-rsa' - end - it "should not support values other than ssh-dss, ssh-rsa, dsa, rsa for type" do proc { @class.new(:name => "whev", :type => :'ssh-dsa') }.should raise_error(Puppet::Error) end it "should accept one host_alias" do proc { @class.new(:name => "foo", :host_aliases => 'foo.bar.tld') }.should_not raise_error end it "should accept multiple host_aliases as an array" do proc { @class.new(:name => "foo", :host_aliases => ['foo.bar.tld','10.0.9.9']) }.should_not raise_error end it "should not accept spaces in any host_alias" do proc { @class.new(:name => "foo", :host_aliases => ['foo.bar.tld','foo bar']) }.should raise_error(Puppet::Error) end it "should not accept aliases in the resourcename" do proc { @class.new(:name => 'host,host.domain,ip') }.should raise_error(Puppet::Error) end end end