summaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-03-15 14:16:09 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commite5a78009f6bd593e7e3957f0dadb470e623396dd (patch)
treef1d386962e4a7ef5b4e20347653e570dccd141bf /spec/integration
parentf838389da0530201849958444dbbe60977935ad0 (diff)
Feature #3347 REST-ified FileBucket
FileBucket Files have been reimplemented as an indirector terminus so that they can be transmitted over REST. The old Network::Client.dipper has been replaced with a compatibility later in FileBucket::Dipper that uses the indirector to access filebucket termini. Slightly revised patch: * No longer allows nil contents in FileBucket outside of initialization * Uses File.exist? instead of the deprecated File.exists? * Tweaks JSON serialization and de-serialization to include "path" Deferred issues: * Feature #3371 "FileBucket should not keep files in memory". * Feature #3372 "Replace FileBucket Dipper with more idiomatic calls"
Diffstat (limited to 'spec/integration')
-rwxr-xr-xspec/integration/checksum.rb48
-rw-r--r--spec/integration/indirector/bucket_file/rest.rb68
-rwxr-xr-xspec/integration/network/client.rb2
3 files changed, 69 insertions, 49 deletions
diff --git a/spec/integration/checksum.rb b/spec/integration/checksum.rb
deleted file mode 100755
index 49ae8d2b7..000000000
--- a/spec/integration/checksum.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/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/checksum'
-
-describe Puppet::Checksum, " when using the file terminus" do
- before do
- Puppet.settings.stubs(:use)
- Puppet::Checksum.terminus_class = :file
- @content = "this is some content"
- @sum = Puppet::Checksum.new(@content)
-
- @file = Puppet::Checksum.indirection.terminus.path(@sum.checksum)
- end
-
- it "should store content at a path determined by its checksum" do
- File.stubs(:directory?).returns(true)
- filehandle = mock 'filehandle'
- filehandle.expects(:print).with(@content)
- File.expects(:open).with(@file, "w").yields(filehandle)
-
- @sum.save
- end
-
- it "should retrieve stored content when the checksum is provided as the key" do
- File.stubs(:exist?).returns(true)
- File.expects(:read).with(@file).returns(@content)
-
- newsum = Puppet::Checksum.find(@sum.checksum)
-
- newsum.content.should == @content
- end
-
- it "should remove specified files when asked" do
- File.stubs(:exist?).returns(true)
- File.expects(:unlink).with(@file)
-
- Puppet::Checksum.destroy(@sum.name)
- end
-
- after do
- Puppet.settings.clear
- end
-end
diff --git a/spec/integration/indirector/bucket_file/rest.rb b/spec/integration/indirector/bucket_file/rest.rb
new file mode 100644
index 000000000..296b03eb6
--- /dev/null
+++ b/spec/integration/indirector/bucket_file/rest.rb
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/file_bucket/file'
+require 'puppet/network/server'
+require 'puppet/network/http/webrick/rest'
+
+describe "Filebucket REST Terminus" do
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @host = Puppet::SSL::Host.new(Puppet[:certname])
+
+ @params = { :port => 34343, :handlers => [ :file_bucket_file ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ @old_terminus = Puppet::FileBucket::File.indirection.terminus_class
+ Puppet::FileBucket::File.terminus_class = :rest
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
+ # return.
+ @file_bucket_file = stub_everything 'file_bucket_file'
+ @mock_model = stub('faked model', :name => "file_bucket_file", :convert_from => @file_bucket_file)
+ Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
+
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ Puppet::FileBucket::File.terminus_class = @old_terminus
+ end
+
+ it "should be able save a file to the remote filebucket" do
+ @file_bucket_file.expects(:save)
+
+ file_bucket_file = Puppet::FileBucket::File.new("pouet")
+ file_bucket_file.save()
+ end
+end
diff --git a/spec/integration/network/client.rb b/spec/integration/network/client.rb
index 970763712..fe1524e60 100755
--- a/spec/integration/network/client.rb
+++ b/spec/integration/network/client.rb
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/client'
describe Puppet::Network::Client do
- %w{ca dipper file report resource runner status}.each do |name|
+ %w{ca file report resource runner status}.each do |name|
it "should have a #{name} client" do
Puppet::Network::Client.client(name).should be_instance_of(Class)
end