summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorFrancois Deppierraz <francois.deppierraz@camptocamp.com>2008-11-28 15:12:30 +0100
committerJames Turnbull <james@lovedthanlost.net>2009-03-24 08:15:33 +1100
commitbbcda1d5bcab492dc68d331e6f78fb0473e9f046 (patch)
tree89da1743d3c4244ba147faa0924a587f972af8fe /spec
parent69a0f7dc8d3ba1c64e5acdf99628f10b41ab8e30 (diff)
downloadpuppet-bbcda1d5bcab492dc68d331e6f78fb0473e9f046.tar.gz
puppet-bbcda1d5bcab492dc68d331e6f78fb0473e9f046.tar.xz
puppet-bbcda1d5bcab492dc68d331e6f78fb0473e9f046.zip
Fix Bug #1629
A refactoring of ssh_authorized_key parsed provider was needed and tests were improved. flush method has been split for clarity.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/provider/ssh_authorized_key/parsed.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb
index 21f30f97e..73d623573 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed.rb
@@ -100,3 +100,67 @@ describe provider_class do
@provider.parse_options(optionstr).should == options
end
end
+
+describe provider_class do
+ before :each do
+ @resource = stub("resource", :name => "foo")
+ @resource.stubs(:[]).returns "foo"
+ @provider = provider_class.new(@resource)
+ end
+
+ describe "when flushing" do
+ before :each do
+ # Stub file and directory operations
+ Dir.stubs(:mkdir)
+ File.stubs(:chmod)
+ File.stubs(:chown)
+ end
+
+ describe "and a user has been specified" do
+ before :each do
+ @resource.stubs(:should).with(:user).returns "nobody"
+ @resource.stubs(:should).with(:target).returns nil
+ 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
+
+ end
+end