summaryrefslogtreecommitdiffstats
path: root/spec/unit/application
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-13 12:18:37 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-13 14:33:03 -0800
commit1a6fab2aacbc1499a00a9451654073181435afa1 (patch)
tree9615f8b92976fbf90fd55aaa2a077a12237dd830 /spec/unit/application
parenta7cd1856f3347b6a00a260d1001252b56f54f7de (diff)
downloadpuppet-1a6fab2aacbc1499a00a9451654073181435afa1.tar.gz
puppet-1a6fab2aacbc1499a00a9451654073181435afa1.tar.xz
puppet-1a6fab2aacbc1499a00a9451654073181435afa1.zip
(#5171) Made "puppet inspect" upload audited files to a file bucket
This only occurs if the new setting :archive_files is set. Another new setting, :archive_file_server, can be used to specify the server that files should be uploaded to. Paired-with: Nick Lewis <nick@puppetlabs.com>
Diffstat (limited to 'spec/unit/application')
-rw-r--r--spec/unit/application/inspect_spec.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb
index b3224d577..0c7b61f59 100644
--- a/spec/unit/application/inspect_spec.rb
+++ b/spec/unit/application/inspect_spec.rb
@@ -6,8 +6,11 @@ require 'puppet/application/inspect'
require 'puppet/resource/catalog'
require 'puppet/indirector/catalog/yaml'
require 'puppet/indirector/report/rest'
+require 'puppet/indirector/file_bucket_file/rest'
describe Puppet::Application::Inspect do
+ include PuppetSpec::Files
+
before :each do
@inspect = Puppet::Application[:inspect]
end
@@ -113,6 +116,87 @@ describe Puppet::Application::Inspect do
end
properties.should == {"ensure" => :absent}
end
+
+ describe "when archiving to a bucket" do
+ before :each do
+ Puppet[:archive_files] = true
+ Puppet[:archive_file_server] = "filebucketserver"
+ @catalog = Puppet::Resource::Catalog.new
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
+ end
+
+ describe "when auditing files" do
+ before :each do
+ @file = tmpfile("foo")
+ @resource = Puppet::Resource.new(:file, @file, :parameters => {:audit => "content"})
+ @catalog.add_resource(@resource)
+ end
+
+ it "should send an existing file to the file bucket" do
+ File.open(@file, 'w') { |f| f.write('stuff') }
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).with do |request|
+ request.server == Puppet[:archive_file_server]
+ end.returns(false)
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).with do |request|
+ request.server == Puppet[:archive_file_server] and request.instance.contents == 'stuff'
+ end
+ @inspect.run_command
+ end
+
+ it "should not send unreadable files" do
+ pending "see bug #5882"
+ File.open(@file, 'w') { |f| f.write('stuff') }
+ File.chmod(0, @file)
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+
+ it "should not try to send non-existent files" do
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+
+ it "should not try to send files whose content we are not auditing" do
+ @resource[:audit] = "group"
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+ end
+
+ describe "when auditing non-files" do
+ before :each do
+ Puppet::Type.newtype(:stub_type) do
+ newparam(:name) do
+ desc "The name var"
+ isnamevar
+ end
+
+ newproperty(:content) do
+ desc "content"
+ def retrieve
+ :whatever
+ end
+ end
+ end
+
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
+ @catalog.add_resource(@resource)
+ end
+
+ after :each do
+ Puppet::Type.rmtype(:stub_type)
+ end
+
+ it "should not try to send non-files" do
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+ end
+ end
end
after :all do