summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-23 07:28:42 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-23 07:28:42 -0500
commit7def1eaa0e6e559ed70f260bf7b42d8e84d3740b (patch)
tree81c91d425f015a634e5fe45e500ca0dec87bc0f6 /spec
parentb134f0ce465923a6b0b7f2855850e38599f0f176 (diff)
parentde5d91e2036de2934a4eec79d35a714f3ed24b10 (diff)
downloadpuppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.gz
puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.xz
puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.zip
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/indirector/file_content/file_server.rb18
-rwxr-xr-xspec/integration/indirector/file_content/mounts.rb18
-rwxr-xr-xspec/integration/indirector/file_metadata/file_server.rb18
-rwxr-xr-xspec/integration/indirector/file_metadata/mounts.rb18
-rwxr-xr-xspec/integration/indirector/module_files.rb2
-rw-r--r--spec/lib/shared_behaviours/file_server_terminus.rb (renamed from spec/lib/shared_behaviours/file_server_mounts.rb)14
-rw-r--r--spec/lib/shared_behaviours/file_serving.rb18
-rwxr-xr-xspec/unit/file_serving/configuration.rb48
-rwxr-xr-xspec/unit/file_serving/content.rb81
-rwxr-xr-xspec/unit/file_serving/file_base.rb85
-rwxr-xr-xspec/unit/file_serving/fileset.rb230
-rwxr-xr-xspec/unit/file_serving/metadata.rb94
-rwxr-xr-xspec/unit/file_serving/mount.rb4
-rwxr-xr-xspec/unit/file_serving/terminus_helper.rb38
-rwxr-xr-xspec/unit/file_serving/terminus_selector.rb70
-rwxr-xr-xspec/unit/indirector/file_content/file.rb70
-rwxr-xr-xspec/unit/indirector/file_content/file_server.rb (renamed from spec/unit/indirector/file_content/mounts.rb)8
-rwxr-xr-xspec/unit/indirector/file_content/local.rb37
-rwxr-xr-xspec/unit/indirector/file_metadata/file.rb82
-rwxr-xr-xspec/unit/indirector/file_metadata/file_server.rb (renamed from spec/unit/indirector/file_metadata/mounts.rb)8
-rwxr-xr-xspec/unit/indirector/file_metadata/local.rb43
-rwxr-xr-xspec/unit/indirector/file_server.rb131
-rwxr-xr-xspec/unit/indirector/indirection.rb9
-rwxr-xr-xspec/unit/indirector/module_files.rb140
-rwxr-xr-xspec/unit/indirector/ssl_rsa/file.rb116
25 files changed, 1152 insertions, 248 deletions
diff --git a/spec/integration/indirector/file_content/file_server.rb b/spec/integration/indirector/file_content/file_server.rb
new file mode 100755
index 000000000..965bd8fd1
--- /dev/null
+++ b/spec/integration/indirector/file_content/file_server.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_content/file_server'
+require 'shared_behaviours/file_server_terminus'
+
+describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
+ it_should_behave_like "Puppet::Indirector::FileServerTerminus"
+
+ before do
+ @terminus = Puppet::Indirector::FileContent::FileServer.new
+ @test_class = Puppet::FileServing::Content
+ end
+end
diff --git a/spec/integration/indirector/file_content/mounts.rb b/spec/integration/indirector/file_content/mounts.rb
deleted file mode 100755
index cd80825c7..000000000
--- a/spec/integration/indirector/file_content/mounts.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-10-18.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/indirector/file_content/mounts'
-require 'shared_behaviours/file_server_mounts'
-
-describe Puppet::Indirector::FileContent::Mounts, " when finding files" do
- it_should_behave_like "Puppet::Indirector::FileServerMounts"
-
- before do
- @terminus = Puppet::Indirector::FileContent::Mounts.new
- @test_class = Puppet::FileServing::Content
- end
-end
diff --git a/spec/integration/indirector/file_metadata/file_server.rb b/spec/integration/indirector/file_metadata/file_server.rb
new file mode 100755
index 000000000..7caa2e4de
--- /dev/null
+++ b/spec/integration/indirector/file_metadata/file_server.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_metadata/file_server'
+require 'shared_behaviours/file_server_terminus'
+
+describe Puppet::Indirector::FileMetadata::FileServer, " when finding files" do
+ it_should_behave_like "Puppet::Indirector::FileServerTerminus"
+
+ before do
+ @terminus = Puppet::Indirector::FileMetadata::FileServer.new
+ @test_class = Puppet::FileServing::Metadata
+ end
+end
diff --git a/spec/integration/indirector/file_metadata/mounts.rb b/spec/integration/indirector/file_metadata/mounts.rb
deleted file mode 100755
index 5899a9dbd..000000000
--- a/spec/integration/indirector/file_metadata/mounts.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-10-18.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/indirector/file_metadata/mounts'
-require 'shared_behaviours/file_server_mounts'
-
-describe Puppet::Indirector::FileMetadata::Mounts, " when finding files" do
- it_should_behave_like "Puppet::Indirector::FileServerMounts"
-
- before do
- @terminus = Puppet::Indirector::FileMetadata::Mounts.new
- @test_class = Puppet::FileServing::Metadata
- end
-end
diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb
index 67209fb39..3725a1286 100755
--- a/spec/integration/indirector/module_files.rb
+++ b/spec/integration/indirector/module_files.rb
@@ -19,7 +19,7 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module
FileTest.expects(:exists?).with(filepath).returns(true)
- @terminus.model.expects(:new).with(filepath)
+ @terminus.model.expects(:new).with(filepath, :links => nil)
@terminus.find("puppetmounts://host/modules/mymod/myfile")
end
diff --git a/spec/lib/shared_behaviours/file_server_mounts.rb b/spec/lib/shared_behaviours/file_server_terminus.rb
index 99a2f2953..e1ec35251 100644
--- a/spec/lib/shared_behaviours/file_server_mounts.rb
+++ b/spec/lib/shared_behaviours/file_server_terminus.rb
@@ -3,7 +3,7 @@
# Created by Luke Kanies on 2007-10-18.
# Copyright (c) 2007. All rights reserved.
-describe "Puppet::Indirector::FileServerMounts", :shared => true do
+describe "Puppet::Indirector::FileServerTerminus", :shared => true do
# This only works if the shared behaviour is included before
# the 'before' block in the including context.
before do
@@ -22,8 +22,6 @@ describe "Puppet::Indirector::FileServerMounts", :shared => true do
Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
- Puppet::FileServing::Configuration.create.stubs(:modules_mount)
-
# Stub out the modules terminus
@modules = mock 'modules terminus'
end
@@ -34,18 +32,10 @@ describe "Puppet::Indirector::FileServerMounts", :shared => true do
path = "/my/mount/path/my/file"
FileTest.stubs(:exists?).with(path).returns(true)
- @test_class.expects(:new).with(path).returns(:myinstance)
+ @test_class.expects(:new).with(path, :links => nil).returns(:myinstance)
FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
@mount1.expects(:file).with("my/file", :node => nil).returns(path)
@terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance
end
-
- it "should try to use the modules terminus to find files" do
- path = "puppetmounts://myhost/one/my/file"
- @modules.stubs(:find).with(path, {}).returns(:myinstance)
- @terminus.indirection.stubs(:terminus).with(:modules).returns(@modules)
-
- @terminus.find("puppetmounts://myhost/one/my/file").should == :myinstance
- end
end
diff --git a/spec/lib/shared_behaviours/file_serving.rb b/spec/lib/shared_behaviours/file_serving.rb
index ffc96ee78..6eaec6850 100644
--- a/spec/lib/shared_behaviours/file_serving.rb
+++ b/spec/lib/shared_behaviours/file_serving.rb
@@ -18,31 +18,33 @@ describe "Puppet::FileServing::Files", :shared => true do
@test_class.find(uri)
end
- it "should use the mounts terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'puppet'" do
+ it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'puppet'" do
uri = "puppet:///mymod/my/file"
Puppet.settings.stubs(:value).with(:name).returns("puppet")
+ Puppet.settings.stubs(:value).with(:modulepath, nil).returns("")
Puppet.settings.stubs(:value).with(:modulepath).returns("")
Puppet.settings.stubs(:value).with(:libdir).returns("")
Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever")
- @indirection.terminus(:mounts).expects(:find).with(uri)
+ Puppet.settings.stubs(:value).with(:environment).returns("")
+ @indirection.terminus(:file_server).expects(:find).with(uri)
@test_class.find(uri)
end
- it "should use the mounts terminus when the 'puppetmounts' URI scheme is used" do
+ it "should use the file_server terminus when the 'puppetmounts' URI scheme is used" do
uri = "puppetmounts:///mymod/my/file"
- @indirection.terminus(:mounts).expects(:find).with(uri)
+ @indirection.terminus(:file_server).expects(:find).with(uri)
@test_class.find(uri)
end
- it "should use the local terminus when the 'file' URI scheme is used" do
+ it "should use the file terminus when the 'file' URI scheme is used" do
uri = "file:///mymod/my/file"
- @indirection.terminus(:local).expects(:find).with(uri)
+ @indirection.terminus(:file).expects(:find).with(uri)
@test_class.find(uri)
end
- it "should use the local terminus when a fully qualified path is provided" do
+ it "should use the file terminus when a fully qualified path is provided" do
uri = "/mymod/my/file"
- @indirection.terminus(:local).expects(:find).with(uri)
+ @indirection.terminus(:file).expects(:find).with(uri)
@test_class.find(uri)
end
end
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb
index d491447e9..df46b9b6a 100755
--- a/spec/unit/file_serving/configuration.rb
+++ b/spec/unit/file_serving/configuration.rb
@@ -177,3 +177,51 @@ describe Puppet::FileServing::Configuration, " when finding files" do
@config.file_path("/one/something").should be_nil
end
end
+
+describe Puppet::FileServing::Configuration, " when checking authorization" do
+ include FSConfigurationTesting
+
+ before do
+ @parser = mock 'parser'
+ @parser.stubs(:changed?).returns true
+ FileTest.stubs(:exists?).with(@path).returns(true)
+ Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
+
+ @mount1 = stub 'mount', :name => "one"
+ @mounts = {"one" => @mount1}
+ @parser.stubs(:parse).returns(@mounts)
+
+ Facter.stubs(:value).with("hostname").returns("whatever")
+
+ @config = Puppet::FileServing::Configuration.create
+ end
+
+ it "should return false if the mount cannot be found" do
+ @config.authorized?("/nope/my/file").should be_false
+ end
+
+ it "should use the mount to determine authorization" do
+ @mount1.expects(:allowed?)
+ @config.authorized?("/one/my/file")
+ end
+
+ it "should pass the client's name to the mount if provided" do
+ @mount1.expects(:allowed?).with("myhost", nil)
+ @config.authorized?("/one/my/file", :node => "myhost")
+ end
+
+ it "should pass the client's IP to the mount if provided" do
+ @mount1.expects(:allowed?).with("myhost", "myip")
+ @config.authorized?("/one/my/file", :node => "myhost", :ipaddress => "myip")
+ end
+
+ it "should return true if the mount allows the client" do
+ @mount1.expects(:allowed?).returns(true)
+ @config.authorized?("/one/my/file").should be_true
+ end
+
+ it "should return false if the mount denies the client" do
+ @mount1.expects(:allowed?).returns(false)
+ @config.authorized?("/one/my/file").should be_false
+ end
+end
diff --git a/spec/unit/file_serving/content.rb b/spec/unit/file_serving/content.rb
index 593278bf4..e15aa8be6 100755
--- a/spec/unit/file_serving/content.rb
+++ b/spec/unit/file_serving/content.rb
@@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/content'
describe Puppet::FileServing::Content do
+ it "should should be a subclass of FileBase" do
+ Puppet::FileServing::Content.superclass.should equal(Puppet::FileServing::FileBase)
+ end
+
it "should indirect file_content" do
Puppet::FileServing::Content.indirection.name.should == :file_content
end
@@ -15,41 +19,80 @@ describe Puppet::FileServing::Content do
end
describe Puppet::FileServing::Content, " when initializing" do
+ it "should accept a file path" do
+ Puppet::FileServing::Content.new("not/qualified").path.should == "not/qualified"
+ end
+
+ it "should not allow a fully qualified file path" do
+ proc { Puppet::FileServing::Content.new("/fully/qualified") }.should raise_error(ArgumentError)
+ end
+
+ it "should allow specification of whether links should be managed" do
+ Puppet::FileServing::Content.new("not/qualified", :links => :manage)
+ end
+
+ it "should fail if :links is set to anything other than :manage or :follow" do
+ Puppet::FileServing::Content.new("not/qualified", :links => :manage)
+ end
+
+ it "should default to :manage for :links" do
+ Puppet::FileServing::Content.new("not/qualified", :links => :manage)
+ end
+end
+
+describe Puppet::FileServing::Content, " when returning the contents" do
before do
- @path = "/my/file"
+ @content = Puppet::FileServing::Content.new("sub/path", :links => :follow)
+ @base = "/my/base"
+ @full = "/my/base/sub/path"
end
- it "should accept a file path" do
- FileTest.expects(:exists?).with(@path).returns(true)
- Puppet::FileServing::Content.new(@path).path.should == @path
+ it "should fail if the file is a symlink and links are set to :manage" do
+ @content.links = :manage
+ File.expects(:lstat).with(@full).returns stub("stat", :ftype => "symlink")
+ proc { @content.content(@base) }.should raise_error(ArgumentError)
end
- it "should require a fully qualified file path" do
- proc { Puppet::FileServing::Content.new("unqualified") }.should raise_error(ArgumentError)
+ it "should accept a base path path to which the file should be relative" do
+ File.expects(:stat).with(@full).returns stub("stat", :ftype => "file")
+ File.expects(:read).with(@full).returns(:mycontent)
+ @content.content(@base).should == :mycontent
end
- it "should require the path to exist" do
- FileTest.expects(:exists?).with(@path).returns(false)
- proc { Puppet::FileServing::Content.new(@path) }.should raise_error(ArgumentError)
+ it "should use the set base path if one is not provided" do
+ @content.base_path = @base
+ File.expects(:stat).with(@full).returns stub("stat", :ftype => "file")
+ File.expects(:read).with(@full).returns(:mycontent)
+ @content.content()
end
- it "should not stat the file" do
- FileTest.expects(:exists?).with(@path).returns(true)
- File.expects(:read).with(@path).never
- Puppet::FileServing::Content.new(@path)
+ it "should fail if a base path is neither set nor provided" do
+ proc { @content.content() }.should raise_error(ArgumentError)
+ end
+
+ it "should raise Errno::ENOENT if the file is absent" do
+ @content.base_path = "/there/is/absolutely/no/chance/that/this/path/exists"
+ proc { @content.content() }.should raise_error(Errno::ENOENT)
+ end
+
+ it "should return the contents of the path if the file exists" do
+ File.expects(:stat).with(@full).returns stub("stat", :ftype => "file")
+ File.expects(:read).with(@full).returns(:mycontent)
+ @content.content(@base).should == :mycontent
end
end
describe Puppet::FileServing::Content, " when converting to yaml" do
- before do
- @path = "/my/file"
- FileTest.expects(:exists?).with(@path).returns(true)
- @content = Puppet::FileServing::Content.new(@path)
+ it "should fail if no base path has been set" do
+ @content = Puppet::FileServing::Content.new("some/path")
+ proc { @content.to_yaml }.should raise_error(ArgumentError)
end
it "should return the file contents" do
- File.expects(:read).with(@path).returns("mycontent")
- @content.to_yaml.should == "mycontent"
+ @content = Puppet::FileServing::Content.new("some/path")
+ @content.base_path = "/base/path"
+ @content.expects(:content).returns(:content)
+ @content.to_yaml.should == :content
end
end
diff --git a/spec/unit/file_serving/file_base.rb b/spec/unit/file_serving/file_base.rb
new file mode 100755
index 000000000..14be6d003
--- /dev/null
+++ b/spec/unit/file_serving/file_base.rb
@@ -0,0 +1,85 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/file_serving/file_base'
+
+describe Puppet::FileServing::FileBase, " when initializing" do
+ it "should accept a file path" do
+ Puppet::FileServing::FileBase.new("not/qualified").path.should == "not/qualified"
+ end
+
+ it "should not allow a fully qualified file path" do
+ proc { Puppet::FileServing::FileBase.new("/fully/qualified") }.should raise_error(ArgumentError)
+ end
+
+ it "should allow specification of whether links should be managed" do
+ Puppet::FileServing::FileBase.new("not/qualified", :links => :manage).links.should == :manage
+ end
+
+ it "should fail if :links is set to anything other than :manage or :follow" do
+ proc { Puppet::FileServing::FileBase.new("not/qualified", :links => :else) }.should raise_error(ArgumentError)
+ end
+
+ it "should default to :manage for :links" do
+ Puppet::FileServing::FileBase.new("not/qualified").links.should == :manage
+ end
+end
+
+describe Puppet::FileServing::FileBase do
+ it "should provide a method for setting the base path" do
+ @file = Puppet::FileServing::FileBase.new("not/qualified")
+ @file.base_path = "/something"
+ @file.base_path.should == "/something"
+ end
+end
+
+describe Puppet::FileServing::FileBase, " when determining the full file path" do
+ it "should return the provided path joined with the qualified path if a path is provided" do
+ @file = Puppet::FileServing::FileBase.new("not/qualified")
+ @file.full_path("/this/file").should == "/this/file/not/qualified"
+ end
+
+ it "should return the set base path joined with the qualified path if a base path is set" do
+ @file = Puppet::FileServing::FileBase.new("not/qualified")
+ @file.base_path = "/this/file"
+ @file.full_path.should == "/this/file/not/qualified"
+ end
+
+ it "should should fail if a base path is neither provided nor set" do
+ @file = Puppet::FileServing::FileBase.new("not/qualified")
+ proc { @file.full_path }.should raise_error(ArgumentError)
+ end
+end
+
+describe Puppet::FileServing::FileBase, " when stat'ing files" do
+ before do
+ @file = Puppet::FileServing::FileBase.new("not/qualified")
+ end
+
+ it "should join the provided path with the qualified path is a path is provided" do
+ File.expects(:lstat).with("/this/file/not/qualified").returns stub("stat", :ftype => "file")
+ @file.stat("/this/file")
+ end
+
+ it "should use the set base path if no base is provided" do
+ @file.base_path = "/this/file"
+ File.expects(:lstat).with("/this/file/not/qualified").returns stub("stat", :ftype => "file")
+ @file.stat
+ end
+
+ it "should fail if a base path is neither set nor provided" do
+ proc { @file.stat }.should raise_error(ArgumentError)
+ end
+
+ it "should use :lstat if :links is set to :manage" do
+ File.expects(:lstat).with("/this/file/not/qualified").returns stub("stat", :ftype => "file")
+ @file.stat("/this/file")
+ end
+
+ it "should use :stat if :links is set to :follow" do
+ File.expects(:stat).with("/this/file/not/qualified").returns stub("stat", :ftype => "file")
+ @file.links = :follow
+ @file.stat("/this/file")
+ end
+end
diff --git a/spec/unit/file_serving/fileset.rb b/spec/unit/file_serving/fileset.rb
new file mode 100755
index 000000000..2cd3e83dd
--- /dev/null
+++ b/spec/unit/file_serving/fileset.rb
@@ -0,0 +1,230 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/file_serving/fileset'
+
+describe Puppet::FileServing::Fileset, " when initializing" do
+ it "should require a path" do
+ proc { Puppet::FileServing::Fileset.new }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if its path is not fully qualified" do
+ proc { Puppet::FileServing::Fileset.new("some/file") }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if its path does not exist" do
+ File.expects(:lstat).with("/some/file").returns nil
+ proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a 'recurse' option" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ set = Puppet::FileServing::Fileset.new("/some/file", :recurse => true)
+ set.recurse.should be_true
+ end
+
+ it "should accept an 'ignore' option" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ set = Puppet::FileServing::Fileset.new("/some/file", :ignore => ".svn")
+ set.ignore.should == [".svn"]
+ end
+
+ it "should accept a 'links' option" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ set = Puppet::FileServing::Fileset.new("/some/file", :links => :manage)
+ set.links.should == :manage
+ end
+
+ it "should fail if 'links' is set to anything other than :manage or :follow" do
+ proc { Puppet::FileServing::Fileset.new("/some/file", :links => :whatever) }.should raise_error(ArgumentError)
+ end
+
+ it "should default to 'false' for recurse" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ Puppet::FileServing::Fileset.new("/some/file").recurse.should == false
+ end
+
+ it "should default to an empty ignore list" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ Puppet::FileServing::Fileset.new("/some/file").ignore.should == []
+ end
+
+ it "should default to :manage for links" do
+ File.expects(:lstat).with("/some/file").returns stub("stat")
+ Puppet::FileServing::Fileset.new("/some/file").links.should == :manage
+ end
+end
+
+describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
+ before do
+ @path = "/my/path"
+ File.expects(:lstat).with(@path).returns stub("stat")
+ @fileset = Puppet::FileServing::Fileset.new(@path)
+ end
+
+ it "should always recurse if :recurse is set to 'true'" do
+ @fileset.recurse = true
+ @fileset.recurse?(0).should be_true
+ end
+
+ it "should never recurse if :recurse is set to 'false'" do
+ @fileset.recurse = false
+ @fileset.recurse?(-1).should be_false
+ end
+
+ it "should recurse if :recurse is set to an integer and the current depth is less than that integer" do
+ @fileset.recurse = 1
+ @fileset.recurse?(0).should be_true
+ end
+
+ it "should recurse if :recurse is set to an integer and the current depth is equal to that integer" do
+ @fileset.recurse = 1
+ @fileset.recurse?(1).should be_true
+ end
+
+ it "should not recurse if :recurse is set to an integer and the current depth is greater than that integer" do
+ @fileset.recurse = 1
+ @fileset.recurse?(2).should be_false
+ end
+
+ it "should not recurse if :recurse is set to 0" do
+ @fileset.recurse = 0
+ @fileset.recurse?(-1).should be_false
+ end
+end
+
+describe Puppet::FileServing::Fileset, " when recursing" do
+ before do
+ @path = "/my/path"
+ File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
+ @fileset = Puppet::FileServing::Fileset.new(@path)
+
+ @dirstat = stub 'dirstat', :directory? => true
+ @filestat = stub 'filestat', :directory? => false
+ end
+
+ def mock_dir_structure(path, stat_method = :lstat)
+ File.stubs(stat_method).with(path).returns(@dirstat)
+ Dir.stubs(:entries).with(path).returns(%w{one two .svn CVS})
+
+ # Keep track of the files we're stubbing.
+ @files = %w{.}
+
+ %w{one two .svn CVS}.each do |subdir|
+ @files << subdir # relative path
+ subpath = File.join(path, subdir)
+ File.stubs(stat_method).with(subpath).returns(@dirstat)
+ Dir.stubs(:entries).with(subpath).returns(%w{.svn CVS file1 file2})
+ %w{file1 file2 .svn CVS}.each do |file|
+ @files << File.join(subdir, file) # relative path
+ File.stubs(stat_method).with(File.join(subpath, file)).returns(@filestat)
+ end
+ end
+ end
+
+ it "should recurse through the whole file tree if :recurse is set to 'true'" do
+ mock_dir_structure(@path)
+ @fileset.stubs(:recurse?).returns(true)
+ @fileset.files.sort.should == @files.sort
+ end
+
+ it "should not recurse if :recurse is set to 'false'" do
+ mock_dir_structure(@path)
+ @fileset.stubs(:recurse?).returns(false)
+ @fileset.files.should == %w{.}
+ end
+
+ # It seems like I should stub :recurse? here, or that I shouldn't stub the
+ # examples above, but...
+ it "should recurse to the level set if :recurse is set to an integer" do
+ mock_dir_structure(@path)
+ @fileset.recurse = 1
+ @fileset.files.should == %w{. one two .svn CVS}
+ end
+
+ it "should ignore the '.' and '..' directories in subdirectories" do
+ mock_dir_structure(@path)
+ @fileset.recurse = true
+ @fileset.files.sort.should == @files.sort
+ end
+
+ it "should ignore files that match a single pattern in the ignore list" do
+ mock_dir_structure(@path)
+ @fileset.recurse = true
+ @fileset.ignore = ".svn"
+ @fileset.files.find { |file| file.include?(".svn") }.should be_nil
+ end
+
+ it "should ignore files that match any of multiple patterns in the ignore list" do
+ mock_dir_structure(@path)
+ @fileset.recurse = true
+ @fileset.ignore = %w{.svn CVS}
+ @fileset.files.find { |file| file.include?(".svn") or file.include?("CVS") }.should be_nil
+ end
+
+ it "should use File.stat if :links is set to :follow" do
+ mock_dir_structure(@path, :stat)
+ @fileset.recurse = true
+ @fileset.links = :follow
+ @fileset.files.sort.should == @files.sort
+ end
+
+ it "should use File.lstat if :links is set to :manage" do
+ mock_dir_structure(@path, :lstat)
+ @fileset.recurse = true
+ @fileset.links = :manage
+ @fileset.files.sort.should == @files.sort
+ end
+end
+
+describe Puppet::FileServing::Fileset, " when following links that point to missing files" do
+ before do
+ @path = "/my/path"
+ File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
+ @fileset = Puppet::FileServing::Fileset.new(@path)
+ @fileset.links = :follow
+ @fileset.recurse = true
+
+ @stat = stub 'stat', :directory? => true
+
+ File.expects(:stat).with(@path).returns(@stat)
+ File.expects(:stat).with(File.join(@path, "mylink")).raises(Errno::ENOENT)
+ Dir.stubs(:entries).with(@path).returns(["mylink"])
+ end
+
+ it "should not fail" do
+ proc { @fileset.files }.should_not raise_error
+ end
+
+ it "should still manage the link" do
+ @fileset.files.sort.should == %w{. mylink}.sort
+ end
+end
+
+describe Puppet::FileServing::Fileset, " when ignoring" do
+ before do
+ @path = "/my/path"
+ File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
+ @fileset = Puppet::FileServing::Fileset.new(@path)
+ end
+
+ it "should use ruby's globbing to determine what files should be ignored" do
+ @fileset.ignore = ".svn"
+ File.expects(:fnmatch?).with(".svn", "my_file")
+ @fileset.ignore?("my_file")
+ end
+
+ it "should ignore files whose paths match a single provided ignore value" do
+ @fileset.ignore = ".svn"
+ File.stubs(:fnmatch?).with(".svn", "my_file").returns true
+ @fileset.ignore?("my_file").should be_true
+ end
+
+ it "should ignore files whose paths match any of multiple provided ignore values" do
+ @fileset.ignore = [".svn", "CVS"]
+ File.stubs(:fnmatch?).with(".svn", "my_file").returns false
+ File.stubs(:fnmatch?).with("CVS", "my_file").returns true
+ @fileset.ignore?("my_file").should be_true
+ end
+end
diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb
index 1237c3184..27ebe2471 100755
--- a/spec/unit/file_serving/metadata.rb
+++ b/spec/unit/file_serving/metadata.rb
@@ -15,40 +15,80 @@ describe Puppet::FileServing::Metadata do
end
describe Puppet::FileServing::Metadata, " when initializing" do
- it "should allow initialization without a path" do
- proc { Puppet::FileServing::Metadata.new() }.should_not raise_error
+ it "should not allow initialization without a path" do
+ proc { Puppet::FileServing::Metadata.new() }.should raise_error(ArgumentError)
end
- it "should allow initialization with a path" do
- proc { Puppet::FileServing::Metadata.new("unqualified") }.should raise_error(ArgumentError)
+ it "should not allow the path to be fully qualified if it is provided" do
+ proc { Puppet::FileServing::Metadata.new("/fully/qualified") }.should raise_error(ArgumentError)
end
- it "should the path to be fully qualified if it is provied" do
- proc { Puppet::FileServing::Metadata.new("unqualified") }.should raise_error(ArgumentError)
+ it "should allow initialization with a relative path" do
+ Puppet::FileServing::Metadata.new("not/fully/qualified")
end
- it "should require the path to exist if it is provided" do
- FileTest.expects(:exists?).with("/no/such/path").returns(false)
- proc { Puppet::FileServing::Metadata.new("/no/such/path") }.should raise_error(ArgumentError)
+ it "should allow specification of whether links should be managed" do
+ Puppet::FileServing::Metadata.new("not/qualified", :links => :manage)
+ end
+
+ it "should fail if :links is set to anything other than :manage or :follow" do
+ Puppet::FileServing::Metadata.new("not/qualified", :links => :manage)
+ end
+
+ it "should default to :manage for :links" do
+ Puppet::FileServing::Metadata.new("not/qualified", :links => :manage)
end
end
-describe Puppet::FileServing::Metadata do
+describe Puppet::FileServing::Metadata, " when finding the file to use for setting attributes" do
+ before do
+ @metadata = Puppet::FileServing::Metadata.new("my/path")
+
+ @base = "/base/path"
+ @full = "/base/path/my/path"
+
+ # Use a symlink because it's easier to test -- no checksumming
+ @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "symlink"
+ end
+
+ it "should accept a base path path to which the file should be relative" do
+ File.expects(:lstat).with(@full).returns @stat
+ File.expects(:readlink).with(@full).returns "/what/ever"
+ @metadata.collect_attributes(@base)
+ end
+
+ it "should use the set base path if one is not provided" do
+ @metadata.base_path = @base
+ File.expects(:lstat).with(@full).returns @stat
+ File.expects(:readlink).with(@full).returns "/what/ever"
+ @metadata.collect_attributes()
+ end
+
+ it "should fail if a base path is neither set nor provided" do
+ proc { @metadata.collect_attributes() }.should raise_error(ArgumentError)
+ end
+
+ it "should raise an exception if the file does not exist" do
+ File.expects(:lstat).with("/base/dir/my/path").raises(Errno::ENOENT)
+ proc { @metadata.collect_attributes("/base/dir")}.should raise_error(Errno::ENOENT)
+ end
+end
+
+describe Puppet::FileServing::Metadata, " when collecting attributes" do
before do
@path = "/my/file"
- @stat = mock 'stat', :uid => 10, :gid => 20, :mode => 0755
- File.stubs(:stat).returns(@stat)
+ @stat = stub 'stat', :uid => 10, :gid => 20, :mode => 0755, :ftype => "file"
+ File.stubs(:lstat).returns(@stat)
@filehandle = mock 'filehandle'
@filehandle.expects(:each_line).yields("some content\n")
File.stubs(:open).with(@path, 'r').yields(@filehandle)
@checksum = Digest::MD5.hexdigest("some content\n")
- FileTest.expects(:exists?).with(@path).returns(true)
- @metadata = Puppet::FileServing::Metadata.new(@path)
- @metadata.get_attributes
+ @metadata = Puppet::FileServing::Metadata.new("file")
+ @metadata.collect_attributes("/my")
end
it "should accept a file path" do
- @metadata.path.should == @path
+ @metadata.path.should == "file"
end
# LAK:FIXME This should actually change at some point
@@ -86,6 +126,28 @@ describe Puppet::FileServing::Metadata do
end
end
+describe Puppet::FileServing::Metadata, " when pointing to a symlink" do
+ it "should store the destination of the symlink in :destination if links are :manage" do
+ file = Puppet::FileServing::Metadata.new("my/file", :links => :manage)
+
+ File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755)
+ File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path"
+
+ file.collect_attributes("/base/path")
+ file.destination.should == "/some/other/path"
+ end
+
+ it "should not collect the checksum" do
+ file = Puppet::FileServing::Metadata.new("my/file", :links => :manage)
+
+ File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755)
+ File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path"
+
+ file.collect_attributes("/base/path")
+ file.checksum.should be_nil
+ end
+end
+
describe Puppet::FileServing::Metadata, " when converting from yaml" do
# LAK:FIXME This isn't in the right place, but we need some kind of
# control somewhere that requires that all REST connections only pull
diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb
index e9a7f6ddc..ebe058301 100755
--- a/spec/unit/file_serving/mount.rb
+++ b/spec/unit/file_serving/mount.rb
@@ -105,10 +105,6 @@ describe Puppet::FileServing::Mount, " when finding files" do
@mount.path().should == "/myhost/mydomain.com/myhost.mydomain.com"
end
- it "should ignore links by default"
-
- it "should follow links when asked"
-
after do
Puppet::FileServing::Mount.clear_cache
end
diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb
new file mode 100755
index 000000000..3a5274b5a
--- /dev/null
+++ b/spec/unit/file_serving/terminus_helper.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-22.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/file_serving/terminus_helper'
+
+describe Puppet::FileServing::TerminusHelper do
+ before do
+ @helper = Object.new
+ @helper.extend(Puppet::FileServing::TerminusHelper)
+
+ @model = mock 'model'
+ @helper.stubs(:model).returns(@model)
+ end
+
+ it "should use a fileset to find paths" do
+ fileset = mock 'fileset', :files => []
+ Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset)
+ @helper.path2instances("/my/file")
+ end
+
+ it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do
+ fileset = mock 'fileset', :files => []
+ Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset)
+ @helper.path2instances("/my/file", :links => :a, :ignore => :b, :recurse => :c)
+ end
+
+ it "should return an instance of the model for each path returned by the fileset" do
+ fileset = mock 'fileset', :files => %w{one two}
+ Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset)
+ @model.expects(:new).with("one").returns(:one)
+ @model.expects(:new).with("two").returns(:two)
+ @helper.path2instances("/my/file").should == [:one, :two]
+ end
+end
diff --git a/spec/unit/file_serving/terminus_selector.rb b/spec/unit/file_serving/terminus_selector.rb
index 341c60fea..9c2c01bfd 100755
--- a/spec/unit/file_serving/terminus_selector.rb
+++ b/spec/unit/file_serving/terminus_selector.rb
@@ -30,22 +30,34 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term
@object.select_terminus("puppet://host/module/file").should == :rest
end
- it "should choose :modules when the protocol is 'puppetmounts' and the mount name is 'modules'" do
- @object.select_terminus("puppetmounts://host/modules/mymod/file").should == :modules
+ it "should choose :file_server when the protocol is 'puppetmounts' and the mount name is not 'modules'" do
+ modules = mock 'modules'
+ @object.stubs(:terminus).with(:modules).returns(modules)
+ modules.stubs(:find_module).returns(nil)
+
+ @object.select_terminus("puppetmounts://host/notmodules/file").should == :file_server
end
- it "should choose :modules when no server name is provided, the process name is 'puppet', and the mount name is 'modules'" do
+ it "should choose :file_server when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do
+ modules = mock 'modules'
+ @object.stubs(:terminus).with(:modules).returns(modules)
+ modules.stubs(:find_module).returns(nil)
+
Puppet.settings.expects(:value).with(:name).returns("puppet")
- @object.select_terminus("puppet:///modules/mymod/file").should == :modules
+ @object.select_terminus("puppet:///notmodules/file").should == :file_server
end
- it "should choose :mounts when the protocol is 'puppetmounts' and the mount name is not 'modules'" do
- @object.select_terminus("puppetmounts://host/notmodules/file").should == :mounts
+ it "should choose :modules if it would normally choose :file_server but the mount name is 'modules'" do
+ @object.select_terminus("puppetmounts://host/modules/mymod/file").should == :modules
end
- it "should choose :mounts when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do
- Puppet.settings.expects(:value).with(:name).returns("puppet")
- @object.select_terminus("puppet:///notmodules/file").should == :mounts
+ it "should choose :modules it would normally choose :file_server but a module exists with the mount name" do
+ modules = mock 'modules'
+
+ @object.expects(:terminus).with(:modules).returns(modules)
+ modules.expects(:find_module).with("mymod", nil).returns(:thing)
+
+ @object.select_terminus("puppetmounts://host/mymod/file").should == :modules
end
it "should choose :rest when no server name is provided and the process name is not 'puppet'" do
@@ -53,20 +65,46 @@ describe Puppet::FileServing::TerminusSelector, " when being used to select term
@object.select_terminus("puppet:///module/file").should == :rest
end
- it "should choose :local when the protocol is 'file'" do
- @object.select_terminus("file://host/module/file").should == :local
+ it "should choose :file when the protocol is 'file'" do
+ @object.select_terminus("file://host/module/file").should == :file
end
- it "should choose :local when the URI is a normal path name" do
- @object.select_terminus("/module/file").should == :local
+ it "should choose :file when the URI is a normal path name" do
+ @object.select_terminus("/module/file").should == :file
end
- # This is so that we only choose modules over mounts, not local
- it "should choose :local when the protocol is 'file' and the fully qualified path starts with '/modules'" do
- @object.select_terminus("file://host/modules/file").should == :local
+ # This is so that we only choose modules over mounts, not file
+ it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do
+ @object.select_terminus("file://host/modules/file").should == :file
end
it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do
proc { @object.select_terminus("http:///module/file") }.should raise_error(ArgumentError)
end
end
+
+describe Puppet::FileServing::TerminusSelector, " when looking for a module whose name matches the mount name" do
+ before do
+ @object = Object.new
+ @object.extend(Puppet::FileServing::TerminusSelector)
+
+ @modules = mock 'modules'
+ @object.stubs(:terminus).with(:modules).returns(@modules)
+ end
+
+ it "should use the modules terminus to look up the module" do
+ @modules.expects(:find_module).with("mymod", nil)
+ @object.select_terminus("puppetmounts://host/mymod/my/file")
+ end
+
+ it "should pass the node name to the modules terminus" do
+ @modules.expects(:find_module).with("mymod", nil)
+ @object.select_terminus("puppetmounts://host/mymod/my/file")
+ end
+
+ it "should log a deprecation warning if a module is found" do
+ @modules.expects(:find_module).with("mymod", nil).returns(:something)
+ Puppet.expects(:warning)
+ @object.select_terminus("puppetmounts://host/mymod/my/file")
+ end
+end
diff --git a/spec/unit/indirector/file_content/file.rb b/spec/unit/indirector/file_content/file.rb
new file mode 100755
index 000000000..da2c90770
--- /dev/null
+++ b/spec/unit/indirector/file_content/file.rb
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_content/file'
+
+describe Puppet::Indirector::FileContent::File do
+ it "should be registered with the file_content indirection" do
+ Puppet::Indirector::Terminus.terminus_class(:file_content, :file).should equal(Puppet::Indirector::FileContent::File)
+ end
+
+ it "should be a subclass of the File terminus" do
+ Puppet::Indirector::FileContent::File.superclass.should equal(Puppet::Indirector::File)
+ end
+end
+
+describe Puppet::Indirector::FileContent::File, "when finding a single file" do
+ it "should return a Content instance created with the full path to the file if the file exists" do
+ @content = Puppet::Indirector::FileContent::File.new
+ @uri = "file:///my/local"
+
+ FileTest.expects(:exists?).with("/my/local").returns true
+ Puppet::FileServing::Content.expects(:new).with("/my/local", :links => nil).returns(:mycontent)
+ @content.find(@uri).should == :mycontent
+ end
+
+ it "should pass the :links setting on to the created Content instance if the file exists" do
+ @content = Puppet::Indirector::FileContent::File.new
+ @uri = "file:///my/local"
+
+ FileTest.expects(:exists?).with("/my/local").returns true
+ Puppet::FileServing::Content.expects(:new).with("/my/local", :links => :manage).returns(:mycontent)
+ @content.find(@uri, :links => :manage)
+ end
+
+ it "should return nil if the file does not exist" do
+ @content = Puppet::Indirector::FileContent::File.new
+ @uri = "file:///my/local"
+
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @content.find(@uri).should be_nil
+ end
+end
+
+describe Puppet::Indirector::FileContent::File, "when searching for multiple files" do
+ before do
+ @content = Puppet::Indirector::FileContent::File.new
+ @uri = "file:///my/local"
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @content.find(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if the file exists" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @content.expects(:path2instances).with("/my/local", {})
+ @content.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @content.expects(:path2instances).with("/my/local", :testing => :one, :other => :two)
+ @content.search(@uri, :testing => :one, :other => :two)
+ end
+end
diff --git a/spec/unit/indirector/file_content/mounts.rb b/spec/unit/indirector/file_content/file_server.rb
index 00149dfd4..a09c7e2f7 100755
--- a/spec/unit/indirector/file_content/mounts.rb
+++ b/spec/unit/indirector/file_content/file_server.rb
@@ -5,14 +5,14 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'puppet/indirector/file_content/mounts'
+require 'puppet/indirector/file_content/file_server'
-describe Puppet::Indirector::FileContent::Mounts do
+describe Puppet::Indirector::FileContent::FileServer do
it "should be registered with the file_content indirection" do
- Puppet::Indirector::Terminus.terminus_class(:file_content, :mounts).should equal(Puppet::Indirector::FileContent::Mounts)
+ Puppet::Indirector::Terminus.terminus_class(:file_content, :file_server).should equal(Puppet::Indirector::FileContent::FileServer)
end
it "should be a subclass of the FileServer terminus" do
- Puppet::Indirector::FileContent::Mounts.superclass.should equal(Puppet::Indirector::FileServer)
+ Puppet::Indirector::FileContent::FileServer.superclass.should equal(Puppet::Indirector::FileServer)
end
end
diff --git a/spec/unit/indirector/file_content/local.rb b/spec/unit/indirector/file_content/local.rb
deleted file mode 100755
index 361628767..000000000
--- a/spec/unit/indirector/file_content/local.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-10-18.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/indirector/file_content/local'
-
-describe Puppet::Indirector::FileContent::Local do
- it "should be registered with the file_content indirection" do
- Puppet::Indirector::Terminus.terminus_class(:file_content, :local).should equal(Puppet::Indirector::FileContent::Local)
- end
-
- it "should be a subclass of the File terminus" do
- Puppet::Indirector::FileContent::Local.superclass.should equal(Puppet::Indirector::File)
- end
-end
-
-describe Puppet::Indirector::FileContent::Local, "when finding a single file" do
- it "should return a Content instance created with the full path to the file if the file exists" do
- @content = Puppet::Indirector::FileContent::Local.new
- @uri = "file:///my/local"
-
- FileTest.expects(:exists?).with("/my/local").returns true
- Puppet::FileServing::Content.expects(:new).with("/my/local").returns(:mycontent)
- @content.find(@uri).should == :mycontent
- end
-
- it "should return nil if the file does not exist" do
- @content = Puppet::Indirector::FileContent::Local.new
- @uri = "file:///my/local"
-
- FileTest.expects(:exists?).with("/my/local").returns false
- @content.find(@uri).should be_nil
- end
-end
diff --git a/spec/unit/indirector/file_metadata/file.rb b/spec/unit/indirector/file_metadata/file.rb
new file mode 100755
index 000000000..c88d559a7
--- /dev/null
+++ b/spec/unit/indirector/file_metadata/file.rb
@@ -0,0 +1,82 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-18.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/file_metadata/file'
+
+describe Puppet::Indirector::FileMetadata::File do
+ it "should be registered with the file_metadata indirection" do
+ Puppet::Indirector::Terminus.terminus_class(:file_metadata, :file).should equal(Puppet::Indirector::FileMetadata::File)
+ end
+end
+
+describe Puppet::Indirector::FileMetadata::File, "when finding a single file" do
+ before do
+ @metadata = Puppet::Indirector::FileMetadata::File.new
+ @uri = "file:///my/local"
+
+ @data = mock 'metadata'
+ end
+
+ it "should return a Metadata instance created with the full path to the file if the file exists" do
+ @data.stubs(:collect_attributes)
+
+ FileTest.expects(:exists?).with("/my/local").returns true
+ Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data)
+ @metadata.find(@uri).should == @data
+ end
+
+ it "should pass the :links setting on to the created Content instance if the file exists" do
+ @data.stubs(:collect_attributes)
+
+ FileTest.expects(:exists?).with("/my/local").returns true
+ Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => :manage).returns(@data)
+ @metadata.find(@uri, :links => :manage)
+ end
+
+ it "should collect its attributes when a file is found" do
+ @data.expects(:collect_attributes)
+
+ FileTest.expects(:exists?).with("/my/local").returns true
+ Puppet::FileServing::Metadata.expects(:new).with("/my/local", :links => nil).returns(@data)
+ @metadata.find(@uri).should == @data
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @metadata.find(@uri).should be_nil
+ end
+end
+
+describe Puppet::Indirector::FileMetadata::File, "when searching for multiple files" do
+ before do
+ @metadata = Puppet::Indirector::FileMetadata::File.new
+ @uri = "file:///my/local"
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @metadata.find(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if the file exists" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", {}).returns([])
+ @metadata.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", :testing => :one, :other => :two).returns([])
+ @metadata.search(@uri, :testing => :one, :other => :two)
+ end
+
+ it "should collect the attributes of the instances returned" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", {}).returns( [mock("one", :collect_attributes => nil), mock("two", :collect_attributes => nil)] )
+ @metadata.search(@uri)
+ end
+end
diff --git a/spec/unit/indirector/file_metadata/mounts.rb b/spec/unit/indirector/file_metadata/file_server.rb
index 33f977163..40232a108 100755
--- a/spec/unit/indirector/file_metadata/mounts.rb
+++ b/spec/unit/indirector/file_metadata/file_server.rb
@@ -5,14 +5,14 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
-require 'puppet/indirector/file_metadata/mounts'
+require 'puppet/indirector/file_metadata/file_server'
-describe Puppet::Indirector::FileMetadata::Mounts do
+describe Puppet::Indirector::FileMetadata::FileServer do
it "should be registered with the file_metadata indirection" do
- Puppet::Indirector::Terminus.terminus_class(:file_metadata, :mounts).should equal(Puppet::Indirector::FileMetadata::Mounts)
+ Puppet::Indirector::Terminus.terminus_class(:file_metadata, :file_server).should equal(Puppet::Indirector::FileMetadata::FileServer)
end
it "should be a subclass of the FileServer terminus" do
- Puppet::Indirector::FileMetadata::Mounts.superclass.should equal(Puppet::Indirector::FileServer)
+ Puppet::Indirector::FileMetadata::FileServer.superclass.should equal(Puppet::Indirector::FileServer)
end
end
diff --git a/spec/unit/indirector/file_metadata/local.rb b/spec/unit/indirector/file_metadata/local.rb
deleted file mode 100755
index 604cdf6af..000000000
--- a/spec/unit/indirector/file_metadata/local.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-10-18.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/indirector/file_metadata/local'
-
-describe Puppet::Indirector::FileMetadata::Local do
- it "should be registered with the file_metadata indirection" do
- Puppet::Indirector::Terminus.terminus_class(:file_metadata, :local).should equal(Puppet::Indirector::FileMetadata::Local)
- end
-end
-
-describe Puppet::Indirector::FileMetadata::Local, "when finding a single file" do
- before do
- @content = Puppet::Indirector::FileMetadata::Local.new
- @uri = "file:///my/local"
-
- @data = mock 'metadata'
- end
- it "should return a Metadata instance created with the full path to the file if the file exists" do
- @data.stubs(:get_attributes)
-
- FileTest.expects(:exists?).with("/my/local").returns true
- Puppet::FileServing::Metadata.expects(:new).with("/my/local").returns(@data)
- @content.find(@uri).should == @data
- end
-
- it "should collect its attributes when a file is found" do
- @data.expects(:get_attributes)
-
- FileTest.expects(:exists?).with("/my/local").returns true
- Puppet::FileServing::Metadata.expects(:new).with("/my/local").returns(@data)
- @content.find(@uri).should == @data
- end
-
- it "should return nil if the file does not exist" do
- FileTest.expects(:exists?).with("/my/local").returns false
- @content.find(@uri).should be_nil
- end
-end
diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb
index 5a53610e4..ed36e180e 100755
--- a/spec/unit/indirector/file_server.rb
+++ b/spec/unit/indirector/file_server.rb
@@ -26,81 +26,128 @@ module FileServerTerminusTesting
@uri = "puppetmounts://host/my/local/file"
@configuration = mock 'configuration'
Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
-
- @module_server = mock 'module_server'
- @indirection.stubs(:terminus).with(:modules).returns(@module_server)
end
end
describe Puppet::Indirector::FileServer, " when finding files" do
include FileServerTerminusTesting
- it "should see if the modules terminus has the file" do
- @module_server.expects(:find).with(@uri, {})
- @configuration.stubs(:file_path)
- @file_server.find(@uri)
- end
-
- it "should pass the client name to the modules terminus if one is provided" do
- @module_server.expects(:find).with(@uri, :node => "mynode")
- @configuration.stubs(:file_path)
- @file_server.find(@uri, :node => "mynode")
- end
-
- it "should return any results from the modules terminus" do
- @module_server.expects(:find).with(@uri, {}).returns(:myinstance)
- @file_server.find(@uri).should == :myinstance
- end
-
- it "should produce a deprecation notice if it finds a file in the module terminus" do
- @module_server.expects(:find).with(@uri, {}).returns(:myinstance)
- Puppet.expects(:warning)
- @file_server.find(@uri)
- end
-
it "should use the path portion of the URI as the file name" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri)
end
it "should use the FileServing configuration to convert the file name to a fully qualified path" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri)
end
it "should pass the node name to the FileServing configuration if one is provided" do
@configuration.expects(:file_path).with("/my/local/file", :node => "testing")
- @module_server.stubs(:find)
@file_server.find(@uri, :node => "testing")
end
it "should return nil if no fully qualified path is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri).should be_nil
end
- it "should return nil if the configuration returns a file path that does not exist" do
+ it "should return an instance of the model created with the full path if a file is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(false)
- @module_server.stubs(:find).returns(nil)
- @file_server.find(@uri).should be_nil
+ @model.expects(:new).with("/some/file", :links => nil).returns(:myinstance)
+ @file_server.find(@uri).should == :myinstance
end
+end
- it "should return an instance of the model created with the full path if a file is found and it exists" do
+
+describe Puppet::Indirector::FileServer, " when returning instances" do
+ include FileServerTerminusTesting
+
+ it "should pass the provided :links setting on to the instance if one is provided" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(true)
- @module_server.stubs(:find).returns(nil)
- @model.expects(:new).with("/some/file").returns(:myinstance)
- @file_server.find(@uri).should == :myinstance
+ @model.expects(:new).with("/some/file", :links => :mytest)
+ @file_server.find(@uri, :links => :mytest)
end
end
+describe Puppet::Indirector::FileServer, " when checking authorization" do
+ include FileServerTerminusTesting
+
+ it "should have an authorization hook" do
+ @file_server.should respond_to(:authorized?)
+ end
-describe Puppet::Indirector::FileServer, " when returning file paths" do
- it "should follow links if the links option is set to :follow"
+ it "should deny the :destroy method" do
+ @file_server.authorized?(:destroy, "whatever").should be_false
+ end
- it "should ignore links if the links option is not set to follow"
+ it "should deny the :save method" do
+ @file_server.authorized?(:save, "whatever").should be_false
+ end
+
+ it "should use the file server configuration to determine authorization" do
+ @configuration.expects(:authorized?)
+ @file_server.authorized?(:find, "puppetmounts://host/my/file")
+ end
+
+ it "should pass the file path from the URI to the file server configuration" do
+ @configuration.expects(:authorized?).with { |uri, *args| uri == "/my/file" }
+ @file_server.authorized?(:find, "puppetmounts://host/my/file")
+ end
+
+ it "should pass the node name to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" }
+ @file_server.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode")
+ end
+
+ it "should pass the IP address to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" }
+ @file_server.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip")
+ end
+
+ it "should return false if the file server configuration denies authorization" do
+ @configuration.expects(:authorized?).returns(false)
+ @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_false
+ end
+
+ it "should return true if the file server configuration approves authorization" do
+ @configuration.expects(:authorized?).returns(true)
+ @file_server.authorized?(:find, "puppetmounts://host/my/file").should be_true
+ end
+end
+
+describe Puppet::Indirector::FileServer, " when searching for files" do
+ include FileServerTerminusTesting
+
+ it "should use the path portion of the URI as the file name" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @file_server.search(@uri)
+ end
+
+ it "should use the FileServing configuration to convert the file name to a fully qualified path" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @file_server.search(@uri)
+ end
+
+ it "should pass the node name to the FileServing configuration if one is provided" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => "testing")
+ @file_server.search(@uri, :node => "testing")
+ end
+
+ it "should return nil if no fully qualified path is found" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
+ @file_server.search(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
+ @file_server.expects(:path2instances).with("/my/file", {})
+ @file_server.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
+ @file_server.expects(:path2instances).with("/my/file", :testing => :one, :other => :two)
+ @file_server.search(@uri, :testing => :one, :other => :two)
+ end
end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 70b869bad..00153ff35 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -20,7 +20,7 @@ module IndirectionTesting
end
describe Puppet::Indirector::Indirection, " when initializing" do
- # LAK:FIXME I've no idea how to test this, really.
+ # (LAK) I've no idea how to test this, really.
it "should store a reference to itself before it consumes its options" do
proc { @indirection = Puppet::Indirector::Indirection.new(Object.new, :testingness, :not_valid_option) }.should raise_error
Puppet::Indirector::Indirection.instance(:testingness).should be_instance_of(Puppet::Indirector::Indirection)
@@ -257,6 +257,13 @@ describe Puppet::Indirector::Indirection, " when a select_terminus hook is avail
@indirection.find(@uri).should == :whatever
end
+ it "should pass all arguments to the :select_terminus hook" do
+ @indirection.expects(:select_terminus).with(@uri, :node => "johnny").returns(:other)
+ @other_terminus.stubs(:find)
+
+ @indirection.find(@uri, :node => "johnny")
+ end
+
it "should pass the original key to the terminus rather than a modified key" do
# This is the same test as before
@other_terminus.expects(:find).with(@uri).returns(@result)
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb
index 2e1373748..f2e43f771 100755
--- a/spec/unit/indirector/module_files.rb
+++ b/spec/unit/indirector/module_files.rb
@@ -65,7 +65,7 @@ describe Puppet::Indirector::ModuleFiles, " when finding files" do
it "should return an instance of the model created with the full path if a module is found and the file exists" do
Puppet::Module.expects(:find).with('my', nil).returns @module
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
- @model.expects(:new).with("/module/path/files/local/file").returns(:myinstance)
+ @model.expects(:new).with("/module/path/files/local/file", :links => nil).returns(:myinstance)
@module_files.find(@uri).should == :myinstance
end
@@ -82,15 +82,145 @@ describe Puppet::Indirector::ModuleFiles, " when finding files" do
@module_files.find(@uri)
end
- it "should not us an environment when looking up the module if the node name is not provided and the environment is set to ''" do
+ it "should not use an environment when looking up the module if the node name is not provided and the environment is set to ''" do
Puppet.settings.stubs(:value).with(:environment).returns("")
Puppet::Module.expects(:find).with('my', nil)
@module_files.find(@uri)
end
end
-describe Puppet::Indirector::ModuleFiles, " when returning file paths" do
- it "should follow links if the links option is set to :follow"
+describe Puppet::Indirector::ModuleFiles, " when returning instances" do
+ include ModuleFilesTerminusTesting
+
+ it "should pass the provided :links setting on to the instance if one is provided" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @model.expects(:new).with("/module/path/files/local/file", :links => :mytest)
+ @module_files.find(@uri, :links => :mytest)
+ end
+end
+
+describe Puppet::Indirector::ModuleFiles, " when authorizing" do
+ include ModuleFilesTerminusTesting
+
+ before do
+ @configuration = mock 'configuration'
+ Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
+ end
+
+ it "should have an authorization hook" do
+ @module_files.should respond_to(:authorized?)
+ end
+
+ it "should deny the :destroy method" do
+ @module_files.authorized?(:destroy, "whatever").should be_false
+ end
+
+ it "should deny the :save method" do
+ @module_files.authorized?(:save, "whatever").should be_false
+ end
+
+ it "should use the file server configuration to determine authorization" do
+ @configuration.expects(:authorized?)
+ @module_files.authorized?(:find, "puppetmounts://host/my/file")
+ end
+
+ it "should use the path directly from the URI if it already includes /modules" do
+ @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" }
+ @module_files.authorized?(:find, "puppetmounts://host/modules/my/file")
+ end
+
+ it "should add /modules to the file path if it's not included in the URI" do
+ @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" }
+ @module_files.authorized?(:find, "puppetmounts://host/my/file")
+ end
+
+ it "should pass the node name to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" }
+ @module_files.authorized?(:find, "puppetmounts://host/my/file", :node => "mynode")
+ end
+
+ it "should pass the IP address to the file server configuration" do
+ @configuration.expects(:authorized?).with { |key, options| options[:ipaddress] == "myip" }
+ @module_files.authorized?(:find, "puppetmounts://host/my/file", :ipaddress => "myip")
+ end
+
+ it "should return false if the file server configuration denies authorization" do
+ @configuration.expects(:authorized?).returns(false)
+ @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_false
+ end
+
+ it "should return true if the file server configuration approves authorization" do
+ @configuration.expects(:authorized?).returns(true)
+ @module_files.authorized?(:find, "puppetmounts://host/my/file").should be_true
+ end
+end
+
+describe Puppet::Indirector::ModuleFiles, " when searching for files" do
+ include ModuleFilesTerminusTesting
+
+ it "should strip off the leading '/modules' mount name" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.search(@uri)
+ end
+
+ it "should not strip off leading terms that start with '/modules' but are longer words" do
+ Puppet::Module.expects(:find).with('modulestart', nil).returns nil
+ @module_files.search("puppetmounts://host/modulestart/my/local/file")
+ end
- it "should ignore links if the links option is not set to follow"
+ it "should search for a module whose name is the first term in the remaining file path" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.search(@uri)
+ end
+
+ it "should search for a file relative to the module's files directory" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file")
+ @module_files.search(@uri)
+ end
+
+ it "should return nil if the module does not exist" do
+ Puppet::Module.expects(:find).with('my', nil).returns nil
+ @module_files.search(@uri).should be_nil
+ end
+
+ it "should return nil if the module exists but the file does not" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
+ @module_files.search(@uri).should be_nil
+ end
+
+ it "should use the node's environment to look up the module if the node name is provided" do
+ node = stub "node", :environment => "testing"
+ Puppet::Node.expects(:find).with("mynode").returns(node)
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.search(@uri, :node => "mynode")
+ end
+
+ it "should use the local environment setting to look up the module if the node name is not provided and the environment is not set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("testing")
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.search(@uri)
+ end
+
+ it "should not use an environment when looking up the module if the node name is not provided and the environment is set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("")
+ Puppet::Module.expects(:find).with('my', nil)
+ @module_files.search(@uri)
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @module_files.expects(:path2instances).with("/module/path/files/local/file", {})
+ @module_files.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @module_files.expects(:path2instances).with("/module/path/files/local/file", :testing => :one, :other => :two)
+ @module_files.search(@uri, :testing => :one, :other => :two)
+ end
end
diff --git a/spec/unit/indirector/ssl_rsa/file.rb b/spec/unit/indirector/ssl_rsa/file.rb
new file mode 100755
index 000000000..76e5e3a94
--- /dev/null
+++ b/spec/unit/indirector/ssl_rsa/file.rb
@@ -0,0 +1,116 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-9-22.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/sslcertificates/monkey_patch'
+require 'puppet/indirector/ssl_rsa/file'
+
+
+describe Puppet::Indirector::SslRsa::File do
+
+ it "should be a subclass of the File terminus class" do
+ Puppet::Indirector::SslRsa::File.superclass.should equal(Puppet::Indirector::File)
+ end
+
+ it "should have documentation" do
+ Puppet::Indirector::SslRsa::File.doc.should be_instance_of(String)
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when choosing a path for a ca key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+ @name = :ca
+ end
+
+ it "should use the cadir" do
+ Puppet.settings.stubs(:value).with(:cadir).returns("/dir")
+ @file.path(@name).should =~ /^\/dir/
+ end
+
+ it "should use 'ca_key.pem' as the file name" do
+ @file.path(@name).should =~ /ca_key\.pem$/
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when choosing a path for a non-ca key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+ @name = :publickey
+ end
+
+ it "should use the publickeydir" do
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @file.path(@name).should =~ /^\/dir/
+ end
+
+ it "should use the key name with the pem file extension" do
+ @file.path(@name).should =~ /#{@name}\.pem$/
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when saving" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @key = stub "key", :name => "foo"
+ end
+
+ it "should store the rsa key to disk in pem format" do
+ @key.expects(:to_pem).returns(:data)
+ @path = "/dir/foo.pem"
+ filehandle = mock "filehandle"
+ File.expects(:open).with(@path, "w").yields(filehandle)
+ filehandle.expects(:print).with(:data)
+ @file.save(@key)
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when finding a key by name" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @name = "foo"
+ end
+
+ it "should return the key as a key object on success" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(true)
+ File.stubs(:read).with(@path).returns(:data)
+ OpenSSL::PKey::RSA.expects(:new).with(:data).returns(:mykey)
+ @file.find(@name).should == :mykey
+ end
+
+ it "should return 'nil' on failure" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(false)
+ @file.find(@name).should == nil
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when removing a key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @name = "foo"
+ end
+
+ it "should remove the key from disk and return true" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(true)
+ File.stubs(:unlink).with(@path).returns(true)
+ @file.destroy(@name).should == true
+ end
+
+ it "should return an exception on failure" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(false)
+ @file.destroy(@name).should == nil
+ end
+end