summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/ssh_authorized_key/parsed.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-02 18:56:53 -0500
committerLuke Kanies <luke@madstop.com>2009-04-02 18:56:53 -0500
commit6e79cc00965a50c44f215fd1e553281cfd2b87c9 (patch)
tree56c496df9ad6ab66dfb16993910eb5ff1c34d065 /spec/unit/provider/ssh_authorized_key/parsed.rb
parent62dad7a5f87f8d6285650ab1b727819db27cf2a7 (diff)
parentc62c19370bfba881819c1a3d9da2f8e6fb52e5d9 (diff)
downloadpuppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.tar.gz
puppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.tar.xz
puppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.zip
Merge branch '0.24.x'
Conflicts: bin/ralsh lib/puppet/executables/client/certhandler.rb lib/puppet/parser/functions/versioncmp.rb lib/puppet/parser/resource/reference.rb lib/puppet/provider/augeas/augeas.rb lib/puppet/provider/nameservice/directoryservice.rb lib/puppet/provider/ssh_authorized_key/parsed.rb lib/puppet/type.rb lib/puppet/type/file/checksum.rb spec/integration/defaults.rb spec/integration/transaction/report.rb spec/unit/executables/client/certhandler.rb spec/unit/indirector/ssl_rsa/file.rb spec/unit/node/catalog.rb spec/unit/provider/augeas/augeas.rb spec/unit/rails.rb spec/unit/type/ssh_authorized_key.rb spec/unit/type/tidy.rb test/executables/filebucket.rb test/executables/puppetbin.rb
Diffstat (limited to 'spec/unit/provider/ssh_authorized_key/parsed.rb')
-rwxr-xr-xspec/unit/provider/ssh_authorized_key/parsed.rb82
1 files changed, 63 insertions, 19 deletions
diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb
index ec8f2b96a..18f3be126 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed.rb
@@ -72,32 +72,76 @@ describe provider_class do
genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root@localhost\n"
end
- it "should prefetch ~user/.ssh/authorized_keys when user is given" do
- key = Puppet::Type.type(:ssh_authorized_key).create(
- :name => "Test",
- :key => "AA",
- :type => "rsa",
- :ensure => :present,
- :user => "root")
- prov = @provider.new key
+ it "'s parse_options method should be able to parse options containing commas" do
+ options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
+ optionstr = options.join(", ")
- prov.prefetch
- prov.target.should == File.expand_path("~root/.ssh/authorized_keys")
+ @provider.parse_options(optionstr).should == options
end
+end
- it "should create destination dir" do
- # No idea how to test the flush method
+describe provider_class do
+ before :each do
+ @resource = stub("resource", :name => "foo")
+ @resource.stubs(:[]).returns "foo"
+ @provider = provider_class.new(@resource)
end
- it "should set correct default permissions" do
- # No idea how to test the flush method
- end
+ describe "when flushing" do
+ before :each do
+ # Stub file and directory operations
+ Dir.stubs(:mkdir)
+ File.stubs(:chmod)
+ File.stubs(:chown)
+ end
- it "'s parse_options method should be able to parse options containing commas" do
- options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
- optionstr = options.join(", ")
+ describe "and a user has been specified" do
+ before :each do
+ @resource.stubs(:should).with(:user).returns "nobody"
+ target = File.expand_path("~nobody/.ssh/authorized_keys")
+ @resource.stubs(:should).with(:target).returns target
+ end
+
+ it "should create the directory" do
+ Dir.expects(:mkdir).with(File.expand_path("~nobody/.ssh"), 0700)
+ @provider.flush
+ end
+
+ it "should chown the directory to the user" do
+ uid = Puppet::Util.uid("nobody")
+ File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh"))
+ @provider.flush
+ end
+
+ it "should chown the key file to the user" do
+ uid = Puppet::Util.uid("nobody")
+ File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh/authorized_keys"))
+ @provider.flush
+ end
+
+ it "should chmod the key file to 0600" do
+ File.chmod(0600, File.expand_path("~nobody/.ssh/authorized_keys"))
+ @provider.flush
+ end
+ end
+
+ describe "and a target has been specified" do
+ before :each do
+ @resource.stubs(:should).with(:user).returns nil
+ @resource.stubs(:should).with(:target).returns "/tmp/.ssh/authorized_keys"
+ end
+
+ it "should make the directory" do
+ Dir.expects(:mkdir).with("/tmp/.ssh", 0755)
+ @provider.flush
+ end
+
+ it "should chmod the key file to 0644" do
+ File.expects(:chmod).with(0644, "/tmp/.ssh/authorized_keys")
+ @provider.flush
+ end
+ end
- @provider.parse_options(optionstr).should == options
end
end