diff options
| author | Francois Deppierraz <francois.deppierraz@camptocamp.com> | 2008-04-10 19:24:06 +0200 |
|---|---|---|
| committer | Francois Deppierraz <francois@ctrlaltdel.ch> | 2008-05-07 22:04:07 +0200 |
| commit | db8a46c605b8b4a205e65aa35a1442f2de32431b (patch) | |
| tree | b3266d73a0fa7af433e096f667ec8a172c8ffb22 /spec | |
| parent | 2b185af97882afb4a7feab42de97771ceed80b43 (diff) | |
New native ssh_authorized_key type
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/ral/provider/ssh_authorized_key/parsed.rb | 74 | ||||
| -rw-r--r-- | spec/unit/ral/type/ssh_authorized_key.rb | 80 |
2 files changed, 154 insertions, 0 deletions
diff --git a/spec/unit/ral/provider/ssh_authorized_key/parsed.rb b/spec/unit/ral/provider/ssh_authorized_key/parsed.rb new file mode 100644 index 000000000..459001cb5 --- /dev/null +++ b/spec/unit/ral/provider/ssh_authorized_key/parsed.rb @@ -0,0 +1,74 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../../spec_helper' + +require 'puppettest' +require 'puppettest/support/utils' +require 'puppettest/fileparsing' + +provider_class = Puppet::Type.type(:ssh_authorized_key).provider(:parsed) + +describe provider_class do + include PuppetTest + include PuppetTest::FileParsing + + before :each do + @sshauthkey_class = Puppet.type(:ssh_authorized_key) + @provider = @sshauthkey_class.provider(:parsed) + end + + after :each do + @provider.initvars + end + + def mkkey(args) + fakeresource = fakeresource(:ssh_authorized_key, args[:name]) + + key = @provider.new(fakeresource) + args.each do |p,v| + key.send(p.to_s + "=", v) + end + + return key + end + + def genkey(key) + @provider.filetype = :ram + file = @provider.default_target + + key.flush + text = @provider.target_object(file).read + return text + end + + it "should be able to parse each example" do + fakedata("data/providers/ssh_authorized_key/parsed").each { |file| + puts "Parsing %s" % file + fakedataparse(file) + } + end + + it "should be able to generate a basic authorized_keys file" do + key = mkkey({ + :name => "Just Testing", + :key => "AAAAfsfddsjldjgksdflgkjsfdlgkj", + :type => "ssh-dss", + :ensure => :present, + :options => [:absent] + }) + + genkey(key).should == "ssh-dss AAAAfsfddsjldjgksdflgkjsfdlgkj Just Testing\n" + end + + it "should be able to generate a authorized_keys file with options" do + key = mkkey({ + :name => "root@localhost", + :key => "AAAAfsfddsjldjgksdflgkjsfdlgkj", + :type => "ssh-rsa", + :ensure => :present, + :options => ['from="192.168.1.1"', "no-pty", "no-X11-forwarding"] + }) + + genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root@localhost\n" + end +end diff --git a/spec/unit/ral/type/ssh_authorized_key.rb b/spec/unit/ral/type/ssh_authorized_key.rb new file mode 100644 index 000000000..d27cb9f25 --- /dev/null +++ b/spec/unit/ral/type/ssh_authorized_key.rb @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +ssh_authorized_key = Puppet::Type.type(:ssh_authorized_key) + +describe ssh_authorized_key do + before do + @class = Puppet::Type.type(:ssh_authorized_key) + + @provider_class = stub 'provider_class', :name => "fake", :suitable? => true, :supports_parameter? => true + @class.stubs(:defaultprovider).returns(@provider_class) + @class.stubs(:provider).returns(@provider_class) + + @provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil + @provider_class.stubs(:new).returns(@provider) + end + + it "should have a name parameter" do + @class.attrtype(:name).should == :param + end + + it "should have :name be its namevar" do + @class.namevar.should == :name + end + + it "should have a :provider parameter" do + @class.attrtype(:provider).should == :param + end + + it "should have an ensure property" do + @class.attrtype(:ensure).should == :property + end + + it "should support :present as a value for :ensure" do + proc { @class.create(:name => "whev", :ensure => :present) }.should_not raise_error + end + + it "should support :absent as a value for :ensure" do + proc { @class.create(:name => "whev", :ensure => :absent) }.should_not raise_error + end + + it "should have an type property" do + @class.attrtype(:type).should == :property + end + it "should support ssh-dss as an type value" do + proc { @class.create(:name => "whev", :type => "ssh-dss") }.should_not raise_error + end + it "should support ssh-rsa as an type value" do + proc { @class.create(:name => "whev", :type => "ssh-rsa") }.should_not raise_error + end + it "should support :dsa as an type value" do + proc { @class.create(:name => "whev", :type => :dsa) }.should_not raise_error + end + it "should support :rsa as an type value" do + proc { @class.create(:name => "whev", :type => :rsa) }.should_not raise_error + end + + it "should not support values other than ssh-dss, ssh-rsa, dsa, rsa in the ssh_authorized_key_type" do + proc { @class.create(:name => "whev", :type => :something) }.should raise_error(Puppet::Error) + end + + it "should have an key property" do + @class.attrtype(:key).should == :property + end + + it "should have an user property" do + @class.attrtype(:user).should == :property + end + + it "should have an options property" do + @class.attrtype(:options).should == :property + end + + it "should have a target property" do + @class.attrtype(:target).should == :property + end + + after { @class.clear } +end |
