summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-12-27 23:25:25 -0800
committerPatrick <patrick@puppetlabs.com>2011-12-29 16:21:38 -0800
commit81c73fd0d0d0a9ad4a7f2cb5386d5956739a89aa (patch)
tree33b48d183285480ca2b5b52c6a2ada178feff7ec
parent26093a8f8de214a2db982e1c70a987eb67496652 (diff)
downloadpuppet-81c73fd0d0d0a9ad4a7f2cb5386d5956739a89aa.tar.gz
(#8296) Remove XMLRPC code
The XMLRPC code was left in place to ensure backward compatibility with Puppet 0.24.x clients, but 0.24.x clients haven't been able to talk to masters since 0.25.6 due to other bugs and incompatibilities. Therefore, the XMLRPC code has been dead code for a long time and removing it makes the codebase a lot easier to navigate. Paired with Patrick Carlisle <patrick@puppetlabs.com>
-rwxr-xr-xinstall.rb2
-rw-r--r--lib/puppet/application/agent.rb29
-rw-r--r--lib/puppet/application/master.rb8
-rw-r--r--lib/puppet/feature/base.rb2
-rw-r--r--lib/puppet/file_serving/metadata.rb14
-rw-r--r--lib/puppet/module.rb5
-rw-r--r--lib/puppet/network/handler.rb50
-rw-r--r--lib/puppet/network/handler/ca.rb61
-rwxr-xr-xlib/puppet/network/handler/filebucket.rb53
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb732
-rwxr-xr-xlib/puppet/network/handler/report.rb82
-rwxr-xr-xlib/puppet/network/handler/runner.rb33
-rw-r--r--lib/puppet/network/handler/status.rb18
-rw-r--r--lib/puppet/network/http/mongrel.rb8
-rw-r--r--lib/puppet/network/http/rack.rb18
-rw-r--r--lib/puppet/network/http/rack/xmlrpc.rb65
-rw-r--r--lib/puppet/network/http/webrick.rb16
-rw-r--r--lib/puppet/network/http_server.rb3
-rw-r--r--lib/puppet/network/http_server/mongrel.rb129
-rw-r--r--lib/puppet/network/rest_authconfig.rb4
-rw-r--r--lib/puppet/network/server.rb31
-rw-r--r--lib/puppet/network/xmlrpc/processor.rb86
-rw-r--r--lib/puppet/network/xmlrpc/server.rb19
-rw-r--r--lib/puppet/network/xmlrpc/webrick_servlet.rb114
-rw-r--r--lib/puppet/reference/network.rb39
-rw-r--r--lib/puppet/type/file.rb1
-rwxr-xr-xspec/integration/network/handler_spec.rb24
-rwxr-xr-xspec/integration/network/server/webrick_spec.rb2
-rwxr-xr-xspec/unit/application/agent_spec.rb21
-rwxr-xr-xspec/unit/application/master_spec.rb24
-rwxr-xr-xspec/unit/file_serving/metadata_spec.rb26
-rwxr-xr-xspec/unit/module_spec.rb16
-rw-r--r--spec/unit/network/handler/ca_spec.rb86
-rwxr-xr-xspec/unit/network/handler/fileserver_spec.rb201
-rwxr-xr-xspec/unit/network/http/mongrel/xmlrpc_spec.rb0
-rwxr-xr-xspec/unit/network/http/mongrel_spec.rb28
-rwxr-xr-xspec/unit/network/http/rack/xmlrpc_spec.rb155
-rwxr-xr-xspec/unit/network/http/rack_spec.rb35
-rwxr-xr-xspec/unit/network/http/webrick/xmlrpc_spec.rb0
-rwxr-xr-xspec/unit/network/http/webrick_spec.rb55
-rwxr-xr-xspec/unit/network/server_spec.rb92
-rw-r--r--test/lib/puppettest/servertest.rb41
-rwxr-xr-xtest/network/handler/fileserver.rb1260
-rwxr-xr-xtest/network/handler/report.rb83
-rwxr-xr-xtest/network/handler/runner.rb20
-rwxr-xr-xtest/network/xmlrpc/processor.rb79
-rwxr-xr-xtest/network/xmlrpc/server.rb26
-rwxr-xr-xtest/network/xmlrpc/webrick_servlet.rb35
48 files changed, 23 insertions, 3908 deletions
diff --git a/install.rb b/install.rb
index d015c4d3f..0dc2d52e3 100755
--- a/install.rb
+++ b/install.rb
@@ -53,7 +53,7 @@ rescue LoadError
$haverdoc = false
end
-PREREQS = %w{openssl facter xmlrpc/client xmlrpc/server cgi}
+PREREQS = %w{openssl facter cgi}
MIN_FACTER_VERSION = 1.5
InstallOptions = OpenStruct.new
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 3cee7c374..eb747b96f 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -49,14 +49,6 @@ class Puppet::Application::Agent < Puppet::Application
option("--fingerprint")
option("--digest DIGEST")
- option("--serve HANDLER", "-s") do |arg|
- if Puppet::Network::Handler.handler(arg)
- options[:serve] << arg.to_sym
- else
- raise "Could not find handler for #{arg}"
- end
- end
-
option("--no-client") do |arg|
options[:client] = false
end
@@ -103,7 +95,7 @@ USAGE
puppet agent [--certname <name>] [-D|--daemonize|--no-daemonize]
[-d|--debug] [--detailed-exitcodes] [--digest <digest>] [--disable] [--enable]
[--fingerprint] [-h|--help] [-l|--logdest syslog|<file>|console]
- [--no-client] [--noop] [-o|--onetime] [--serve <handler>] [-t|--test]
+ [--no-client] [--noop] [-o|--onetime] [-t|--test]
[-v|--verbose] [-V|--version] [-w|--waitforcert <seconds>]
@@ -247,15 +239,6 @@ configuration options can also be generated by running puppet agent with
run. Useful for interactively running puppet agent when used in
conjunction with the --no-daemonize option.
-* --serve:
- Start another type of server. By default, 'puppet agent' will start a
- service handler that allows authenticated and authorized remote nodes
- to trigger the configuration to be pulled down and applied. You can
- specify any handler here that does not require configuration, e.g.,
- filebucket, ca, or resource. The handlers are in
- 'lib/puppet/network/handler', and the names must match exactly, both
- in the call to 'serve' and in 'namespaceauth.conf'.
-
* --test:
Enable the most common options used for testing. These are 'onetime',
'verbose', 'ignorecache', 'no-daemonize', 'no-usecacheonfailure',
@@ -395,17 +378,9 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
exit(14)
end
- handlers = nil
-
- if options[:serve].empty?
- handlers = [:Runner]
- else
- handlers = options[:serve]
- end
-
require 'puppet/network/server'
# No REST handlers yet.
- server = Puppet::Network::Server.new(:xmlrpc_handlers => handlers, :port => Puppet[:puppetport])
+ server = Puppet::Network::Server.new(:port => Puppet[:puppetport])
@daemon.server = server
end
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index b4da770f0..1c7a025f5 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -166,10 +166,6 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
require 'puppet/file_serving/content'
require 'puppet/file_serving/metadata'
- xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
-
- xmlrpc_handlers << :CA if Puppet[:ca]
-
# Make sure we've got a localhost ssl cert
Puppet::SSL::Host.localhost
@@ -189,11 +185,11 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
unless options[:rack]
require 'puppet/network/server'
- @daemon.server = Puppet::Network::Server.new(:xmlrpc_handlers => xmlrpc_handlers)
+ @daemon.server = Puppet::Network::Server.new()
@daemon.daemonize if Puppet[:daemonize]
else
require 'puppet/network/http/rack'
- @app = Puppet::Network::HTTP::Rack.new(:xmlrpc_handlers => xmlrpc_handlers, :protocols => [:rest, :xmlrpc])
+ @app = Puppet::Network::HTTP::Rack.new(:protocols => [:rest])
end
Puppet.notice "Starting Puppet master version #{Puppet.version}"
diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb
index 8813197a8..7e60734b4 100644
--- a/lib/puppet/feature/base.rb
+++ b/lib/puppet/feature/base.rb
@@ -44,7 +44,7 @@ Puppet.features.add(:libshadow, :libs => ["shadow"])
Puppet.features.add(:root) { require 'puppet/util/suidmanager'; Puppet::Util::SUIDManager.root? }
# We've got mongrel available
-Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/http_server/mongrel})
+Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/http/mongrel})
# We have lcs diff
Puppet.features.add :diff, :libs => %w{diff/lcs diff/lcs/hunk}
diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb
index 587c2196d..131f9cb8b 100644
--- a/lib/puppet/file_serving/metadata.rb
+++ b/lib/puppet/file_serving/metadata.rb
@@ -17,20 +17,6 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
PARAM_ORDER = [:mode, :ftype, :owner, :group]
- def attributes_with_tabs
- raise(ArgumentError, "Cannot manage files of type #{ftype}") unless ['file','directory','link'].include? ftype
- desc = []
- PARAM_ORDER.each { |check|
- check = :ftype if check == :type
- desc << send(check)
- }
-
- desc << checksum
- desc << @destination rescue nil if ftype == 'link'
-
- desc.join("\t")
- end
-
def checksum_type=(type)
raise(ArgumentError, "Unsupported checksum type #{type}") unless respond_to?("#{type}_file")
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 00468df96..6f84e077c 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -99,11 +99,6 @@ class Puppet::Module
! path.nil?
end
- # Find the first 'files' directory. This is used by the XMLRPC fileserver.
- def file_directory
- subpath("files")
- end
-
def license_file
return @license_file if defined?(@license_file)
diff --git a/lib/puppet/network/handler.rb b/lib/puppet/network/handler.rb
deleted file mode 100644
index 3cad3872f..000000000
--- a/lib/puppet/network/handler.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'puppet/util/docs'
-require 'puppet/util/subclass_loader'
-
-module Puppet::Network
- # The base class for the different handlers. The handlers are each responsible
- # for separate xmlrpc namespaces.
- class Handler
- extend Puppet::Util::Docs
-
- # This is so that the handlers can subclass just 'Handler', rather
- # then having to specify the full class path.
- Handler = self
- attr_accessor :server, :local
-
- extend Puppet::Util::SubclassLoader
- extend Puppet::Util
-
- handle_subclasses :handler, "puppet/network/handler"
-
- # Return the xmlrpc interface.
- def self.interface
- if defined?(@interface)
- return @interface
- else
- raise Puppet::DevError, "Handler #{self} has no defined interface"
- end
- end
-
- # Set/Determine whether we're a client- or server-side handler.
- def self.side(side = nil)
- if side
- side = side.intern if side.is_a?(String)
- raise ArgumentError, "Invalid side registration '#{side}' for #{self.name}" unless [:client, :server].include?(side)
- @side = side
- else
- @side ||= :server
- return @side
- end
- end
-
- # Create an empty init method with the same signature.
- def initialize(hash = {})
- end
-
- def local?
- self.local
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/ca.rb b/lib/puppet/network/handler/ca.rb
deleted file mode 100644
index a61f62faf..000000000
--- a/lib/puppet/network/handler/ca.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'openssl'
-require 'puppet'
-require 'xmlrpc/server'
-require 'puppet/network/handler'
-
-class Puppet::Network::Handler
- class CA < Handler
- attr_reader :ca
-
- desc "Provides an interface for signing CSRs. Accepts a CSR and returns
- the CA certificate and the signed certificate, or returns nil if
- the cert is not signed."
-
- @interface = XMLRPC::Service::Interface.new("puppetca") { |iface|
- iface.add_method("array getcert(csr)")
- }
-
- def initialize(hash = {})
- Puppet.settings.use(:main, :ssl, :ca)
-
- @ca = Puppet::SSL::CertificateAuthority.instance
- end
-
- # our client sends us a csr, and we either store it for later signing,
- # or we sign it right away
- def getcert(csrtext, client = nil, clientip = nil)
- csr = Puppet::SSL::CertificateRequest.from_s(csrtext)
- hostname = csr.name
-
- unless @ca
- Puppet.notice "Host #{hostname} asked for signing from non-CA master"
- return ""
- end
-
- # We used to save the public key, but it's basically unnecessary
- # and it mucks with the permissions requirements.
-
- # first check to see if we already have a signed cert for the host
- cert = Puppet::SSL::Certificate.indirection.find(hostname)
- cacert = Puppet::SSL::Certificate.indirection.find(@ca.host.name)
-
- if cert
- Puppet.info "Retrieving existing certificate for #{hostname}"
- unless csr.content.public_key.to_s == cert.content.public_key.to_s
- raise Puppet::Error, "Certificate request does not match existing certificate; run 'puppetca --clean #{hostname}'."
- end
- [cert.to_s, cacert.to_s]
- else
- Puppet::SSL::CertificateRequest.indirection.save(csr)
-
- # We determine whether we signed the csr by checking if there's a certificate for it
- if cert = Puppet::SSL::Certificate.indirection.find(hostname)
- [cert.to_s, cacert.to_s]
- else
- nil
- end
- end
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb
deleted file mode 100755
index 0ca467f7a..000000000
--- a/lib/puppet/network/handler/filebucket.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require 'fileutils'
-require 'digest/md5'
-require 'puppet/external/base64'
-require 'puppet/network/handler'
-require 'xmlrpc/server'
-
-class Puppet::Network::Handler # :nodoc:
- # Accept files and store them by md5 sum, returning the md5 sum back
- # to the client. Alternatively, accept an md5 sum and return the
- # associated content.
- class FileBucket < Handler
- desc "The interface to Puppet's FileBucket system. Can be used to store
- files in and retrieve files from a filebucket."
-
- @interface = XMLRPC::Service::Interface.new("puppetbucket") { |iface|
- iface.add_method("string addfile(string, string)")
- iface.add_method("string getfile(string)")
- }
-
- Puppet::Util.logmethods(self, true)
- attr_reader :name, :path
-
- def initialize(hash)
- @path = hash[:Path] || Puppet[:bucketdir]
- @name = "Filebucket[#{@path}]"
- end
-
- # Accept a file from a client and store it by md5 sum, returning
- # the sum.
- def addfile(contents, path, client = nil, clientip = nil)
- contents = Base64.decode64(contents) if client
- bucket = Puppet::FileBucket::File.new(contents)
- Puppet::FileBucket::File.indirection.save(bucket)
- end
-
- # Return the contents associated with a given md5 sum.
- def getfile(md5, client = nil, clientip = nil)
- bucket = Puppet::FileBucket::File.indirection.find("md5:#{md5}")
- contents = bucket.contents
-
- if client
- return Base64.encode64(contents)
- else
- return contents
- end
- end
-
- def to_s
- self.name
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
deleted file mode 100755
index 8fe3da29a..000000000
--- a/lib/puppet/network/handler/fileserver.rb
+++ /dev/null
@@ -1,732 +0,0 @@
-require 'puppet'
-require 'puppet/network/authstore'
-require 'webrick/httpstatus'
-require 'cgi'
-require 'delegate'
-require 'sync'
-require 'puppet/network/handler'
-
-require 'puppet/network/handler'
-require 'puppet/network/xmlrpc/server'
-require 'puppet/file_serving'
-require 'puppet/file_serving/metadata'
-require 'puppet/network/handler'
-
-class Puppet::Network::Handler
- AuthStoreError = Puppet::AuthStoreError
- class FileServerError < Puppet::Error; end
- class FileServer < Handler
- desc "The interface to Puppet's fileserving abilities."
-
- attr_accessor :local
-
- CHECKPARAMS = [:mode, :type, :owner, :group, :checksum]
-
- # Special filserver module for puppet's module system
- MODULES = "modules"
- PLUGINS = "plugins"
-
- @interface = XMLRPC::Service::Interface.new("fileserver") { |iface|
- iface.add_method("string describe(string, string)")
- iface.add_method("string list(string, string, boolean, array)")
- iface.add_method("string retrieve(string, string)")
- }
-
- def self.params
- CHECKPARAMS.dup
- end
-
- # If the configuration file exists, then create (if necessary) a LoadedFile
- # object to manage it; else, return nil.
- def configuration
- # Short-circuit the default case.
- return @configuration if defined?(@configuration)
-
- config_path = @passed_configuration_path || Puppet[:fileserverconfig]
- return nil unless FileTest.exist?(config_path)
-
- # The file exists but we don't have a LoadedFile instance for it.
- @configuration = Puppet::Util::LoadedFile.new(config_path)
- end
-
- # Create our default mounts for modules and plugins. This is duplicated code,
- # but I'm not really worried about that.
- def create_default_mounts
- @mounts = {}
- Puppet.debug "No file server configuration file; autocreating #{MODULES} mount with default permissions"
- mount = Mount.new(MODULES)
- mount.allow("*")
- @mounts[MODULES] = mount
-
- Puppet.debug "No file server configuration file; autocreating #{PLUGINS} mount with default permissions"
- mount = PluginMount.new(PLUGINS)
- mount.allow("*")
- @mounts[PLUGINS] = mount
- end
-
- # Describe a given file. This returns all of the manageable aspects
- # of that file.
- def describe(url, links = :follow, client = nil, clientip = nil)
- links = links.intern if links.is_a? String
-
- mount, path = convert(url, client, clientip)
-
- mount.debug("Describing #{url} for #{client}") if client
-
- # use the mount to resolve the path for us.
- return "" unless full_path = mount.file_path(path, client)
-
- metadata = Puppet::FileServing::Metadata.new(url, :path => full_path, :links => links)
-
- return "" unless metadata.exist?
-
- begin
- metadata.collect
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err detail
- return ""
- end
-
- metadata.attributes_with_tabs
- end
-
- # Create a new fileserving module.
- def initialize(hash = {})
- @mounts = {}
- @files = {}
-
- @local = hash[:Local]
-
- @noreadconfig = true if hash[:Config] == false
-
- @passed_configuration_path = hash[:Config]
-
- if hash.include?(:Mount)
- @passedconfig = true
- raise Puppet::DevError, "Invalid mount hash #{hash[:Mount].inspect}" unless hash[:Mount].is_a?(Hash)
-
- hash[:Mount].each { |dir, name|
- self.mount(dir, name) if FileTest.exists?(dir)
- }
- self.mount(nil, MODULES)
- self.mount(nil, PLUGINS)
- else
- @passedconfig = false
- if configuration
- readconfig(false) # don't check the file the first time.
- else
- create_default_mounts
- end
- end
- end
-
- # List a specific directory's contents.
- def list(url, links = :ignore, recurse = false, ignore = false, client = nil, clientip = nil)
- mount, path = convert(url, client, clientip)
-
- mount.debug "Listing #{url} for #{client}" if client
-
- return "" unless mount.path_exists?(path, client)
-
- desc = mount.list(path, recurse, ignore, client)
-
- if desc.length == 0
- mount.notice "Got no information on //#{mount}/#{path}"
- return ""
- end
-
- desc.collect { |sub| sub.join("\t") }.join("\n")
- end
-
- def local?
- self.local
- end
-
- # Is a given mount available?
- def mounted?(name)
- @mounts.include?(name)
- end
-
- # Mount a new directory with a name.
- def mount(path, name)
- if @mounts.include?(name)
- if @mounts[name] != path
- raise FileServerError, "#{@mounts[name].path} is already mounted at #{name}"
- else
- # it's already mounted; no problem
- return
- end
- end
-
- # Let the mounts do their own error-checking.
- @mounts[name] = Mount.new(name, path)
- @mounts[name].info "Mounted #{path}"
-
- @mounts[name]
- end
-
- # Retrieve a file from the local disk and pass it to the remote
- # client.
- def retrieve(url, links = :ignore, client = nil, clientip = nil)
- links = links.intern if links.is_a? String
-
- mount, path = convert(url, client, clientip)
-
- mount.info "Sending #{url} to #{client}" if client
-
- unless mount.path_exists?(path, client)
- mount.debug "#{mount} reported that #{path} does not exist"
- return ""
- end
-
- links = links.intern if links.is_a? String
-
- if links == :ignore and FileTest.symlink?(path)
- mount.debug "I think that #{path} is a symlink and we're ignoring them"
- return ""
- end
-
- str = mount.read_file(path, client)
-
- if @local
- return str
- else
- return CGI.escape(str)
- end
- end
-
- def umount(name)
- @mounts.delete(name) if @mounts.include? name
- end
-
- private
-
- def authcheck(file, mount, client, clientip)
- # If we're local, don't bother passing in information.
- if local?
- client = nil
- clientip = nil
- end
- unless mount.allowed?(client, clientip)
- mount.warning "#{client} cannot access #{file}"
- raise Puppet::AuthorizationError, "Cannot access #{mount}"
- end
- end
-
- # Take a URL and some client info and return a mount and relative
- # path pair.
- #
- def convert(url, client, clientip)
- readconfig
-
- url = URI.unescape(url)
-
- mount, stub = splitpath(url, client)
-
- authcheck(url, mount, client, clientip)
-
- return mount, stub
- end
-
- # Return the mount for the Puppet modules; allows file copying from
- # the modules.
- def modules_mount(module_name, client)
- # Find our environment, if we have one.
- unless hostname = (client || Facter.value("hostname"))
- raise ArgumentError, "Could not find hostname"
- end
- env = (node = Puppet::Node.indirection.find(hostname)) ? node.environment : nil
-
- # And use the environment to look up the module.
- (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil
- end
-
- # Read the configuration file.
- def readconfig(check = true)
- return if @noreadconfig
-
- return unless configuration
-
- return if check and ! @configuration.changed?
-
- newmounts = {}
- begin
- File.open(@configuration.file) { |f|
- mount = nil
- count = 1
- f.each { |line|
- case line
- when /^\s*#/; next # skip comments
- when /^\s*$/; next # skip blank lines
- when /\[([-\w]+)\]/
- name = $1
- raise FileServerError, "#{newmounts[name]} is already mounted as #{name} in #{@configuration.file}" if newmounts.include?(name)
- mount = Mount.new(name)
- newmounts[name] = mount
- when /^\s*(\w+)\s+(.+)$/
- var = $1
- value = $2
- case var
- when "path"
- raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount
- if mount.name == MODULES
- Puppet.warning "The '#{mount.name}' module can not have a path. Ignoring attempt to set it"
- else
- begin
- mount.path = value
- rescue FileServerError => detail
- Puppet.err "Removing mount #{mount.name}: #{detail}"
- newmounts.delete(mount.name)
- end
- end
- when "allow"
- raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount
- value.split(/\s*,\s*/).each { |val|
- begin
- mount.info "allowing #{val} access"
- mount.allow(val)
- rescue AuthStoreError => detail
- puts detail.backtrace if Puppet[:trace]
-
- raise FileServerError.new(
- detail.to_s,
-
- count, @configuration.file)
- end
- }
- when "deny"
- raise FileServerError.new("No mount specified for argument #{var} #{value}") unless mount
- value.split(/\s*,\s*/).each { |val|
- begin
- mount.info "denying #{val} access"
- mount.deny(val)
- rescue AuthStoreError => detail
-
- raise FileServerError.new(
- detail.to_s,
-
- count, @configuration.file)
- end
- }
- else
- raise FileServerError.new("Invalid argument '#{var}'", count, @configuration.file)
- end
- else
- raise FileServerError.new("Invalid line '#{line.chomp}'", count, @configuration.file)
- end
- count += 1
- }
- }
- rescue Errno::EACCES => detail
- Puppet.err "FileServer error: Cannot read #{@configuration}; cannot serve"
- #raise Puppet::Error, "Cannot read #{@configuration}"
- rescue Errno::ENOENT => detail
- Puppet.err "FileServer error: '#{@configuration}' does not exist; cannot serve"
- end
-
- unless newmounts[MODULES]
- Puppet.debug "No #{MODULES} mount given; autocreating with default permissions"
- mount = Mount.new(MODULES)
- mount.allow("*")
- newmounts[MODULES] = mount
- end
-
- unless newmounts[PLUGINS]
- Puppet.debug "No #{PLUGINS} mount given; autocreating with default permissions"
- mount = PluginMount.new(PLUGINS)
- mount.allow("*")
- newmounts[PLUGINS] = mount
- end
-
- unless newmounts[PLUGINS].valid?
- Puppet.debug "No path given for #{PLUGINS} mount; creating a special PluginMount"
- # We end up here if the user has specified access rules for
- # the plugins mount, without specifying a path (which means
- # they want to have the default behaviour for the mount, but
- # special access control). So we need to move all the
- # user-specified access controls into the new PluginMount
- # object...
- mount = PluginMount.new(PLUGINS)
- # Yes, you're allowed to hate me for this.
-
- mount.instance_variable_set(
- :@declarations,
-
- newmounts[PLUGINS].instance_variable_get(:@declarations)
- )
- newmounts[PLUGINS] = mount
- end
-
- # Verify each of the mounts are valid.
- # We let the check raise an error, so that it can raise an error
- # pointing to the specific problem.
- newmounts.each { |name, mount|
- raise FileServerError, "Invalid mount #{name}" unless mount.valid?
- }
- @mounts = newmounts
- end
-
- # Split the path into the separate mount point and path.
- def splitpath(dir, client)
- # the dir is based on one of the mounts
- # so first retrieve the mount path
- mount = nil
- path = nil
- if dir =~ %r{/([-\w]+)}
- # Strip off the mount name.
- mount_name, path = dir.sub(%r{^/}, '').split(File::Separator, 2)
-
- unless mount = modules_mount(mount_name, client)
- unless mount = @mounts[mount_name]
- raise FileServerError, "Fileserver module '#{mount_name}' not mounted"
- end
- end
- else
- raise FileServerError, "Fileserver error: Invalid path '#{dir}'"
- end
-
- if path.nil? or path == ''
- path = '/'
- elsif path
- # Remove any double slashes that might have occurred
- path = URI.unescape(path.gsub(/\/\//, "/"))
- end
-
- return mount, path
- end
-
- def to_s
- "fileserver"
- end
-
- # A simple class for wrapping mount points. Instances of this class
- # don't know about the enclosing object; they're mainly just used for
- # authorization.
- class Mount < Puppet::Network::AuthStore
- attr_reader :name
-
- @@syncs = {}
-
- @@files = {}
-
- Puppet::Util.logmethods(self, true)
-
- # Create a map for a specific client.
- def clientmap(client)
- {
- "h" => client.sub(/\..*$/, ""),
- "H" => client,
- "d" => client.sub(/[^.]+\./, "") # domain name
- }
- end
-
- # Replace % patterns as appropriate.
- def expand(path, client = nil)
- # This map should probably be moved into a method.
- map = nil
-
- if client
- map = clientmap(client)
- else
- Puppet.notice "No client; expanding '#{path}' with local host"
- # Else, use the local information
- map = localmap
- end
- path.gsub(/%(.)/) do |v|
- key = $1
- if key == "%"
- "%"
- else
- map[key] || v
- end
- end
- end
-
- # Do we have any patterns in our path, yo?
- def expandable?
- if defined?(@expandable)
- @expandable
- else
- false
- end
- end
-
- # Return a fully qualified path, given a short path and
- # possibly a client name.
- def file_path(relative_path, node = nil)
- full_path = path(node)
-
- unless full_path
- p self
- raise ArgumentError.new("Mounts without paths are not usable") unless full_path
- end
-
- # If there's no relative path name, then we're serving the mount itself.
- return full_path unless relative_path and relative_path != "/"
-
- File.join(full_path, relative_path)
- end
-
- # Create out object. It must have a name.
- def initialize(name, path = nil)
- unless name =~ %r{^[-\w]+$}
- raise FileServerError, "Invalid name format '#{name}'"
- end
- @name = name
-
- if path
- self.path = path
- else
- @path = nil
- end
-
- @files = {}
-
- super()
- end
-
- def fileobj(path, links, client)
- obj = nil
- if obj = @files[file_path(path, client)]
- # This can only happen in local fileserving, but it's an
- # important one. It'd be nice if we didn't just set
- # the check params every time, but I'm not sure it's worth
- # the effort.
- obj[:audit] = CHECKPARAMS
- else
-
- obj = Puppet::Type.type(:file).new(
-
- :name => file_path(path, client),
-
- :audit => CHECKPARAMS
- )
- @files[file_path(path, client)] = obj
- end
-
- if links == :manage
- links = :follow
- end
-
- # This, ah, might be completely redundant
- obj[:links] = links unless obj[:links] == links
-
- obj
- end
-
- # Read the contents of the file at the relative path given.
- def read_file(relpath, client)
- File.read(file_path(relpath, client))
- end
-
- # Cache this manufactured map, since if it's used it's likely
- # to get used a lot.
- def localmap
- unless defined?(@@localmap)
- @@localmap = {
- "h" => Facter.value("hostname"),
- "H" => [Facter.value("hostname"),
- Facter.value("domain")].join("."),
- "d" => Facter.value("domain")
- }
- end
- @@localmap
- end
-
- # Return the path as appropriate, expanding as necessary.
- def path(client = nil)
- if expandable?
- return expand(@path, client)
- else
- return @path
- end
- end
-
- # Set the path.
- def path=(path)
- # FIXME: For now, just don't validate paths with replacement
- # patterns in them.
- if path =~ /%./
- # Mark that we're expandable.
- @expandable = true
- else
- raise FileServerError, "#{path} does not exist" unless FileTest.exists?(path)
- raise FileServerError, "#{path} is not a directory" unless FileTest.directory?(path)
- raise FileServerError, "#{path} is not readable" unless FileTest.readable?(path)
- @expandable = false
- end
- @path = path
- end
-
- # Verify that the path given exists within this mount's subtree.
- #
- def path_exists?(relpath, client = nil)
- File.exists?(file_path(relpath, client))
- end
-
- # Return the current values for the object.
- def properties(obj)
- obj.retrieve.inject({}) { |props, ary| props[ary[0].name] = ary[1]; props }
- end
-
- # Retrieve a specific directory relative to a mount point.
- # If they pass in a client, then expand as necessary.
- def subdir(dir = nil, client = nil)
- basedir = self.path(client)
-
- dirname = if dir
- File.join(basedir, *dir.split("/"))
- else
- basedir
- end
-
- dirname
- end
-
- def sync(path)
- @@syncs[path] ||= Sync.new
- @@syncs[path]
- end
-
- def to_s
- "mount[#{@name}]"
- end
-
- # Verify our configuration is valid. This should really check to
- # make sure at least someone will be allowed, but, eh.
- def valid?
- if name == MODULES
- return @path.nil?
- else
- return ! @path.nil?
- end
- end
-
- # Return a new mount with the same properties as +self+, except
- # with a different name and path.
- def copy(name, path)
- result = self.clone
- result.path = path
- result.instance_variable_set(:@name, name)
- result
- end
-
- # List the contents of the relative path +relpath+ of this mount.
- #
- # +recurse+ is the number of levels to recurse into the tree,
- # or false to provide no recursion or true if you just want to
- # go for broke.
- #
- # +ignore+ is an array of filenames to ignore when traversing
- # the list.
- #
- # The return value of this method is a complex nest of arrays,
- # which describes a directory tree. Each file or directory is
- # represented by an array, where the first element is the path
- # of the file (relative to the root of the mount), and the
- # second element is the type. A directory is represented by an
- # array as well, where the first element is a "directory" array,
- # while the remaining elements are other file or directory
- # arrays. Confusing? Hell yes. As an added bonus, all names
- # must start with a slash, because... well, I'm fairly certain
- # a complete explanation would involve the words "crack pipe"
- # and "bad batch".
- #
- def list(relpath, recurse, ignore, client = nil)
- abspath = file_path(relpath, client)
- if FileTest.exists?(abspath)
- if FileTest.directory?(abspath) and recurse
- return reclist(abspath, recurse, ignore)
- else
- return [["/", File.stat(abspath).ftype]]
- end
- end
- nil
- end
-
- def reclist(abspath, recurse, ignore)
- require 'puppet/file_serving'
- require 'puppet/file_serving/fileset'
- if recurse.is_a?(Fixnum)
- args = { :recurse => true, :recurselimit => recurse, :links => :follow }
- else
- args = { :recurse => recurse, :links => :follow }
- end
- args[:ignore] = ignore if ignore
- fs = Puppet::FileServing::Fileset.new(abspath, args)
- ary = fs.files.collect do |file|
- if file == "."
- file = "/"
- else
- file = File.join("/", file )
- end
- stat = fs.stat(File.join(abspath, file))
- next if stat.nil?
- [ file, stat.ftype ]
- end
-
- ary.compact
- end
-
- end
-
- # A special mount class specifically for the plugins mount -- just
- # has some magic to effectively do a union mount of the 'plugins'
- # directory of all modules.
- #
- class PluginMount < Mount
- def path(client)
- ''
- end
-
- def mod_path_exists?(mod, relpath, client = nil)
- ! mod.plugin(relpath).nil?
- end
-
- def path_exists?(relpath, client = nil)
- !valid_modules(client).find { |mod| mod.plugin(relpath) }.nil?
- end
-
- def valid?
- true
- end
-
- def mod_file_path(mod, relpath, client = nil)
- File.join(mod, PLUGINS, relpath)
- end
-
- def file_path(relpath, client = nil)
- return nil unless mod = valid_modules(client).find { |m| m.plugin(relpath) }
- mod.plugin(relpath)
- end
-
- # create a list of files by merging all modules
- def list(relpath, recurse, ignore, client = nil)
- result = []
- valid_modules(client).each do |mod|
- if modpath = mod.plugin(relpath)
- if FileTest.directory?(modpath) and recurse
- ary = reclist(modpath, recurse, ignore)
- ary ||= []
- result += ary
- else
- result += [["/", File.stat(modpath).ftype]]
- end
- end
- end
- result
- end
-
- private
- def valid_modules(client)
- Puppet::Node::Environment.new.modules.find_all { |mod| mod.exist? }
- end
-
- def add_to_filetree(f, filetree)
- first, rest = f.split(File::SEPARATOR, 2)
- end
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
deleted file mode 100755
index 5e3ee266d..000000000
--- a/lib/puppet/network/handler/report.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'puppet/util/instance_loader'
-require 'puppet/reports'
-require 'puppet/network/handler'
-require 'xmlrpc/server'
-
-# A simple server for triggering a new run on a Puppet client.
-class Puppet::Network::Handler
- class Report < Handler
- desc "Accepts a Puppet transaction report and processes it."
-
- @interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
- iface.add_method("string report(array)")
- }
-
- # Add a new report type.
- def self.newreport(name, options = {}, &block)
- Puppet.warning "The interface for registering report types has changed; use Puppet::Reports.register_report for report type #{name}"
- Puppet::Reports.register_report(name, options, &block)
- end
-
- def initialize(*args)
- super
- Puppet.settings.use(:main, :reporting, :metrics)
- end
-
- # Accept a report from a client.
- def report(report, client = nil, clientip = nil)
- # Unescape the report
- report = CGI.unescape(report) unless @local
-
- Puppet.info "Processing reports #{reports().join(", ")} for #{client}"
- begin
- process(report)
- rescue => detail
- Puppet.err "Could not process report for #{client}: #{detail}"
- puts detail.backtrace if Puppet[:trace]
- end
- end
-
- private
-
- # Process the report using all of the existing hooks.
- def process(yaml)
- return if Puppet[:reports] == "none"
-
- # First convert the report to real objects
- begin
- report = YAML.load(yaml)
- rescue => detail
- Puppet.warning "Could not load report: #{detail}"
- return
- end
-
- # Used for those reports that accept yaml
- client = report.host
-
- reports.each do |name|
- if mod = Puppet::Reports.report(name)
- # We have to use a dup because we're including a module in the
- # report.
- newrep = report.dup
- begin
- newrep.extend(mod)
- newrep.process
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Report #{name} failed: #{detail}"
- end
- else
- Puppet.warning "No report named '#{name}'"
- end
- end
- end
-
- # Handle the parsing of the reports attribute.
- def reports
- # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
- x = Puppet[:reports].gsub(/(^\s+)|(\s+$)/, '').split(/\s*,\s*/)
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/runner.rb b/lib/puppet/network/handler/runner.rb
deleted file mode 100755
index 1bc62bcd9..000000000
--- a/lib/puppet/network/handler/runner.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require 'puppet/run'
-require 'puppet/network/handler'
-require 'xmlrpc/server'
-
-class Puppet::Network::Handler
- class MissingMasterError < RuntimeError; end # Cannot find the master client
- # A simple server for triggering a new run on a Puppet client.
- class Runner < Handler
- desc "An interface for triggering client configuration runs."
-
- @interface = XMLRPC::Service::Interface.new("puppetrunner") { |iface|
- iface.add_method("string run(string, string)")
- }
-
- side :client
-
- # Run the client configuration right now, optionally specifying
- # tags and whether to ignore schedules
- def run(tags = nil, ignoreschedules = false, fg = true, client = nil, clientip = nil)
- options = {}
- options[:tags] = tags if tags
- options[:ignoreschedules] = ignoreschedules if ignoreschedules
- options[:background] = !fg
-
- runner = Puppet::Run.new(options)
-
- runner.run
-
- runner.status
- end
- end
-end
-
diff --git a/lib/puppet/network/handler/status.rb b/lib/puppet/network/handler/status.rb
deleted file mode 100644
index df6215f9c..000000000
--- a/lib/puppet/network/handler/status.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'puppet/network/handler'
-require 'xmlrpc/server'
-class Puppet::Network::Handler
- class Status < Handler
- desc "A simple interface for testing Puppet connectivity."
-
- side :client
-
- @interface = XMLRPC::Service::Interface.new("status") { |iface|
- iface.add_method("int status()")
- }
-
- def status(client = nil, clientip = nil)
- 1
- end
- end
-end
-
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index 2a638b229..355259a86 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -14,7 +14,6 @@ class Puppet::Network::HTTP::Mongrel
raise "Mongrel server is already listening" if listening?
@protocols = args[:protocols]
- @xmlrpc_handlers = args[:xmlrpc_handlers]
@server = Mongrel::HttpServer.new(args[:address], args[:port])
setup_handlers
@@ -39,13 +38,6 @@ class Puppet::Network::HTTP::Mongrel
# Register our REST support at /
klass = class_for_protocol(:rest)
@server.register('/', klass.new(:server => @server))
-
- setup_xmlrpc_handlers if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- end
-
- # Use our existing code to provide the xmlrpc backward compatibility.
- def setup_xmlrpc_handlers
- @server.register('/RPC2', Puppet::Network::HTTPServer::Mongrel.new(@xmlrpc_handlers))
end
def class_for_protocol(protocol)
diff --git a/lib/puppet/network/http/rack.rb b/lib/puppet/network/http/rack.rb
index 5b4ef7e1c..77af351d2 100644
--- a/lib/puppet/network/http/rack.rb
+++ b/lib/puppet/network/http/rack.rb
@@ -4,7 +4,6 @@ require 'rack/response'
require 'puppet/network/http'
require 'puppet/network/http/rack/rest'
-require 'puppet/network/http/rack/xmlrpc'
# An rack application, for running the Puppet HTTP Server.
class Puppet::Network::HTTP::Rack
@@ -17,15 +16,6 @@ class Puppet::Network::HTTP::Rack
@rest_http_handler = Puppet::Network::HTTP::RackREST.new
protocols.delete :rest
- # Prepare the XMLRPC handler, for backward compatibility (if requested)
- @xmlrpc_path = '/RPC2'
- if args[:protocols].include?(:xmlrpc)
- raise ArgumentError, "XMLRPC was requested, but no handlers were given" if !args.include?(:xmlrpc_handlers)
-
- @xmlrpc_http_handler = Puppet::Network::HTTP::RackXMLRPC.new(args[:xmlrpc_handlers])
- protocols.delete :xmlrpc
- end
-
raise ArgumentError, "there were unknown :protocols specified." if !protocols.empty?
end
@@ -39,13 +29,7 @@ class Puppet::Network::HTTP::Rack
response = Rack::Response.new
Puppet.debug 'Handling request: %s %s' % [request.request_method, request.fullpath]
- # if we shall serve XMLRPC, have /RPC2 go to the xmlrpc handler
- if @xmlrpc_http_handler and @xmlrpc_path == request.path_info[0, @xmlrpc_path.size]
- handler = @xmlrpc_http_handler
- else
- # everything else is handled by the new REST handler
- handler = @rest_http_handler
- end
+ handler = @rest_http_handler
begin
handler.process(request, response)
diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb
deleted file mode 100644
index f75342783..000000000
--- a/lib/puppet/network/http/rack/xmlrpc.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require 'puppet/network/http/rack/httphandler'
-require 'puppet/network/xmlrpc/server'
-require 'resolv'
-
-class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler
- def initialize(handlers)
- @xmlrpc_server = Puppet::Network::XMLRPCServer.new
- handlers.each do |name|
- Puppet.debug " -> register xmlrpc namespace #{name}"
- unless handler = Puppet::Network::Handler.handler(name)
- raise ArgumentError, "Invalid XMLRPC handler #{name}"
- end
- @xmlrpc_server.add_handler(handler.interface, handler.new({}))
- end
- super()
- end
-
- def process(request, response)
- # errors are sent as text/plain
- response['Content-Type'] = 'text/plain'
- if not request.post?
- response.status = 405
- response.write 'Method Not Allowed'
- return
- end
- if request.media_type != "text/xml"
- response.status = 400
- response.write 'Bad Request'
- return
- end
-
- # get auth/certificate data
- client_request = build_client_request(request)
-
- response_body = @xmlrpc_server.process(request.body.read, client_request)
-
- response.status = 200
- response['Content-Type'] = 'text/xml; charset=utf-8'
- response.write response_body
- end
-
- def build_client_request(request)
- ip = request.ip
-
- # if we find SSL info in the headers, use them to get a hostname.
- # try this with :ssl_client_header, which defaults should work for
- # Apache with StdEnvVars.
- if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/)
- node = dn_matchdata[1].to_str
- authenticated = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS')
- else
- begin
- node = Resolv.getname(ip)
- rescue => detail
- Puppet.err "Could not resolve #{ip}: #{detail}"
- node = "unknown"
- end
- authenticated = false
- end
-
- Puppet::Network::ClientRequest.new(node, ip, authenticated)
- end
-
-end
-
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index 52aec1bf1..a97a631a7 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -1,7 +1,6 @@
require 'webrick'
require 'webrick/https'
require 'puppet/network/http/webrick/rest'
-require 'puppet/network/xmlrpc/webrick_servlet'
require 'thread'
require 'puppet/ssl/certificate'
@@ -24,7 +23,6 @@ class Puppet::Network::HTTP::WEBrick
raise ArgumentError, ":port must be specified." unless args[:port]
@protocols = args[:protocols]
- @xmlrpc_handlers = args[:xmlrpc_handlers]
arguments = {:BindAddress => args[:address], :Port => args[:port]}
arguments.merge!(setup_logger)
@@ -121,19 +119,5 @@ class Puppet::Network::HTTP::WEBrick
# Set up the new-style protocols.
klass = self.class.class_for_protocol(:rest)
@server.mount('/', klass, :this_value_is_apparently_necessary_but_unused)
-
- # And then set up xmlrpc, if configured.
- @server.mount("/RPC2", xmlrpc_servlet) if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- end
-
- # Create our xmlrpc servlet, which provides backward compatibility.
- def xmlrpc_servlet
- handlers = @xmlrpc_handlers.collect { |handler|
- unless hclass = Puppet::Network::Handler.handler(handler)
- raise "Invalid xmlrpc handler #{handler}"
- end
- hclass.new({})
- }
- Puppet::Network::XMLRPC::WEBrickServlet.new handlers
end
end
diff --git a/lib/puppet/network/http_server.rb b/lib/puppet/network/http_server.rb
deleted file mode 100644
index e3826a654..000000000
--- a/lib/puppet/network/http_server.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-# Just a stub, so we can correctly scope other classes.
-module Puppet::Network::HTTPServer # :nodoc:
-end
diff --git a/lib/puppet/network/http_server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb
deleted file mode 100644
index fb9516461..000000000
--- a/lib/puppet/network/http_server/mongrel.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env ruby
-# File: 06-11-14-mongrel_xmlrpc.rb
-# Author: Manuel Holtgrewe <purestorm at ggnore.net>
-#
-# Copyright (c) 2006 Manuel Holtgrewe, 2007 Luke Kanies
-#
-# This file is based heavily on a file retrieved from
-# http://ttt.ggnore.net/2006/11/15/xmlrpc-with-mongrel-and-ruby-off-rails/
-
-require 'rubygems'
-require 'mongrel'
-require 'xmlrpc/server'
-require 'puppet/network/xmlrpc/server'
-require 'puppet/network/http_server'
-require 'puppet/network/client_request'
-require 'puppet/network/handler'
-
-require 'resolv'
-
-# This handler can be hooked into Mongrel to accept HTTP requests. After
-# checking whether the request itself is sane, the handler forwards it
-# to an internal instance of XMLRPC::BasicServer to process it.
-#
-# You can access the server by calling the Handler's "xmlrpc_server"
-# attribute accessor method and add XMLRPC handlers there. For example:
-#
-# <pre>
-# handler = XmlRpcHandler.new
-# handler.xmlrpc_server.add_handler("my.add") { |a, b| a.to_i + b.to_i }
-# </pre>
-module Puppet::Network
- class HTTPServer::Mongrel < ::Mongrel::HttpHandler
- attr_reader :xmlrpc_server
-
- def initialize(handlers)
- if Puppet[:debug]
- $mongrel_debug_client = true
- Puppet.debug 'Mongrel client debugging enabled. [$mongrel_debug_client = true].'
- end
- # Create a new instance of BasicServer. We are supposed to subclass it
- # but that does not make sense since we would not introduce any new
- # behaviour and we have to subclass Mongrel::HttpHandler so our handler
- # works for Mongrel.
- @xmlrpc_server = Puppet::Network::XMLRPCServer.new
- handlers.each do |name|
- unless handler = Puppet::Network::Handler.handler(name)
- raise ArgumentError, "Invalid handler #{name}"
- end
- @xmlrpc_server.add_handler(handler.interface, handler.new({}))
- end
- end
-
- # This method produces the same results as XMLRPC::CGIServer.serve
- # from Ruby's stdlib XMLRPC implementation.
- def process(request, response)
- # Make sure this has been a POST as required for XMLRPC.
- request_method = request.params[Mongrel::Const::REQUEST_METHOD] || Mongrel::Const::GET
- if request_method != "POST"
- response.start(405) { |head, out| out.write("Method Not Allowed") }
- return
- end
-
- # Make sure the user has sent text/xml data.
- request_mime = request.params["CONTENT_TYPE"] || "text/plain"
- if parse_content_type(request_mime).first != "text/xml"
- response.start(400) { |head, out| out.write("Bad Request") }
- return
- end
-
- # Make sure there is data in the body at all.
- length = request.params[Mongrel::Const::CONTENT_LENGTH].to_i
- if length <= 0
- response.start(411) { |head, out| out.write("Length Required") }
- return
- end
-
- # Check the body to be valid.
- if request.body.nil? or request.body.size != length
- response.start(400) { |head, out| out.write("Bad Request") }
- return
- end
-
- info = client_info(request)
-
- # All checks above passed through
- response.start(200) do |head, out|
- head["Content-Type"] = "text/xml; charset=utf-8"
- begin
- out.write(@xmlrpc_server.process(request.body, info))
- rescue => detail
- puts detail.backtrace
- raise
- end
- end
- end
-
- private
-
- def client_info(request)
- params = request.params
- ip = params["HTTP_X_FORWARDED_FOR"] ? params["HTTP_X_FORWARDED_FOR"].split(',').last.strip : params["REMOTE_ADDR"]
- # JJM #906 The following dn.match regular expression is forgiving
- # enough to match the two Distinguished Name string contents
- # coming from Apache, Pound or other reverse SSL proxies.
- if dn = params[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/)
- client = dn_matchdata[1].to_str
- valid = (params[Puppet[:ssl_client_verify_header]] == 'SUCCESS')
- else
- begin
- client = Resolv.getname(ip)
- rescue => detail
- Puppet.err "Could not resolve #{ip}: #{detail}"
- client = "unknown"
- end
- valid = false
- end
-
- info = Puppet::Network::ClientRequest.new(client, ip, valid)
-
- info
- end
-
- # Taken from XMLRPC::ParseContentType
- def parse_content_type(str)
- a, *b = str.split(";")
- return a.strip, *b
- end
- end
-end
diff --git a/lib/puppet/network/rest_authconfig.rb b/lib/puppet/network/rest_authconfig.rb
index 80167103b..94bc60d02 100644
--- a/lib/puppet/network/rest_authconfig.rb
+++ b/lib/puppet/network/rest_authconfig.rb
@@ -42,10 +42,6 @@ module Puppet
def check_authorization(indirection, method, key, params)
read
- # we're splitting the request in part because
- # fail_on_deny could as well be called in the XMLRPC context
- # with a ClientRequest.
-
if authorization_failure_exception = @rights.is_request_forbidden_and_why?(indirection, method, key, params)
Puppet.warning("Denying access: #{authorization_failure_exception}")
raise authorization_failure_exception
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index e4de07dea..deccaf1ed 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -51,7 +51,7 @@ class Puppet::Network::Server
end
def initialize(args = {})
- valid_args = [:handlers, :xmlrpc_handlers, :port]
+ valid_args = [:handlers, :port]
bad_args = args.keys.find_all { |p| ! valid_args.include?(p) }.collect { |p| p.to_s }.join(",")
raise ArgumentError, "Invalid argument(s) #{bad_args}" unless bad_args == ""
@server_type = Puppet[:servertype] or raise "No servertype configuration found." # e.g., WEBrick, Mongrel, etc.
@@ -60,12 +60,10 @@ class Puppet::Network::Server
@port = args[:port] || Puppet[:masterport] || raise(ArgumentError, "Must specify :port or configure Puppet :masterport")
@address = determine_bind_address
- @protocols = [ :rest, :xmlrpc ]
+ @protocols = [ :rest ]
@listening = false
@routes = {}
- @xmlrpc_routes = {}
self.register(args[:handlers]) if args[:handlers]
- self.register_xmlrpc(args[:xmlrpc_handlers]) if args[:xmlrpc_handlers]
# Make sure we have all of the directories we need to function.
Puppet.settings.use(:main, :ssl, Puppet[:name])
@@ -94,29 +92,6 @@ class Puppet::Network::Server
end
end
- # Register xmlrpc handlers for backward compatibility.
- def register_xmlrpc(*namespaces)
- raise ArgumentError, "XMLRPC namespaces are required." if namespaces.empty?
- namespaces.flatten.each do |name|
- Puppet::Network::Handler.handler(name) || raise(ArgumentError, "Cannot locate XMLRPC handler for namespace '#{name}'.")
- @xmlrpc_routes[name.to_sym] = true
- end
- end
-
- # Unregister xmlrpc handlers.
- def unregister_xmlrpc(*namespaces)
- raise "Cannot unregister xmlrpc handlers while server is listening." if listening?
- namespaces = @xmlrpc_routes.keys if namespaces.empty?
-
- namespaces.flatten.each do |i|
- raise(ArgumentError, "XMLRPC handler '#{i}' is unknown.") unless @xmlrpc_routes[i.to_sym]
- end
-
- namespaces.flatten.each do |i|
- @xmlrpc_routes.delete(i.to_sym)
- end
- end
-
def listening?
@listening
end
@@ -124,7 +99,7 @@ class Puppet::Network::Server
def listen
raise "Cannot listen -- already listening." if listening?
@listening = true
- http_server.listen(:address => address, :port => port, :handlers => @routes.keys, :xmlrpc_handlers => @xmlrpc_routes.keys, :protocols => protocols)
+ http_server.listen(:address => address, :port => port, :handlers => @routes.keys, :protocols => protocols)
end
def unlisten
diff --git a/lib/puppet/network/xmlrpc/processor.rb b/lib/puppet/network/xmlrpc/processor.rb
deleted file mode 100644
index dea8a02fa..000000000
--- a/lib/puppet/network/xmlrpc/processor.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require 'puppet/network/authorization'
-require 'xmlrpc/server'
-
-# Just silly.
-class ::XMLRPC::FaultException
- def to_s
- self.message
- end
-end
-
-module Puppet::Network
- # Most of our subclassing is just so that we can get
- # access to information from the request object, like
- # the client name and IP address.
- module XMLRPCProcessor
- include Puppet::Network::Authorization
-
- ERR_UNAUTHORIZED = 30
-
- def add_handler(interface, handler)
- @loadedhandlers << interface.prefix
- super(interface, handler)
- end
-
- def handler_loaded?(handler)
- @loadedhandlers.include?(handler.to_s)
- end
-
- # Convert our data and client request into xmlrpc calls, and verify
- # they're authorized and such-like. This method differs from the
- # default in that it expects a ClientRequest object in addition to the
- # data.
- def process(data, request)
- call, params = parser.parseMethodCall(data)
- params << request.name << request.ip
- handler, method = call.split(".")
- request.handler = handler
- request.method = method
- begin
- verify(request)
- rescue InvalidClientRequest => detail
- raise ::XMLRPC::FaultException.new(ERR_UNAUTHORIZED, detail.to_s)
- end
- handle(request.call, *params)
- end
-
- private
-
- # Provide error handling for method calls.
- def protect_service(obj, *args)
- begin
- obj.call(*args)
- rescue ::XMLRPC::FaultException
- raise
- rescue Puppet::AuthorizationError => detail
- Puppet.err "Permission denied: #{detail}"
- raise ::XMLRPC::FaultException.new(
- 1, detail.to_s
- )
- rescue Puppet::Error => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err detail.to_s
- error = ::XMLRPC::FaultException.new(
- 1, detail.to_s
- )
- error.set_backtrace detail.backtrace
- raise error
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not call: #{detail}"
- error = ::XMLRPC::FaultException.new(1, detail.to_s)
- error.set_backtrace detail.backtrace
- raise error
- end
- end
-
- # Set up our service hook and init our handler list.
- def setup_processor
- @loadedhandlers = []
- self.set_service_hook do |obj, *args|
- protect_service(obj, *args)
- end
- end
- end
-end
-
diff --git a/lib/puppet/network/xmlrpc/server.rb b/lib/puppet/network/xmlrpc/server.rb
deleted file mode 100644
index e54881756..000000000
--- a/lib/puppet/network/xmlrpc/server.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require 'xmlrpc/server'
-require 'puppet/network/authorization'
-require 'puppet/network/xmlrpc/processor'
-
-module Puppet::Network
- # Most of our subclassing is just so that we can get
- # access to information from the request object, like
- # the client name and IP address.
- class XMLRPCServer < ::XMLRPC::BasicServer
- include Puppet::Util
- include Puppet::Network::XMLRPCProcessor
-
- def initialize
- super()
- setup_processor
- end
- end
-end
-
diff --git a/lib/puppet/network/xmlrpc/webrick_servlet.rb b/lib/puppet/network/xmlrpc/webrick_servlet.rb
deleted file mode 100644
index c538cf74c..000000000
--- a/lib/puppet/network/xmlrpc/webrick_servlet.rb
+++ /dev/null
@@ -1,114 +0,0 @@
-require 'xmlrpc/server'
-require 'puppet/network/authorization'
-require 'puppet/network/xmlrpc/processor'
-
-module Puppet::Network::XMLRPC
- class ServletError < RuntimeError; end
- class WEBrickServlet < ::XMLRPC::WEBrickServlet
- include Puppet::Network::XMLRPCProcessor
-
- # This is a hackish way to avoid an auth message every time we have a
- # normal operation
- def self.log(msg)
- @logs ||= {}
- if @logs.include?(msg)
- @logs[msg] += 1
- else
- Puppet.info msg
- @logs[msg] = 1
- end
- end
-
- # Accept a list of handlers and register them all.
- def initialize(handlers)
- # the servlet base class does not consume any arguments
- # and its BasicServer base class only accepts a 'class_delim'
- # option which won't change in Puppet at all
- # thus, we don't need to pass any args to our base class,
- # and we can consume them all ourselves
- super()
-
- setup_processor
-
- # Set up each of the passed handlers.
- handlers.each do |handler|
- add_handler(handler.class.interface, handler)
- end
- end
-
- # Handle the actual request. We can't use the super() method, because
- # we need to pass a ClientRequest object to process so we can do
- # authorization. It's the only way to stay thread-safe.
- def service(request, response)
- if @valid_ip
- raise WEBrick::HTTPStatus::Forbidden unless @valid_ip.any? { |ip| request.peeraddr[3] =~ ip }
- end
-
- if request.request_method != "POST"
- raise WEBrick::HTTPStatus::MethodNotAllowed,
- "unsupported method `#{request.request_method}'."
- end
-
- raise WEBrick::HTTPStatus::BadRequest if parse_content_type(request['Content-type']).first != "text/xml"
-
- length = (request['Content-length'] || 0).to_i
-
- raise WEBrick::HTTPStatus::LengthRequired unless length > 0
-
- data = request.body
-
- raise WEBrick::HTTPStatus::BadRequest if data.nil? or data.size != length
-
- resp = process(data, client_request(request))
- raise WEBrick::HTTPStatus::InternalServerError if resp.nil? or resp.size <= 0
-
- response.status = 200
- response['Content-Length'] = resp.size
- response['Content-Type'] = "text/xml; charset=utf-8"
- response.body = resp
- end
-
- private
-
- # Generate a ClientRequest object for later validation.
- def client_request(request)
- if peer = request.peeraddr
- client = peer[2]
- clientip = peer[3]
- else
-
- raise ::XMLRPC::FaultException.new(
-
- ERR_UNCAUGHT_EXCEPTION,
-
- "Could not retrieve client information"
- )
- end
-
- # If they have a certificate (which will almost always be true)
- # then we get the hostname from the cert, instead of via IP
- # info
- valid = false
- if cert = request.client_cert
- nameary = cert.subject.to_a.find { |ary|
- ary[0] == "CN"
- }
-
- if nameary.nil?
- Puppet.warning "Could not retrieve server name from cert"
- else
- unless client == nameary[1]
- Puppet.debug "Overriding #{client} with cert name #{nameary[1]}"
- client = nameary[1]
- end
- valid = true
- end
- end
-
- info = Puppet::Network::ClientRequest.new(client, clientip, valid)
-
- info
- end
- end
-end
-
diff --git a/lib/puppet/reference/network.rb b/lib/puppet/reference/network.rb
deleted file mode 100644
index ee8fea07e..000000000
--- a/lib/puppet/reference/network.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'puppet/network/handler'
-
-network = Puppet::Util::Reference.newreference :network, :depth => 2, :doc => "Available network handlers and clients" do
- ret = ""
- Puppet::Network::Handler.subclasses.sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- handler = Puppet::Network::Handler.handler(name)
-
- next if ! handler.doc or handler.doc == ""
-
- interface = handler.interface
-
- ret << markdown_header(name, 2)
-
- ret << scrub(handler.doc)
- ret << "\n\n"
- ret << option(:prefix, interface.prefix)
- ret << option(:side, handler.side.to_s.capitalize)
- ret << option(:methods, interface.methods.collect { |ary| ary[0] }.join(", ") )
- ret << "\n\n"
- end
-
- ret
-end
-
-network.header = "
-This is a list of all Puppet network interfaces. Each interface is
-implemented in the form of a client and a handler; the handler is loaded
-on the server, and the client knows how to call the handler's methods
-appropriately.
-
-Most handlers are meant to be started on the server, usually within
-`puppet master`, and the clients are mostly started on the client,
-usually within `puppet agent`.
-
-You can find the server-side handler for each interface at
-`puppet/network/handler/<name>.rb` and the client class at
-`puppet/network/client/<name>.rb`.
-
-"
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index c89ea935a..2d537714f 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -5,7 +5,6 @@ require 'uri'
require 'fileutils'
require 'enumerator'
require 'pathname'
-require 'puppet/network/handler'
require 'puppet/util/diff'
require 'puppet/util/checksums'
require 'puppet/util/backups'
diff --git a/spec/integration/network/handler_spec.rb b/spec/integration/network/handler_spec.rb
deleted file mode 100755
index a71e76e71..000000000
--- a/spec/integration/network/handler_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-require 'puppet/network/handler'
-
-describe Puppet::Network::Handler do
- %w{ca filebucket fileserver report runner status}.each do |name|
- it "should have a #{name} client" do
- Puppet::Network::Handler.handler(name).should be_instance_of(Class)
- end
-
- it "should have a name" do
- Puppet::Network::Handler.handler(name).name.to_s.downcase.should == name.to_s.downcase
- end
-
- it "should have an interface" do
- Puppet::Network::Handler.handler(name).interface.should_not be_nil
- end
-
- it "should have a prefix for the interface" do
- Puppet::Network::Handler.handler(name).interface.prefix.should_not be_nil
- end
- end
-end
diff --git a/spec/integration/network/server/webrick_spec.rb b/spec/integration/network/server/webrick_spec.rb
index 7365462d3..7fa83b05a 100755
--- a/spec/integration/network/server/webrick_spec.rb
+++ b/spec/integration/network/server/webrick_spec.rb
@@ -11,7 +11,7 @@ describe Puppet::Network::Server, :unless => Puppet.features.microsoft_windows?
before :each do
Puppet[:servertype] = 'webrick'
Puppet[:server] = '127.0.0.1'
- @params = { :port => 34343, :handlers => [ :node ], :xmlrpc_handlers => [ :status ] }
+ @params = { :port => 34343, :handlers => [ :node ] }
# Get a safe temporary file
dir = tmpdir("webrick_integration_testing")
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb
index 0b65b7923..c6045c895 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -5,7 +5,6 @@ require 'puppet/agent'
require 'puppet/application/agent'
require 'puppet/network/server'
require 'puppet/daemon'
-require 'puppet/network/handler'
describe Puppet::Application::Agent do
before :each do
@@ -102,13 +101,6 @@ describe Puppet::Application::Agent do
end
end
- it "should set an existing handler on server" do
- Puppet::Network::Handler.stubs(:handler).with("handler").returns(true)
-
- @puppetd.handle_serve("handler")
- @puppetd.options[:serve].should == [ :handler ]
- end
-
it "should set client to false with --no-client" do
@puppetd.handle_no_client(nil)
@puppetd.options[:client].should be_false
@@ -416,19 +408,6 @@ describe Puppet::Application::Agent do
expect { @puppetd.setup_listen }.to exit_with 14
end
- it "should create a server to listen on at least the Runner handler" do
- Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Runner] }
-
- @puppetd.setup_listen
- end
-
- it "should create a server to listen for specific handlers" do
- @puppetd.options.stubs(:[]).with(:serve).returns([:handler])
- Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers] == [:handler] }
-
- @puppetd.setup_listen
- end
-
it "should use puppet default port" do
Puppet[:puppetport] = 32768
diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb
index c6df48f4d..7a70bb9ee 100755
--- a/spec/unit/application/master_spec.rb
+++ b/spec/unit/application/master_spec.rb
@@ -312,19 +312,6 @@ describe Puppet::Application::Master, :unless => Puppet.features.microsoft_windo
@master.main
end
- it "should create the server with the right XMLRPC handlers" do
- Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket]}
-
- @master.main
- end
-
- it "should create the server with a :ca xmlrpc handler if needed" do
- Puppet.stubs(:[]).with(:ca).returns(true)
- Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers].include?(:CA) }
-
- @master.main
- end
-
it "should generate a SSL cert for localhost" do
Puppet::SSL::Host.expects(:localhost)
@@ -367,17 +354,6 @@ describe Puppet::Application::Master, :unless => Puppet.features.microsoft_windo
Puppet::Network::HTTP::Rack.stubs(:new).returns(@app)
end
- it "it should create the app with REST and XMLRPC support" do
- @master.options.stubs(:[]).with(:rack).returns(:true)
-
- Puppet::Network::HTTP::Rack.expects(:new).with { |args|
- args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket] and
- args[:protocols] == [:rest, :xmlrpc]
- }
-
- @master.main
- end
-
it "it should not start a daemon" do
@master.options.stubs(:[]).with(:rack).returns(:true)
diff --git a/spec/unit/file_serving/metadata_spec.rb b/spec/unit/file_serving/metadata_spec.rb
index 3842b05bc..c0bd6f083 100755
--- a/spec/unit/file_serving/metadata_spec.rb
+++ b/spec/unit/file_serving/metadata_spec.rb
@@ -117,10 +117,6 @@ describe Puppet::FileServing::Metadata do
FileUtils.touch(path)
end
- it "should be able to produce xmlrpc-style attribute information" do
- metadata.should respond_to(:attributes_with_tabs)
- end
-
it "should set the owner to the file's current owner" do
metadata.owner.should == owner
end
@@ -153,12 +149,6 @@ describe Puppet::FileServing::Metadata do
metadata.collect
metadata.checksum.should == "{mtime}#{@time}"
end
-
- it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do
- set_mode(0755, path)
-
- metadata.attributes_with_tabs.should == "#{0755.to_s}\tfile\t#{owner}\t#{group}\t{md5}#{checksum}"
- end
end
end
@@ -181,13 +171,6 @@ describe Puppet::FileServing::Metadata do
metadata.collect
metadata.checksum.should == "{ctime}#{time}"
end
-
- it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do
- set_mode(0755, path)
- metadata.collect
-
- metadata.attributes_with_tabs.should == "#{0755.to_s}\tdirectory\t#{owner}\t#{group}\t{ctime}#{time.to_s}"
- end
end
describe "when managing links", :unless => Puppet.features.microsoft_windows? do
@@ -207,15 +190,6 @@ describe Puppet::FileServing::Metadata do
it "should read links instead of returning their checksums" do
metadata.destination.should == target
end
-
- pending "should produce tab-separated mode, type, owner, group, and destination for xmlrpc" do
- # "We'd like this to be true, but we need to always collect the checksum because in the server/client/server round trip we lose the distintion between manage and follow."
- metadata.attributes_with_tabs.should == "#{0755}\tlink\t#{owner}\t#{group}\t#{target}"
- end
-
- it "should produce tab-separated mode, type, owner, group, checksum, and destination for xmlrpc" do
- metadata.attributes_with_tabs.should == "#{fmode}\tlink\t#{owner}\t#{group}\t{md5}eb9c2bf0eb63f3a7bc0ea37ef18aeba5\t#{target}"
- end
end
end
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index a0f64c6d3..cf7208443 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -371,19 +371,11 @@ describe Puppet::Module do
end
end
- %w{plugins files}.each do |filetype|
- short = filetype.sub(/s$/, '')
- dirname = filetype == "plugins" ? "lib" : filetype.to_s
- it "should be able to return the #{short} directory" do
- Puppet::Module.new("foo").should respond_to(short + "_directory")
- end
-
- it "should return the path to the #{short} directory" do
- mod = Puppet::Module.new("foo")
- mod.stubs(:path).returns "/a/foo"
+ it "should return the path to the plugin directory" do
+ mod = Puppet::Module.new("foo")
+ mod.stubs(:path).returns "/a/foo"
- mod.send(short + "_directory").should == "/a/foo/#{dirname}"
- end
+ mod.plugin_directory.should == "/a/foo/lib"
end
it "should throw a warning if plugins are in a 'plugins' directory rather than a 'lib' directory" do
diff --git a/spec/unit/network/handler/ca_spec.rb b/spec/unit/network/handler/ca_spec.rb
deleted file mode 100644
index 43aa5a721..000000000
--- a/spec/unit/network/handler/ca_spec.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require 'spec_helper'
-
-require 'puppet/network/handler/ca'
-
-describe Puppet::Network::Handler::CA, :unless => Puppet.features.microsoft_windows? do
- include PuppetSpec::Files
-
- describe "#getcert" do
- let(:host) { "testhost" }
- let(:x509_name) { OpenSSL::X509::Name.new [['CN', host]] }
- let(:key) { Puppet::SSL::Key.new(host).generate }
-
- let(:csr) do
- csr = OpenSSL::X509::Request.new
- csr.subject = x509_name
- csr.public_key = key.public_key
- csr
- end
-
- let(:ca) { Puppet::SSL::CertificateAuthority.new }
- let(:cacert) { ca.instance_variable_get(:@certificate) }
-
- before :each do
- Puppet[:confdir] = tmpdir('conf')
-
- Puppet::SSL::CertificateAuthority.stubs(:ca?).returns true
- Puppet::SSL::CertificateAuthority.stubs(:singleton_instance).returns ca
- end
-
- it "should do nothing if the master is not a CA" do
- Puppet::SSL::CertificateAuthority.stubs(:ca?).returns false
-
- csr = OpenSSL::X509::Request.new
- subject.getcert(csr.to_pem).should == ''
- end
-
- describe "when a certificate already exists for the host" do
- let!(:cert) { ca.generate(host) }
-
- it "should return the existing cert if it matches the public key of the CSR" do
- csr.public_key = cert.content.public_key
-
- subject.getcert(csr.to_pem).should == [cert.to_s, cacert.to_s]
- end
-
- it "should fail if the public key of the CSR does not match the existing cert" do
- expect do
- subject.getcert(csr.to_pem)
- end.to raise_error(Puppet::Error, /Certificate request does not match existing certificate/)
- end
- end
-
- describe "when autosign is enabled" do
- before :each do
- Puppet[:autosign] = true
- end
-
- it "should return the new cert and the CA cert" do
- cert_str, cacert_str = subject.getcert(csr.to_pem)
-
- returned_cert = Puppet::SSL::Certificate.from_s(cert_str)
- returned_cacert = Puppet::SSL::Certificate.from_s(cacert_str)
-
- returned_cert.name.should == host
- returned_cacert.content.subject.cmp(cacert.content.subject).should == 0
- end
- end
-
- describe "when autosign is disabled" do
- before :each do
- Puppet[:autosign] = false
- end
-
- it "should save the CSR without signing it" do
- subject.getcert(csr.to_pem)
-
- Puppet::SSL::Certificate.indirection.find(host).should be_nil
- Puppet::SSL::CertificateRequest.indirection.find(host).should be_a(Puppet::SSL::CertificateRequest)
- end
-
- it "should not return a cert" do
- subject.getcert(csr.to_pem).should be_nil
- end
- end
- end
-end
diff --git a/spec/unit/network/handler/fileserver_spec.rb b/spec/unit/network/handler/fileserver_spec.rb
deleted file mode 100755
index 2b8094b8b..000000000
--- a/spec/unit/network/handler/fileserver_spec.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-require 'puppet/network/handler/fileserver'
-
-describe Puppet::Network::Handler::FileServer do
- include PuppetSpec::Files
-
- def create_file(filename)
- File.open(filename, "w") { |f| f.puts filename}
- end
-
- def create_nested_file
- dirname = File.join(@basedir, "nested_dir")
- Dir.mkdir(dirname)
- file = File.join(dirname, "nested_dir_file")
- create_file(file)
- end
-
- before do
- @basedir = tmpdir("test_network_handler")
- @file = File.join(@basedir, "aFile")
- @link = File.join(@basedir, "aLink")
- create_file(@file)
- @mount = Puppet::Network::Handler::FileServer::Mount.new("some_path", @basedir)
- end
-
- describe "when parsing the fileserver.conf" do
- it "should create a valid mount when a valid conf is read" do
- config_file = tmpfile('fileserver.conf')
- mountdir = tmpdir('mountdir')
-
- conf_text = <<-HEREDOC
- [mymount]
- path #{mountdir}
- allow anyone.com
- deny nobody.com
- HEREDOC
- File.open(config_file, 'w') { |f| f.write conf_text }
-
- fs = Puppet::Network::Handler::FileServer.new(:Config => config_file)
- mounts = fs.instance_variable_get(:@mounts)
- mount = mounts["mymount"]
- mount.path == mountdir
- mount.instance_variable_get(:@declarations).map {|d| d.pattern}.should =~ [["com", "nobody"], ["com", "anyone"]]
- end
-
- ['path', 'allow', 'deny'].each do |arg|
- it "should error if config file doesn't specify a mount for #{arg} argument" do
- config_file = tmpfile('fileserver.conf')
- File.open(config_file, 'w') { |f| f.puts "#{arg} 127.0.0.1/24" }
-
- expect {
- Puppet::Network::Handler::FileServer.new(:Config => config_file)
- }.should raise_error(Puppet::Network::Handler::FileServerError, "No mount specified for argument #{arg} 127.0.0.1/24")
- end
- end
- end
-
- it "should list a single directory" do
- @mount.list("/", false, false).should == [["/", "directory"]]
- end
-
- it "should list a file within a directory when given the file path" do
- @mount.list("/aFile", false, "false").should == [["/", "file"]]
- end
-
- it "should list a file within a directory when given the file path with recursion" do
- @mount.list("/aFile", true, "false").should == [["/", "file"]]
- end
-
- it "should return nil for a non-existent path" do
- @mount.list("/no_such_file", false, false).should be(nil)
- end
-
- it "should list a symbolic link as a file when given the link path", :unless => Puppet.features.microsoft_windows? do
- File.symlink(@file, @link)
- @mount.list("/aLink", false, false).should == [["/", "file"]]
- end
-
- it "should return nil for a dangling symbolic link when given the link path", :unless => Puppet.features.microsoft_windows? do
- File.symlink("/some/where", @link)
- @mount.list("/aLink", false, false).should be(nil)
- end
-
- it "should list directory contents of a flat directory structure when asked to recurse" do
- list = @mount.list("/", true, false)
- list.should include(["/aFile", "file"])
- list.should include(["/", "directory"])
- list.should have(2).items
- end
-
- it "should list the contents of a nested directory" do
- create_nested_file
- list = @mount.list("/", true, false)
- list.sort.should == [ ["/aFile", "file"], ["/", "directory"] , ["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
- end
-
- it "should list the contents of a directory ignoring files that match" do
- create_nested_file
- list = @mount.list("/", true, "*File")
- list.sort.should == [ ["/", "directory"] , ["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
- end
-
- it "should list the contents of a directory ignoring directories that match" do
- create_nested_file
- list = @mount.list("/", true, "*nested_dir")
- list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ].sort
- end
-
- it "should list the contents of a directory ignoring all ignore patterns that match" do
- create_nested_file
- list = @mount.list("/", true, ["*File" , "*nested_dir"])
- list.should == [ ["/", "directory"] ]
- end
-
- it "should list the directory when recursing to a depth of zero" do
- create_nested_file
- list = @mount.list("/", 0, false)
- list.should == [["/", "directory"]]
- end
-
- it "should list the base directory and files and nested directory to a depth of one" do
- create_nested_file
- list = @mount.list("/", 1, false)
- list.sort.should == [ ["/aFile", "file"], ["/nested_dir", "directory"], ["/", "directory"] ].sort
- end
-
- it "should list the base directory and files and nested directory to a depth of two" do
- create_nested_file
- list = @mount.list("/", 2, false)
- list.sort.should == [ ["/aFile", "file"], ["/", "directory"] , ["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
- end
-
- it "should list the base directory and files and nested directory to a depth greater than the directory structure" do
- create_nested_file
- list = @mount.list("/", 42, false)
- list.sort.should == [ ["/aFile", "file"], ["/", "directory"] , ["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
- end
-
- it "should list a valid symbolic link as a file when recursing base dir", :unless => Puppet.features.microsoft_windows? do
- File.symlink(@file, @link)
- list = @mount.list("/", true, false)
- list.sort.should == [ ["/", "directory"], ["/aFile", "file"], ["/aLink", "file"] ].sort
- end
-
- it "should not error when a dangling symlink is present", :unless => Puppet.features.microsoft_windows? do
- File.symlink("/some/where", @link)
- lambda { @mount.list("/", true, false) }.should_not raise_error
- end
-
- it "should return the directory contents of valid entries when a dangling symlink is present", :unless => Puppet.features.microsoft_windows? do
- File.symlink("/some/where", @link)
- list = @mount.list("/", true, false)
- list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ].sort
- end
-
- describe Puppet::Network::Handler::FileServer::PluginMount, :'fails_on_ruby_1.9.2' => true do
- PLUGINS = Puppet::Network::Handler::FileServer::PLUGINS
-
- # create a module plugin hierarchy
- def create_plugin(mod, plugin)
- dirname = File.join(@basedir, mod)
- Dir.mkdir(dirname)
- plugins = File.join(dirname, PLUGINS)
- Dir.mkdir(plugins)
- facter = File.join(plugins, plugin)
- Dir.mkdir(facter)
- create_file(File.join(facter,"fact.rb"))
- end
-
- before :each do
- @modules = ["one","two"]
- @modules.each { |m| create_plugin(m, "facter") }
-
- Puppet::Node::Environment.new.stubs(:modulepath).returns @basedir
-
- @mount = Puppet::Network::Handler::FileServer::PluginMount.new(PLUGINS)
- @mount.allow("*")
- end
-
- it "should list a file within a directory when given the file path with recursion" do
- @mount.list("facter/fact.rb", true, "false").should == [["/", "file"], ["/", "file"]]
- end
-
- it "should return a merged view of all plugins for all modules" do
- list = @mount.list("facter",true,false)
- list.should == [["/", "directory"], ["/fact.rb", "file"], ["/", "directory"], ["/fact.rb", "file"]]
- end
-
- it "should not fail for inexistant plugins type" do
- @mount.list("puppet/parser",true,false)
- end
-
- end
-
- after do
- FileUtils.rm_rf(@basedir)
- end
-
-end
diff --git a/spec/unit/network/http/mongrel/xmlrpc_spec.rb b/spec/unit/network/http/mongrel/xmlrpc_spec.rb
deleted file mode 100755
index e69de29bb..000000000
--- a/spec/unit/network/http/mongrel/xmlrpc_spec.rb
+++ /dev/null
diff --git a/spec/unit/network/http/mongrel_spec.rb b/spec/unit/network/http/mongrel_spec.rb
index 9e7e9c485..0875c054d 100755
--- a/spec/unit/network/http/mongrel_spec.rb
+++ b/spec/unit/network/http/mongrel_spec.rb
@@ -20,10 +20,7 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening", :if => P
@mock_mongrel.stubs(:register)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
- @mock_puppet_mongrel = mock('puppet_mongrel')
- Puppet::Network::HTTPServer::Mongrel.stubs(:new).returns(@mock_puppet_mongrel)
-
- @listen_params = { :address => "127.0.0.1", :port => 31337, :protocols => [ :rest, :xmlrpc ], :xmlrpc_handlers => [ :status, :fileserver ] }
+ @listen_params = { :address => "127.0.0.1", :port => 31337 }
end
it "should fail if already listening" do
@@ -66,29 +63,6 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening", :if => P
@server.listen(@listen_params)
end
-
- it "should use a Mongrel + REST class to configure Mongrel when REST services are requested" do
- @server.expects(:class_for_protocol).with(:rest).at_least_once.returns(Puppet::Network::HTTP::MongrelREST)
- @server.listen(@listen_params)
- end
- end
-
- describe "when providing XMLRPC services" do
- it "should do nothing if no xmlrpc handlers have been provided" do
- Puppet::Network::HTTPServer::Mongrel.expects(:new).never
- @server.listen(@listen_params.merge(:xmlrpc_handlers => []))
- end
-
- it "should create an instance of the existing Mongrel http server with the right handlers" do
- Puppet::Network::HTTPServer::Mongrel.expects(:new).with([:status, :master]).returns(@mock_puppet_mongrel)
- @server.listen(@listen_params.merge(:xmlrpc_handlers => [:status, :master]))
- end
-
- it "should register the Mongrel server instance at /RPC2" do
- @mock_mongrel.expects(:register).with("/RPC2", @mock_puppet_mongrel)
-
- @server.listen(@listen_params.merge(:xmlrpc_handlers => [:status, :master]))
- end
end
end
diff --git a/spec/unit/network/http/rack/xmlrpc_spec.rb b/spec/unit/network/http/rack/xmlrpc_spec.rb
deleted file mode 100755
index 9173438a6..000000000
--- a/spec/unit/network/http/rack/xmlrpc_spec.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-require 'puppet/network/handler'
-require 'puppet/network/http/rack' if Puppet.features.rack?
-require 'puppet/network/http/rack/xmlrpc' if Puppet.features.rack?
-
-describe "Puppet::Network::HTTP::RackXMLRPC", :if => Puppet.features.rack? do
- describe "when initializing" do
- it "should create an Puppet::Network::XMLRPCServer" do
- Puppet::Network::XMLRPCServer.expects(:new).returns stub_everything
- Puppet::Network::HTTP::RackXMLRPC.new([])
- end
-
- it "should create each handler" do
- handler = stub_everything 'handler'
- Puppet::Network::XMLRPCServer.any_instance.stubs(:add_handler)
- Puppet::Network::Handler.expects(:handler).returns(handler).times(2)
- Puppet::Network::HTTP::RackXMLRPC.new([:foo, :bar])
- end
-
- it "should add each handler to the XMLRPCserver" do
- handler = stub_everything 'handler'
- Puppet::Network::Handler.stubs(:handler).returns(handler)
- Puppet::Network::XMLRPCServer.any_instance.expects(:add_handler).times(2)
- Puppet::Network::HTTP::RackXMLRPC.new([:foo, :bar])
- end
- end
-
- describe "when serving a request" do
-
- before :each do
- foo_handler = stub_everything 'foo_handler'
- Puppet::Network::Handler.stubs(:handler).with(:foo).returns foo_handler
- Puppet::Network::XMLRPCServer.any_instance.stubs(:add_handler)
- Puppet::Network::XMLRPCServer.any_instance.stubs(:process).returns('<xml/>')
- @handler = Puppet::Network::HTTP::RackXMLRPC.new([:foo])
- end
-
- before :each do
- @response = Rack::Response.new
- end
-
- def mk_req(opts = {})
- opts[:method] = 'POST' if !opts[:method]
- opts['CONTENT_TYPE'] = 'text/xml; foo=bar' if !opts['CONTENT_TYPE']
- env = Rack::MockRequest.env_for('/RPC2', opts)
- Rack::Request.new(env)
- end
-
- it "should reject non-POST requests" do
- req = mk_req :method => 'PUT'
- @handler.process(req, @response)
- @response.status.should == 405
- end
-
- it "should reject non text/xml requests" do
- req = mk_req 'CONTENT_TYPE' => 'yadda/plain'
- end
-
- it "should create a ClientRequest" do
- cr = Puppet::Network::ClientRequest.new(nil, '127.0.0.1', false)
- Puppet::Network::ClientRequest.expects(:new).returns cr
- req = mk_req
- @handler.process(req, @response)
- end
-
- it "should let xmlrpcserver process the request" do
- Puppet::Network::XMLRPCServer.any_instance.expects(:process).returns('yay')
- req = mk_req
- @handler.process(req, @response)
- end
-
- it "should report the response as OK" do
- req = mk_req
- @handler.process(req, @response)
- @response.status.should == 200
- end
-
- it "should report the response with the correct content type" do
- req = mk_req
- @handler.process(req, @response)
- @response['Content-Type'].should == 'text/xml; charset=utf-8'
- end
-
- it "should set 'authenticated' to false if no certificate is present" do
- req = mk_req
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| authenticated == false }
- @handler.process(req, @response)
- end
-
- it "should use the client's ip address" do
- req = mk_req 'REMOTE_ADDR' => 'ipaddress'
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| ip == 'ipaddress' }
- @handler.process(req, @response)
- end
-
- describe "with pre-validated certificates" do
-
- it "should use the :ssl_client_header to determine the parameter when looking for the certificate" do
- Puppet.settings.stubs(:value).returns "eh"
- Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
- req = mk_req "myheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should retrieve the hostname by matching the certificate parameter" do
- Puppet.settings.stubs(:value).returns "eh"
- Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| node == "host.domain.com" }
- req = mk_req "myheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should use the :ssl_client_header to determine the parameter for checking whether the host certificate is valid" do
- Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
- Puppet.settings.expects(:value).with(:ssl_client_verify_header).returns "myheader"
- req = mk_req "myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should consider the host authenticated if the validity parameter contains 'SUCCESS'" do
- Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
- Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| authenticated == true }
- req = mk_req "myheader" => "SUCCESS", "certheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should consider the host unauthenticated if the validity parameter does not contain 'SUCCESS'" do
- Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
- Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| authenticated == false }
- req = mk_req "myheader" => "whatever", "certheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should consider the host unauthenticated if no certificate information is present" do
- Puppet.settings.stubs(:value).with(:ssl_client_header).returns "certheader"
- Puppet.settings.stubs(:value).with(:ssl_client_verify_header).returns "myheader"
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| authenticated == false }
- req = mk_req "myheader" => nil, "certheader" => "/CN=host.domain.com"
- @handler.process(req, @response)
- end
-
- it "should resolve the node name with an ip address look-up if no certificate is present" do
- Puppet.settings.stubs(:value).returns "eh"
- Puppet.settings.expects(:value).with(:ssl_client_header).returns "myheader"
- Resolv.any_instance.expects(:getname).returns("host.domain.com")
- Puppet::Network::ClientRequest.expects(:new).with { |node,ip,authenticated| node == "host.domain.com" }
- req = mk_req "myheader" => nil
- @handler.process(req, @response)
- end
- end
- end
-end
diff --git a/spec/unit/network/http/rack_spec.rb b/spec/unit/network/http/rack_spec.rb
index 9e1ee3d1e..2aae4116b 100755
--- a/spec/unit/network/http/rack_spec.rb
+++ b/spec/unit/network/http/rack_spec.rb
@@ -1,6 +1,5 @@
#!/usr/bin/env rspec
require 'spec_helper'
-require 'puppet/network/handler'
require 'puppet/network/http/rack' if Puppet.features.rack?
describe "Puppet::Network::HTTP::Rack", :if => Puppet.features.rack? do
@@ -23,19 +22,6 @@ describe "Puppet::Network::HTTP::Rack", :if => Puppet.features.rack? do
Puppet::Network::HTTP::Rack.new({:protocols => [:rest]})
end
- describe "with XMLRPC enabled" do
-
- it "should require XMLRPC handlers" do
- Proc.new { Puppet::Network::HTTP::Rack.new({:protocols => [:xmlrpc]}) }.should raise_error(ArgumentError)
- end
-
- it "should create a RackXMLRPC instance" do
- Puppet::Network::HTTP::RackXMLRPC.expects(:new)
- Puppet::Network::HTTP::Rack.new({:protocols => [:xmlrpc], :xmlrpc_handlers => [:Status]})
- end
-
- end
-
end
describe "when called" do
@@ -75,26 +61,5 @@ describe "Puppet::Network::HTTP::Rack", :if => Puppet.features.rack? do
Rack::Response.any_instance.expects(:finish).once
@app.call(@env) # can't lint when finish is a stub
end
-
end
-
- describe "when serving XMLRPC" do
-
- before :all do
- @app = Puppet::Network::HTTP::Rack.new({:protocols => [:rest, :xmlrpc], :xmlrpc_handlers => [:Status]})
- @linted = Rack::Lint.new(@app)
- end
-
- before :each do
- @env = Rack::MockRequest.env_for('/RPC2', :method => 'POST')
- end
-
- it "should use RackXMLRPC to serve /RPC2 requests" do
- Puppet::Network::HTTP::RackXMLRPC.any_instance.expects(:process).once
- @linted.call(@env)
- end
-
- end
-
end
-
diff --git a/spec/unit/network/http/webrick/xmlrpc_spec.rb b/spec/unit/network/http/webrick/xmlrpc_spec.rb
deleted file mode 100755
index e69de29bb..000000000
--- a/spec/unit/network/http/webrick/xmlrpc_spec.rb
+++ /dev/null
diff --git a/spec/unit/network/http/webrick_spec.rb b/spec/unit/network/http/webrick_spec.rb
index f84e78e24..d5e8415be 100755
--- a/spec/unit/network/http/webrick_spec.rb
+++ b/spec/unit/network/http/webrick_spec.rb
@@ -1,6 +1,5 @@
#!/usr/bin/env rspec
require 'spec_helper'
-require 'puppet/network/handler'
require 'puppet/network/http'
require 'puppet/network/http/webrick'
@@ -17,7 +16,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening", :unless =>
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
[:setup_logger, :setup_ssl].each {|meth| @server.stubs(meth).returns({})} # the empty hash is required because of how we're merging
- @listen_params = { :address => "127.0.0.1", :port => 31337, :xmlrpc_handlers => [], :protocols => [ :rest ] }
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :protocols => [ :rest ] }
end
it "should fail if already listening" do
@@ -84,58 +83,6 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening", :unless =>
@server.listen(@listen_params.merge(:protocols => [:rest]))
end
end
-
- describe "when the XMLRPC protocol is requested" do
- before do
- @servlet = mock 'servlet'
-
- Puppet::Network::XMLRPC::WEBrickServlet.stubs(:new).returns @servlet
-
- @master_handler = mock('master_handler')
- @file_handler = mock('file_handler')
-
- @master = mock 'master'
- @file = mock 'file'
- @master_handler.stubs(:new).returns @master
- @file_handler.stubs(:new).returns @file
-
- Puppet::Network::Handler.stubs(:handler).with(:master).returns @master_handler
- Puppet::Network::Handler.stubs(:handler).with(:fileserver).returns @file_handler
- end
-
- it "should do nothing if no xmlrpc handlers have been specified" do
- Puppet::Network::Handler.expects(:handler).never
-
- @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => []))
- end
-
- it "should look the handler classes up via their base class" do
- Puppet::Network::Handler.expects(:handler).with(:master).returns @master_handler
- Puppet::Network::Handler.expects(:handler).with(:fileserver).returns @file_handler
-
- @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
- end
-
- it "should create an instance for each requested xmlrpc handler" do
- @master_handler.expects(:new).returns @master
- @file_handler.expects(:new).returns @file
-
- @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
- end
-
- it "should create a webrick servlet with the xmlrpc handler instances" do
- Puppet::Network::XMLRPC::WEBrickServlet.expects(:new).with([@master, @file]).returns @servlet
-
- @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
- end
-
- it "should mount the webrick servlet at /RPC2" do
- @mock_webrick.stubs(:mount)
- @mock_webrick.expects(:mount).with("/RPC2", @servlet)
-
- @server.listen(@listen_params.merge(:protocols => [:xmlrpc], :xmlrpc_handlers => [:master, :fileserver]))
- end
- end
end
diff --git a/spec/unit/network/server_spec.rb b/spec/unit/network/server_spec.rb
index b38e82b93..f050dd5c3 100755
--- a/spec/unit/network/server_spec.rb
+++ b/spec/unit/network/server_spec.rb
@@ -1,7 +1,6 @@
#!/usr/bin/env rspec
require 'spec_helper'
require 'puppet/network/server'
-require 'puppet/network/handler'
describe Puppet::Network::Server do
before do
@@ -19,7 +18,6 @@ describe Puppet::Network::Server do
describe "when initializing" do
before do
Puppet::Indirector::Indirection.stubs(:model).returns mock('indirection')
- Puppet::Network::Handler.stubs(:handler).returns mock('xmlrpc_handler')
Puppet.settings.stubs(:value).with(:bindaddress).returns("")
Puppet.settings.stubs(:value).with(:masterport).returns('')
end
@@ -94,25 +92,20 @@ describe Puppet::Network::Server do
lambda { @server.unregister(:foo, :bar, :baz) }.should_not raise_error
end
- it "should allow registering XMLRPC handlers" do
- @server = Puppet::Network::Server.new(:port => 31337, :xmlrpc_handlers => [ :foo, :bar, :baz])
- lambda { @server.unregister_xmlrpc(:foo, :bar, :baz) }.should_not raise_error
- end
-
it "should not be listening after initialization" do
Puppet::Network::Server.new(:port => 31337).should_not be_listening
end
it "should use the :main setting section" do
Puppet.settings.expects(:use).with { |*args| args.include?(:main) }
- @server = Puppet::Network::Server.new(:port => 31337, :xmlrpc_handlers => [ :foo, :bar, :baz])
+ @server = Puppet::Network::Server.new(:port => 31337)
end
it "should use the Puppet[:name] setting section" do
Puppet.settings.expects(:value).with(:name).returns "me"
Puppet.settings.expects(:use).with { |*args| args.include?("me") }
- @server = Puppet::Network::Server.new(:port => 31337, :xmlrpc_handlers => [ :foo, :bar, :baz])
+ @server = Puppet::Network::Server.new(:port => 31337)
end
end
@@ -306,8 +299,8 @@ describe Puppet::Network::Server do
@server.should respond_to(:protocols)
end
- it "should set the protocols to :rest and :xmlrpc" do
- @server.protocols.should == [ :rest, :xmlrpc ]
+ it "should set the protocols to :rest" do
+ @server.protocols.should == [ :rest ]
end
it "should provide a means of determining the listening address" do
@@ -330,70 +323,6 @@ describe Puppet::Network::Server do
lambda { @server2.unregister(:bar) }.should raise_error(ArgumentError)
end
- describe "when managing xmlrpc registrations" do
- before do
- Puppet::Network::Handler.stubs(:handler).returns mock('xmlrpc_handler')
- end
-
- it "should allow registering an xmlrpc handler by specifying its namespace" do
- lambda { @server.register_xmlrpc(:foo) }.should_not raise_error
- end
-
- it "should require that the xmlrpc namespace be valid" do
- Puppet::Network::Handler.stubs(:handler).returns nil
-
- lambda { @server.register_xmlrpc(:foo) }.should raise_error(ArgumentError)
- end
-
- it "should require at least one namespace" do
- lambda { @server.register_xmlrpc }.should raise_error(ArgumentError)
- end
-
- it "should allow multiple namespaces to be registered at once" do
- lambda { @server.register_xmlrpc(:foo, :bar) }.should_not raise_error
- end
-
- it "should allow the use of namespaces to specify which are no longer accessible to clients" do
- @server.register_xmlrpc(:foo, :bar)
- end
-
- it "should leave other namespaces accessible to clients when turning off xmlrpc namespaces" do
- @server.register_xmlrpc(:foo, :bar)
- @server.unregister_xmlrpc(:foo)
- lambda { @server.unregister_xmlrpc(:bar)}.should_not raise_error
- end
-
- it "should allow specifying numerous namespaces which are to be no longer accessible to clients" do
- @server.register_xmlrpc(:foo, :bar)
- lambda { @server.unregister_xmlrpc(:foo, :bar) }.should_not raise_error
- end
-
- it "should not turn off any indirections if given unknown namespaces to turn off" do
- @server.register_xmlrpc(:foo, :bar)
- lambda { @server.unregister_xmlrpc(:foo, :bar, :baz) }.should raise_error(ArgumentError)
- lambda { @server.unregister_xmlrpc(:foo, :bar) }.should_not raise_error
- end
-
- it "should not allow turning off unknown namespaces" do
- @server.register_xmlrpc(:foo, :bar)
- lambda { @server.unregister_xmlrpc(:baz) }.should raise_error(ArgumentError)
- end
-
- it "should disable client access immediately when turning off namespaces" do
- @server.register_xmlrpc(:foo, :bar)
- @server.unregister_xmlrpc(:foo)
- lambda { @server.unregister_xmlrpc(:foo) }.should raise_error(ArgumentError)
- end
-
- it "should allow turning off all namespaces at once" do
- @server.register_xmlrpc(:foo, :bar)
- @server.unregister_xmlrpc
- [ :foo, :bar, :baz].each do |indirection|
- lambda { @server.unregister_xmlrpc(indirection) }.should raise_error(ArgumentError)
- end
- end
- end
-
describe "when listening is off" do
before do
@mock_http_server = mock('http server')
@@ -440,9 +369,8 @@ describe Puppet::Network::Server do
describe "when listening is being turned on" do
before do
Puppet::Indirector::Indirection.stubs(:model).returns mock('indirection')
- Puppet::Network::Handler.stubs(:handler).returns mock('xmlrpc_handler')
- @server = Puppet::Network::Server.new(:port => 31337, :handlers => [:node], :xmlrpc_handlers => [:master])
+ @server = Puppet::Network::Server.new(:port => 31337, :handlers => [:node])
@mock_http_server = mock('http server')
@mock_http_server.stubs(:listen)
end
@@ -483,18 +411,10 @@ describe Puppet::Network::Server do
@server.listen
end
- it "should pass a list of XMLRPC handlers to the HTTP server" do
- @server.stubs(:http_server).returns(@mock_http_server)
- @mock_http_server.expects(:listen).with do |args|
- args[:xmlrpc_handlers] == [ :master ]
- end
- @server.listen
- end
-
it "should pass a list of protocols to the HTTP server" do
@server.stubs(:http_server).returns(@mock_http_server)
@mock_http_server.expects(:listen).with do |args|
- args[:protocols] == [ :rest, :xmlrpc ]
+ args[:protocols] == [ :rest ]
end
@server.listen
end
diff --git a/test/lib/puppettest/servertest.rb b/test/lib/puppettest/servertest.rb
index 82483004d..852c0ec27 100644
--- a/test/lib/puppettest/servertest.rb
+++ b/test/lib/puppettest/servertest.rb
@@ -28,46 +28,5 @@ module PuppetTest::ServerTest
file
end
-
- # create a server, forked into the background
- def mkserver(handlers = nil)
- Puppet[:name] = "puppetmasterd"
- # our default handlers
- unless handlers
- handlers = {
- :CA => {}, # so that certs autogenerate
- :Master => {
- :Manifest => mktestmanifest,
- :UseNodes => false
- },
- }
- end
-
- # then create the actual server
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
-
- :Port => @@port,
-
- :Handlers => handlers
- )
- }
-
- # fork it
- spid = fork {
- trap(:INT) { server.shutdown }
- server.start
- }
-
- # and store its pid for killing
- @@tmppids << spid
-
- # give the server a chance to do its thing
- sleep 1
- spid
- end
-
end
diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb
deleted file mode 100755
index b76f8e199..000000000
--- a/test/network/handler/fileserver.rb
+++ /dev/null
@@ -1,1260 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppet/network/handler/fileserver'
-
-class TestFileServer < Test::Unit::TestCase
- include PuppetTest
-
- def mkmount(path = nil)
- mount = nil
- name = "yaytest"
- base = path || tempfile
- Dir.mkdir(base) unless FileTest.exists?(base)
- # Create a test file
- File.open(File.join(base, "file"), "w") { |f| f.puts "bazoo" }
- assert_nothing_raised {
- mount = Puppet::Network::Handler.fileserver::Mount.new(name, base)
- }
-
- mount
- end
- # make a simple file source
- def mktestdir
- testdir = File.join(tmpdir, "remotefilecopytesting")
- @@tmpfiles << testdir
-
- # create a tmpfile
- pattern = "tmpfile"
- tmpfile = File.join(testdir, pattern)
- assert_nothing_raised {
- Dir.mkdir(testdir)
- File.open(tmpfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- }
-
- [testdir, %r{#{pattern}}, tmpfile]
- end
-
- # make a bunch of random test files
- def mktestfiles(testdir)
- @@tmpfiles << testdir
- assert_nothing_raised {
- files = %w{a b c d e}.collect { |l|
- name = File.join(testdir, "file#{l}")
- File.open(name, "w") { |f|
- f.puts rand(100)
- }
-
- name
- }
-
- return files
- }
- end
-
- def assert_describe(base, file, server)
- file = File.basename(file)
- assert_nothing_raised {
- desc = server.describe(base + file)
- assert(desc, "Got no description for #{file}")
- assert(desc != "", "Got no description for #{file}")
- assert_match(/^\d+/, desc, "Got invalid description #{desc}")
- }
- end
-
- # test for invalid names
- def test_namefailures
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- [" ", "=" "+", "&", "#", "*"].each do |char|
- assert_raise(Puppet::Network::Handler::FileServerError, "'#{char}' did not throw a failure in fileserver module names") {
- server.mount("/tmp", "invalid#{char}name")
- }
- end
- end
-
- # verify that listing the root behaves as expected
- def test_listroot
- server = nil
- testdir, pattern, tmpfile = mktestdir
-
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
-
- # and make our fileserver
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- # mount the testdir
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
-
- # and verify different iterations of 'root' return the same value
- list = nil
- assert_nothing_raised {
- list = server.list("/test/", :manage, true, false)
- }
-
- assert(list =~ pattern)
-
- assert_nothing_raised {
- list = server.list("/test", :manage, true, false)
- }
- assert(list =~ pattern)
-
- end
-
- # test listing individual files
- def test_getfilelist
- server = nil
- testdir, pattern, tmpfile = mktestdir
-
- file = nil
-
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
-
- # get our listing
- list = nil
- sfile = "/test/tmpfile"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
-
- output = "/\tfile"
-
- # verify it got listed as a file
- assert_equal(output, list)
-
- # verify we got all fields
- assert(list !~ /\t\t/)
-
- # verify that we didn't get the directory itself
- list.split("\n").each { |line|
- assert(line !~ %r{remotefile})
- }
-
- # and then verify that the contents match
- contents = File.read(tmpfile)
-
- ret = nil
- assert_nothing_raised {
- ret = server.retrieve(sfile)
- }
-
- assert_equal(contents, ret)
- end
-
- # check that the fileserver is seeing newly created files
- def test_seenewfiles
- server = nil
- testdir, pattern, tmpfile = mktestdir
-
-
- newfile = File.join(testdir, "newfile")
-
- # go through the whole schtick again...
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
-
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
-
- list = nil
- sfile = "/test/"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
-
- # create the new file
- File.open(newfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
-
- newlist = nil
- assert_nothing_raised {
- newlist = server.list(sfile, :manage, true, false)
- }
-
- # verify the list has changed
- assert(list != newlist)
-
- # and verify that we are specifically seeing the new file
- assert(newlist =~ /newfile/)
- end
-
- # verify we can mount /, which is what local file servers will
- # normally do
- def test_mountroot
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- assert_nothing_raised {
- server.mount("/", "root")
- }
-
- testdir, pattern, tmpfile = mktestdir
-
- list = nil
- assert_nothing_raised {
- list = server.list("/root/#{testdir}", :manage, true, false)
- }
-
- assert(list =~ pattern)
- assert_nothing_raised {
- list = server.list("/root#{testdir}", :manage, true, false)
- }
-
- assert(list =~ pattern)
- end
-
- # verify that we're correctly recursing the right number of levels
- def test_recursionlevels
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- # make our deep recursion
- basedir = File.join(tmpdir, "recurseremotetesting")
- testdir = "#{basedir}/with/some/sub/directories/for/the/purposes/of/testing"
- oldfile = File.join(testdir, "oldfile")
- assert_nothing_raised {
- system("mkdir -p #{testdir}")
- File.open(oldfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- @@tmpfiles << basedir
- }
-
- assert_nothing_raised {
- server.mount(basedir, "test")
- }
-
- # get our list
- list = nil
- assert_nothing_raised {
- list = server.list("/test/with", :manage, false, false)
- }
-
- # make sure we only got one line, since we're not recursing
- assert(list !~ /\n/)
-
- # for each level of recursion, make sure we get the right list
- [0, 1, 2].each { |num|
- assert_nothing_raised {
- list = server.list("/test/with", :manage, num, false)
- }
-
- count = 0
- while list =~ /\n/
- list.sub!(/\n/, '')
- count += 1
- end
- assert_equal(num, count)
- }
- end
-
- # verify that we're not seeing the dir we ask for; i.e., that our
- # list is relative to that dir, not it's parent dir
- def test_listedpath
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
-
- # create a deep dir
- basedir = tempfile
- testdir = "#{basedir}/with/some/sub/directories/for/testing"
- oldfile = File.join(testdir, "oldfile")
- assert_nothing_raised {
- system("mkdir -p #{testdir}")
- File.open(oldfile, "w") { |f|
- 3.times { f.puts rand(100) }
- }
- @@tmpfiles << basedir
- }
-
- # mounty mounty
- assert_nothing_raised {
- server.mount(basedir, "localhost")
- }
-
- list = nil
- # and then check a few dirs
- assert_nothing_raised {
- list = server.list("/localhost/with", :manage, false, false)
- }
-
- assert(list !~ /with/)
-
- assert_nothing_raised {
- list = server.list("/localhost/with/some/sub", :manage, true, false)
- }
-
- assert(list !~ /sub/)
- end
-
- # test many dirs, not necessarily very deep
- def test_widelists
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- basedir = tempfile
- dirs = %w{a set of directories}
- assert_nothing_raised {
- Dir.mkdir(basedir)
- dirs.each { |dir|
- Dir.mkdir(File.join(basedir, dir))
- }
- @@tmpfiles << basedir
- }
-
- assert_nothing_raised {
- server.mount(basedir, "localhost")
- }
-
- list = nil
- assert_nothing_raised {
- list = server.list("/localhost/", :manage, 1, false)
- }
- assert_instance_of(String, list, "Server returned %s instead of string")
- list = list.split("\n")
-
- assert_equal(dirs.length + 1, list.length)
- end
-
- # verify that 'describe' works as advertised
- def test_describe
- server = nil
- testdir = tstdir
- files = mktestfiles(testdir)
-
- file = nil
- checks = Puppet::Network::Handler.fileserver::CHECKPARAMS
-
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- assert_nothing_raised {
- server.mount(testdir, "test")
- }
-
- # get our list
- list = nil
- sfile = "/test/"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false)
- }
-
- # and describe each file in the list
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
-
- desc = server.describe(sfile + file)
- }
- }
-
- # and then make sure we can describe everything that we know is there
- files.each { |file|
- assert_describe(sfile, file, server)
- }
-
- # And then describe some files that we know aren't there
- retval = nil
- assert_nothing_raised("Describing non-existent files raised an error") {
- retval = server.describe(sfile + "noexisties")
- }
-
- assert_equal("", retval, "Description of non-existent files returned a value")
-
- # Now try to describe some sources that don't even exist
- retval = nil
-
- assert_raise(
- Puppet::Network::Handler::FileServerError,
-
- "Describing non-existent mount did not raise an error") {
- retval = server.describe("/notmounted/noexisties")
- }
-
- assert_nil(retval, "Description of non-existent mounts returned a value")
- end
-
- def test_describe_does_not_fail_when_mount_does_not_find_file
- server = Puppet::Network::Handler.fileserver.new(:Local => true, :Config => false)
-
- assert_nothing_raised("Failed when describing missing plugins") do
- server.describe "/plugins"
- end
- end
-
- # test that our config file is parsing and working as planned
- def test_configfile
- server = nil
- basedir = File.join(tmpdir, "fileserverconfigfiletesting")
- @@tmpfiles << basedir
-
- # make some dirs for mounting
- Dir.mkdir(basedir)
- mounts = {}
- %w{thing thus the-se those}.each { |dir|
- path = File.join(basedir, dir)
- Dir.mkdir(path)
- mounts[dir] = mktestfiles(path)
-
- }
-
- # create an example file with each of them
- conffile = tempfile
- @@tmpfiles << conffile
-
- File.open(conffile, "w") { |f|
- f.print "# a test config file
-
-[thing]
- path #{basedir}/thing
- allow 192.168.0.*
-
-[thus]
- path #{basedir}/thus
- allow *.madstop.com, *.kanies.com
- deny *.sub.madstop.com
-
-[the-se]
- path #{basedir}/the-se
-
-[those]
- path #{basedir}/those
-
-"
- }
-
-
- # create a server with the file
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => false,
-
- :Config => conffile
- )
- }
-
- list = nil
- # run through once with no host/ip info, to verify everything is working
- mounts.each { |mount, files|
- mount = "/#{mount}/"
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
-
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
-
- desc = server.describe(mount + file)
- }
- }
-
- files.each { |f|
- assert_describe(mount, f, server)
- }
- }
-
- # now let's check that things are being correctly forbidden
- # this is just a map of names and expected results
- {
- "thing" => {
- :deny => [
- ["hostname.com", "192.168.1.0"],
- ["hostname.com", "192.158.0.0"]
- ],
- :allow => [
- ["hostname.com", "192.168.0.0"],
- ["hostname.com", "192.168.0.245"],
- ]
- },
- "thus" => {
- :deny => [
- ["hostname.com", "192.168.1.0"],
- ["name.sub.madstop.com", "192.158.0.0"]
- ],
- :allow => [
- ["luke.kanies.com", "192.168.0.0"],
- ["luke.madstop.com", "192.168.0.245"],
- ]
- }
- }.each { |mount, hash|
- mount = "/#{mount}/"
-
- # run through the map
- hash.each { |type, ary|
- ary.each { |sub|
- host, ip = sub
-
- case type
- when :deny
-
- assert_raise(
- Puppet::AuthorizationError,
-
- "Host #{host}, ip #{ip}, allowed #{mount}") {
- list = server.list(mount, :manage, true, false, host, ip)
- }
- when :allow
- assert_nothing_raised("Host #{host}, ip #{ip}, denied #{mount}") {
- list = server.list(mount, :manage, true, false, host, ip)
- }
- end
- }
- }
- }
-
- end
-
- # Test that we smoothly handle invalid config files
- def test_configfailures
- # create an example file with each of them
- conffile = tempfile
-
- invalidmounts = {
- "noexist" => "[noexist]
- path /this/path/does/not/exist
- allow 192.168.0.*
-"
-}
-
- invalidconfigs = [
- "[not valid]
- path /this/path/does/not/exist
- allow 192.168.0.*
-",
-"[valid]
- invalidstatement
- path /etc
- allow 192.168.0.*
-",
-"[valid]
- allow 192.168.0.*
-"
-]
-
- invalidmounts.each { |mount, text|
- File.open(conffile, "w") { |f|
- f.print text
- }
-
-
- # create a server with the file
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => conffile
- )
- }
-
-
- assert_raise(
- Puppet::Network::Handler::FileServerError,
-
- "Invalid mount was mounted") {
- server.list(mount, :manage)
- }
- }
-
- invalidconfigs.each_with_index { |text, i|
- File.open(conffile, "w") { |f|
- f.print text
- }
-
-
- # create a server with the file
- server = nil
-
- assert_raise(
- Puppet::Network::Handler::FileServerError,
-
- "Invalid config #{i} did not raise error") {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => conffile
- )
- }
- }
- end
-
- # verify we reread the config file when it changes
- def test_filereread
- server = nil
-
- conffile = tempfile
- dir = tstdir
-
- files = mktestfiles(dir)
- File.open(conffile, "w") { |f|
- f.print "# a test config file
-
-[thing]
- path #{dir}
- allow test1.domain.com
-"
- }
-
- # Reset the timeout, so we reload faster
- Puppet[:filetimeout] = 0.5
-
- # start our server with a fast timeout
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => false,
-
- :Config => conffile
- )
- }
-
- list = nil
- assert_nothing_raised {
-
- list = server.list(
- "/thing/", :manage, false, false,
-
- "test1.domain.com", "127.0.0.1")
- }
- assert(list != "", "List returned nothing in rereard test")
-
- assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
- }
-
- sleep 1
- File.open(conffile, "w") { |f|
- f.print "# a test config file
-
-[thing]
- path #{dir}
- allow test2.domain.com
-"
- }
-
- assert_raise(Puppet::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1")
- }
-
- assert_nothing_raised {
- list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1")
- }
-
- assert(list != "", "List returned nothing in rereard test")
-
- list = nil
- end
-
- # Verify that we get converted to the right kind of string
- def test_mountstring
- mount = nil
- name = "yaytest"
- path = tmpdir
- assert_nothing_raised {
- mount = Puppet::Network::Handler.fileserver::Mount.new(name, path)
- }
-
- assert_equal("mount[#{name}]", mount.to_s)
- end
-
- def test_servinglinks
- # Disable the checking, so changes propagate immediately.
- Puppet[:filetimeout] = -5
- server = nil
- source = tempfile
- file = File.join(source, "file")
- link = File.join(source, "link")
- Dir.mkdir(source)
- File.open(file, "w") { |f| f.puts "yay" }
- File.symlink(file, link)
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- assert_nothing_raised {
- server.mount(source, "mount")
- }
-
- # First describe the link when following
- results = {}
- assert_nothing_raised {
- server.describe("/mount/link", :follow).split("\t").zip(
- Puppet::Network::Handler.fileserver::CHECKPARAMS
- ).each { |v,p| results[p] = v }
- }
-
- assert_equal("file", results[:type])
-
- # Then not
- results = {}
- assert_nothing_raised {
- server.describe("/mount/link", :manage).split("\t").zip(
- Puppet::Network::Handler.fileserver::CHECKPARAMS
- ).each { |v,p| results[p] = v }
- }
-
- assert_equal("link", results[:type])
-
- results.each { |p,v|
- assert(v, "#{p} has no value")
- assert(v != "", "#{p} has no value")
- }
- end
-
- # Test that substitution patterns in the path are exapanded
- # properly. Disabled, because it was testing too much of the process
- # and in a non-portable way. This is a thorough enough test that it should
- # be kept, but it should be done in a way that is clearly portable (e.g.,
- # no md5 sums of file paths).
- def test_host_specific
- client1 = "client1.example.com"
- client2 = "client2.example.com"
- ip = "127.0.0.1"
-
- # Setup a directory hierarchy for the tests
- fsdir = File.join(tmpdir, "host-specific")
- @@tmpfiles << fsdir
- hostdir = File.join(fsdir, "host")
- fqdndir = File.join(fsdir, "fqdn")
- client1_hostdir = File.join(hostdir, "client1")
- client2_fqdndir = File.join(fqdndir, client2)
- contents = {
- client1_hostdir => "client1\n",
- client2_fqdndir => client2 + "\n"
- }
- [fsdir, hostdir, fqdndir, client1_hostdir, client2_fqdndir].each { |d| Dir.mkdir(d) }
-
- [client1_hostdir, client2_fqdndir].each do |d|
- File.open(File.join(d, "file.txt"), "w") do |f|
- f.print contents[d]
- end
- end
- conffile = tempfile
- File.open(conffile, "w") do |f|
- f.print("
-[host]
-path #{hostdir}/%h
-allow *
-[fqdn]
-path #{fqdndir}/%H
-allow *
-")
- end
-
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => conffile
- )
- }
-
- # check that list returns the correct thing for the two clients
- list = nil
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client1, ip)
- }
- assert_equal("/\tfile", list)
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client2, ip)
- }
- assert_equal("", list)
-
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client1, ip)
- }
- assert_equal("", list)
- assert_nothing_raised {
- list = server.list(sfile, :manage, true, false, client2, ip)
- }
- assert_equal("/\tfile", list)
-
- # check describe
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client1, ip).split("\t")
- }
- assert_equal(5, list.size)
- assert_equal("file", list[1])
- md5 = Digest::MD5.hexdigest(contents[client1_hostdir])
- assert_equal("{md5}#{md5}", list[4])
-
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client2, ip).split("\t")
- }
- assert_equal([], list)
-
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client1, ip).split("\t")
- }
- assert_equal([], list)
-
- assert_nothing_raised {
- list = server.describe(sfile, :manage, client2, ip).split("\t")
- }
- assert_equal(5, list.size)
- assert_equal("file", list[1])
- md5 = Digest::MD5.hexdigest(contents[client2_fqdndir])
- assert_equal("{md5}#{md5}", list[4])
-
- # Check retrieve
- sfile = "/host/file.txt"
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client1, ip).chomp
- }
- assert_equal(contents[client1_hostdir].chomp, list)
-
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client2, ip).chomp
- }
- assert_equal("", list)
-
- sfile = "/fqdn/file.txt"
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client1, ip).chomp
- }
- assert_equal("", list)
-
- assert_nothing_raised {
- list = server.retrieve(sfile, :manage, client2, ip).chomp
- }
- assert_equal(contents[client2_fqdndir].chomp, list)
- end
-
- # Make sure the 'subdir' method in Mount works.
- def test_mount_subdir
- mount = nil
- base = tempfile
- Dir.mkdir(base)
- subdir = File.join(base, "subdir")
- Dir.mkdir(subdir)
- [base, subdir].each do |d|
- File.open(File.join(d, "file"), "w") { |f| f.puts "bazoo" }
- end
- mount = mkmount(base)
-
- assert_equal(base, mount.subdir, "Did not default to base path")
- assert_equal(subdir, mount.subdir("subdir"), "Did not default to base path")
- end
-
- # Make sure mounts get correctly marked expandable or not, depending on
- # the path.
- def test_expandable
- name = "yaytest"
- dir = tempfile
- Dir.mkdir(dir)
-
- mount = mkmount
- assert_nothing_raised {
- mount.path = dir
- }
-
- assert(! mount.expandable?, "Mount incorrectly called expandable")
-
- assert_nothing_raised {
- mount.path = "/dir/a%a"
- }
- assert(mount.expandable?, "Mount not called expandable")
-
- # This isn't a valid replacement pattern, so it should throw an error
- # because the dir doesn't exist
- assert_raise(Puppet::Network::Handler::FileServerError) {
- mount.path = "/dir/a%"
- }
-
- # Now send it back to a normal path
- assert_nothing_raised {
- mount.path = dir
- }
- # Make sure it got reverted
- assert(! mount.expandable?, "Mount incorrectly called expandable")
-
-
- end
-
- def test_mount_expand
- mount = mkmount
-
- check = proc do |client, pattern, repl|
- path = "/my/#{pattern}/file"
- assert_equal("/my/#{repl}/file", mount.expand(path, client))
- end
-
- # Do a round of checks with a fake client
- client = "host.domain.com"
- {"%h" => "host", # Short name
- "%H" => client, # Full name
- "%d" => "domain.com", # domain
- "%%" => "%", # escape
- "%o" => "%o" # other
- }.each do |pat, repl|
- result = check.call(client, pat, repl)
- end
-
- # Now, check that they use Facter info
- client = nil
- Facter.stubs(:value).with { |v| v.to_s == "hostname" }.returns("myhost")
- Facter.stubs(:value).with { |v| v.to_s == "domain" }.returns("mydomain.com")
-
-
- Facter.stubs(:to_hash).returns(
- {
- :ipaddress => "127.0.0.1",
- :hostname => "myhost",
- :domain => "mydomain.com",
-
- })
-
-
- {"%h" => "myhost", # Short name
- "%H" => "myhost.mydomain.com", # Full name
- "%d" => "mydomain.com", # domain
- "%%" => "%", # escape
- "%o" => "%o" # other
- }.each do |pat, repl|
- check.call(client, pat, repl)
- end
-
- end
-
- # Test that the fileserver expands the %h and %d things.
- def test_fileserver_expansion
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler.fileserver.new(
-
- :Local => true,
-
- :Config => false
- )
- }
-
- dir = tempfile
-
- # When mocks attack, part 2
- kernel_fact = Facter.value(:kernel)
-
- ip = '127.0.0.1'
-
-
- Facter.stubs(:to_hash).returns(
- {
- :kernel => kernel_fact,
- :ipaddress => "127.0.0.1",
- :hostname => "myhost",
- :domain => "mydomain.com",
-
- })
-
- Dir.mkdir(dir)
- host = "myhost.mydomain.com"
- {
- "%H" => "myhost.mydomain.com", "%h" => "myhost", "%d" => "mydomain.com"
- }.each do |pattern, string|
- file = File.join(dir, string)
- mount = File.join(dir, pattern)
- File.open(file, "w") do |f| f.puts "yayness: #{string}" end
- name = "name"
- obj = nil
- assert_nothing_raised {
- obj = server.mount(mount, name)
- }
- obj.allow "*"
-
- ret = nil
- assert_nothing_raised do
- ret = server.list("/name", :manage, false, false, host, ip)
- end
-
- assert_equal("/\tfile", ret)
-
- assert_nothing_raised do
- ret = server.describe("/name", :manage, host, ip)
- end
- assert(ret =~ /\tfile\t/, "Did not get valid a description (#{ret.inspect})")
-
- assert_nothing_raised do
- ret = server.retrieve("/name", :manage, host, ip)
- end
-
- assert_equal(ret, File.read(file))
-
- server.umount(name)
-
- File.unlink(file)
- end
- end
-
- # Test the default modules fileserving
- def test_modules_default
- moddir = tempfile
- Dir.mkdir(moddir)
- mounts = {}
- Puppet[:modulepath] = moddir
-
- mods = %w{green red}.collect do |name|
- path = File::join(moddir, name, Puppet::Module::FILES)
- FileUtils::mkdir_p(path)
- if name == "green"
- file = File::join(path, "test.txt")
- File::open(file, "w") { |f| f.print name }
- end
-
- Puppet::Module::find(name)
- end
-
- conffile = tempfile
-
- File.open(conffile, "w") { |f| f.puts "# a test config file" }
-
- # create a server with the file
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler::FileServer.new(
-
- :Local => false ,
-
- :Config => conffile
- )
- }
-
- mods.each do |mod|
- mount = "/#{mod.name}/"
- list = nil
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
- list = list.split("\n")
- if mod.name == "green"
- assert_equal(2, list.size)
- assert_equal("/\tdirectory", list[0])
- assert_equal("/test.txt\tfile", list[1])
- else
- assert_equal(1, list.size)
- assert_equal("/\tdirectory", list[0])
- end
-
- assert_nothing_raised("Host 'allow' denied #{mount}") {
- server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
- }
- end
- end
-
- # Test that configuring deny/allow for modules works
- def test_modules_config
- moddir = tempfile
- Dir.mkdir(moddir)
- mounts = {}
- Puppet[:modulepath] = moddir
-
- path = File::join(moddir, "amod", Puppet::Module::FILES)
- file = File::join(path, "test.txt")
- FileUtils::mkdir_p(path)
- File::open(file, "w") { |f| f.print "Howdy" }
-
- mod = Puppet::Module::find("amod")
-
- conffile = tempfile
- @@tmpfiles << conffile
-
- File.open(conffile, "w") { |f|
- f.print "# a test config file
-[modules]
- path #{basedir}/thing
- allow 192.168.0.*
-"
- }
-
- # create a server with the file
- server = nil
- assert_nothing_raised {
-
- server = Puppet::Network::Handler::FileServer.new(
-
- :Local => false,
-
- :Config => conffile
- )
- }
-
- list = nil
- mount = "/#{mod.name}/"
- assert_nothing_raised {
- list = server.list(mount, :manage, true, false)
- }
-
- assert_nothing_raised {
- list.split("\n").each { |line|
- file, type = line.split("\t")
- server.describe(mount + file)
- }
- }
-
- assert_describe(mount, file, server)
-
- # now let's check that things are being correctly forbidden
-
- assert_raise(
- Puppet::AuthorizationError,
-
- "Host 'deny' allowed #{mount}") {
- server.list(mount, :manage, true, false, 'deny.example.com', "192.168.1.1")
- }
- assert_nothing_raised("Host 'allow' denied #{mount}") {
- server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1")
- }
- end
-
- # Make sure we successfully throw errors -- someone ran into this with
- # 0.22.4.
- def test_failures
- # create a server with the file
- server = nil
-
- config = tempfile
- [
- "[this is invalid]\nallow one.two.com", # invalid name
- "[valid]\nallow *.testing something.com", # invalid allow
- "[valid]\nallow one.two.com\ndeny *.testing something.com", # invalid deny
- ].each do |failer|
- File.open(config, "w") { |f| f.puts failer }
- assert_raise(Puppet::Network::Handler::FileServerError, "Did not fail on #{failer.inspect}") {
-
- server = Puppet::Network::Handler::FileServer.new(
-
- :Local => false,
-
- :Config => config
- )
- }
- end
- end
-
- def test_can_start_without_configuration
- Puppet[:fileserverconfig] = tempfile
- assert_nothing_raised("Could not create fileserver when configuration is absent") do
- server = Puppet::Network::Handler::FileServer.new(
- :Local => false
- )
- end
- end
-
- def test_creates_default_mounts_when_no_configuration_is_available
- Puppet[:fileserverconfig] = tempfile
- server = Puppet::Network::Handler::FileServer.new(:Local => false)
-
- assert(server.mounted?("plugins"), "Did not create default plugins mount when missing configuration file")
- assert(server.mounted?("modules"), "Did not create default modules mount when missing configuration file")
- end
-end
-
-
diff --git a/test/network/handler/report.rb b/test/network/handler/report.rb
deleted file mode 100755
index d0c223878..000000000
--- a/test/network/handler/report.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppet/network/handler/report'
-require 'puppettest/reporttesting'
-
-class TestReportServer < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::Reporttesting
-
- Report = Puppet::Network::Handler.report
- Puppet::Util.logmethods(self)
-
- def mkserver
- server = nil
- assert_nothing_raised {
- server = Puppet::Network::Handler.report.new
- }
- server
- end
-
- def mkclient(server = nil)
- server ||= mkserver
- client = nil
- assert_nothing_raised {
- client = Puppet::Network::Client.report.new(:Report => server)
- }
-
- client
- end
-
- def test_process
- server = Puppet::Network::Handler.report.new
-
- # We have to run multiple reports to make sure there's no conflict
- reports = []
- $run = []
- 2.times do |i|
- name = "processtest#{i}"
- reports << name
-
- Report.newreport(name) do
- def process
- $run << self.report_name
- end
- end
- end
- Puppet[:reports] = reports.collect { |r| r.to_s }.join(",")
-
- report = fakereport
-
- retval = nil
- assert_nothing_raised {
- retval = server.send(:process, YAML.dump(report))
- }
-
- reports.each do |name|
- assert($run.include?(name.intern), "Did not run #{name}")
- end
-
- # Now make sure our server doesn't die on missing reports
- Puppet[:reports] = "fakereport"
- assert_nothing_raised {
- retval = server.send(:process, YAML.dump(report))
- }
- end
-
- def test_reports
- Puppet[:reports] = "myreport"
-
- # Create a server
- server = Puppet::Network::Handler.report.new
-
- {"myreport" => ["myreport"],
- " fake, another, yay " => ["fake", "another", "yay"]
- }.each do |str, ary|
- Puppet[:reports] = str
- assert_equal(ary, server.send(:reports))
- end
- end
-end
diff --git a/test/network/handler/runner.rb b/test/network/handler/runner.rb
deleted file mode 100755
index d03fb2c89..000000000
--- a/test/network/handler/runner.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppet/network/handler/runner'
-
-class TestHandlerRunner < Test::Unit::TestCase
- include PuppetTest
-
- def test_it_calls_agent_runner
- runner = mock 'runner'
- Puppet::Run.expects(:new).with(:tags => "mytags", :ignoreschedules => true, :background => false).returns runner
- runner.expects(:run)
- runner.expects(:status).returns "yay"
-
-
- assert_equal("yay", Puppet::Network::Handler.runner.new.run("mytags", true, true))
- end
-end
diff --git a/test/network/xmlrpc/processor.rb b/test/network/xmlrpc/processor.rb
deleted file mode 100755
index 379b34a85..000000000
--- a/test/network/xmlrpc/processor.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppet/network/xmlrpc/processor'
-require 'mocha'
-
-class TestXMLRPCProcessor < Test::Unit::TestCase
- include PuppetTest
- class BaseProcessor
- def add_handler(interface, handler)
- @handlers ||= {}
- @handlers[interface] = handler
- end
- end
-
- # We use a base class just so super() works with add_handler.
- class Processor < BaseProcessor
- include Puppet::Network::XMLRPCProcessor
-
- def set_service_hook(&block)
- meta_def(:service, &block)
- end
- end
-
- def setup
- super
- Puppet::Util::SUIDManager.stubs(:asuser).yields
- @processor = Processor.new
- end
-
- def test_handlers
- ca = Puppet::Network::Handler.ca
- @processor.send(:setup_processor)
- assert(! @processor.handler_loaded?(:ca), "already have ca handler loaded")
- assert_nothing_raised do
- @processor.add_handler(ca.interface, ca.new)
- end
-
- assert(@processor.handler_loaded?(:puppetca), "ca handler not loaded by symbol")
- assert(@processor.handler_loaded?("puppetca"), "ca handler not loaded by string")
- end
-
- def test_process
- ca = Puppet::Network::Handler.ca
- @processor.send(:setup_processor)
- assert_nothing_raised do
- @processor.add_handler(ca.interface, ca.new)
- end
-
- fakeparser = Class.new do
- def parseMethodCall(data)
- data
- end
- end
-
- request = Puppet::Network::ClientRequest.new("fake", "192.168.0.1", false)
- request.handler = "myhandler"
- request.method = "mymethod"
-
- @processor.expects(:parser).returns(fakeparser.new)
-
- request.expects(:handler=).with("myhandler")
- request.expects(:method=).with("mymethod")
-
- @processor.stubs(:verify)
- @processor.expects(:handle).with(request.call, "params", request.name, request.ip)
-
- @processor.send(:process, ["myhandler.mymethod", ["params"]], request)
- end
-
- def test_setup_processor
- @processor.expects(:set_service_hook)
- @processor.send(:setup_processor)
- end
-end
-
-
diff --git a/test/network/xmlrpc/server.rb b/test/network/xmlrpc/server.rb
deleted file mode 100755
index 0653f009e..000000000
--- a/test/network/xmlrpc/server.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppet/network/xmlrpc/server'
-require 'mocha'
-
-class TestXMLRPCServer < Test::Unit::TestCase
- def setup
- super
- assert_nothing_raised do
- @server = Puppet::Network::XMLRPCServer.new
- end
- end
-
- def test_initialize
- assert(@server.get_service_hook, "no service hook defined")
-
- assert_nothing_raised("Did not init @loadedhandlers") do
- assert(! @server.handler_loaded?(:puppetca), "server thinks handlers are loaded")
- end
- end
-end
-
-
diff --git a/test/network/xmlrpc/webrick_servlet.rb b/test/network/xmlrpc/webrick_servlet.rb
deleted file mode 100755
index f2faf09ec..000000000
--- a/test/network/xmlrpc/webrick_servlet.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-require 'puppettest/support/utils'
-require 'puppet/network/xmlrpc/webrick_servlet'
-require 'mocha'
-
-class TestXMLRPCWEBrickServlet < Test::Unit::TestCase
- include PuppetTest
- def test_basics
- # Make sure we're doing things as our user info, rather than puppet/puppet
- setme
- set_mygroup
- Puppet[:user] = @me
- Puppet[:group] = @mygroup
- servlet = nil
- ca = Puppet::Network::Handler.ca.new
-
- assert_nothing_raised("Could not create servlet") do
- servlet = Puppet::Network::XMLRPC::WEBrickServlet.new([ca])
- end
-
- assert(servlet.get_service_hook, "service hook was not set up")
-
-
- assert(
- servlet.handler_loaded?(:puppetca),
-
- "Did not load handler")
- end
-end
-
-