diff --git a/lib/puppet/file_serving/mount/plugins.rb b/lib/puppet/file_serving/mount/plugins.rb index d21d6e92e..a9048ab98 100644 --- a/lib/puppet/file_serving/mount/plugins.rb +++ b/lib/puppet/file_serving/mount/plugins.rb @@ -1,26 +1,34 @@ require 'puppet/file_serving/mount' # Find files in the modules' plugins directories. # This is a very strange mount because it merges # many directories into one. class Puppet::FileServing::Mount::Plugins < Puppet::FileServing::Mount # Return an instance of the appropriate class. def find(relative_path, request) return nil unless mod = request.environment.modules.find { |mod| mod.plugin(relative_path) } path = mod.plugin(relative_path) path end def search(relative_path, request) # We currently only support one kind of search on plugins - return # them all. paths = request.environment.modules.find_all { |mod| mod.plugins? }.collect { |mod| mod.plugin_directory } - return(paths.empty? ? nil : paths) + if paths.empty? + # If the modulepath is valid then we still need to return a valid root + # directory for the search, but make sure nothing inside it is + # returned. + request.options[:recurse] = false + request.environment.modulepath.empty? ? nil : request.environment.modulepath + else + paths + end end def valid? true end end diff --git a/spec/unit/file_serving/mount/plugins_spec.rb b/spec/unit/file_serving/mount/plugins_spec.rb index b6bed72a0..09da124c3 100755 --- a/spec/unit/file_serving/mount/plugins_spec.rb +++ b/spec/unit/file_serving/mount/plugins_spec.rb @@ -1,60 +1,73 @@ #!/usr/bin/env rspec require 'spec_helper' require 'puppet/file_serving/mount/plugins' describe Puppet::FileServing::Mount::Plugins do before do @mount = Puppet::FileServing::Mount::Plugins.new("plugins") @environment = stub 'environment', :module => nil - @request = stub 'request', :environment => @environment + @options = { :recurse => true } + @request = stub 'request', :environment => @environment, :options => @options end describe "when finding files" do it "should use the provided environment to find the modules" do @environment.expects(:modules).returns [] @mount.find("foo", @request) end it "should return nil if no module can be found with a matching plugin" do mod = mock 'module' mod.stubs(:plugin).with("foo/bar").returns nil @environment.stubs(:modules).returns [mod] @mount.find("foo/bar", @request).should be_nil end it "should return the file path from the module" do mod = mock 'module' mod.stubs(:plugin).with("foo/bar").returns "eh" @environment.stubs(:modules).returns [mod] @mount.find("foo/bar", @request).should == "eh" end end describe "when searching for files" do it "should use the node's environment to find the modules" do @environment.expects(:modules).returns [] + @environment.stubs(:modulepath).returns ["/tmp/modules"] @mount.search("foo", @request) end - it "should return nil if no modules can be found that have plugins" do + it "should return modulepath if no modules can be found that have plugins" do mod = mock 'module' mod.stubs(:plugins?).returns false @environment.stubs(:modules).returns [] + @environment.stubs(:modulepath).returns ["/"] + @options.expects(:[]=).with(:recurse, false) + @mount.search("foo/bar", @request).should == ["/"] + end + + it "should return nil if no modules can be found that have plugins and modulepath is invalid" do + mod = mock 'module' + mod.stubs(:plugins?).returns false + + @environment.stubs(:modules).returns [] + @environment.stubs(:modulepath).returns [] @mount.search("foo/bar", @request).should be_nil end it "should return the plugin paths for each module that has plugins" do one = stub 'module', :plugins? => true, :plugin_directory => "/one" two = stub 'module', :plugins? => true, :plugin_directory => "/two" @environment.stubs(:modules).returns [one, two] @mount.search("foo/bar", @request).should == %w{/one /two} end end end