This looks like a much larger commit than it is -- it doesn't change
any behaviour at all, it just adds some integration tests (which expose
the problem) and then switches from an ad-hoc api to a request-based api.

Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
 lib/puppet/file_serving/terminus_helper.rb     |    8 +-
 lib/puppet/indirector/direct_file_server.rb    |    2 +-
 lib/puppet/indirector/file_server.rb           |   28 +++---
 lib/puppet/indirector/module_files.rb          |   28 +++---
 spec/integration/file_serving/metadata.rb      |    1 -
 spec/integration/indirector/module_files.rb    |    8 ++-
 spec/shared_behaviours/file_server_terminus.rb |    4 +-
 spec/shared_behaviours/file_serving.rb         |   22 ++++--
 spec/unit/file_serving/terminus_helper.rb      |   94 +++++++++++-----------
 spec/unit/indirector/direct_file_server.rb     |   13 +---
 spec/unit/indirector/file_metadata/modules.rb  |    6 +-
 spec/unit/indirector/file_server.rb            |  104 ++++++++++++++----------
 spec/unit/indirector/module_files.rb           |   86 ++++++++++++--------
 13 files changed, 221 insertions(+), 183 deletions(-)

diff --git a/lib/puppet/file_serving/terminus_helper.rb 
b/lib/puppet/file_serving/terminus_helper.rb
index d465aa4..e5da0e2 100644
--- a/lib/puppet/file_serving/terminus_helper.rb
+++ b/lib/puppet/file_serving/terminus_helper.rb
@@ -8,11 +8,11 @@ require 'puppet/file_serving/fileset'
 # Define some common methods for FileServing termini.
 module Puppet::FileServing::TerminusHelper
     # Create model instances for all files in a fileset.
-    def path2instances(key, path, options = {})
-        args = [:links, :ignore, :recurse].inject({}) { |hash, param| 
hash[param] = options[param] if options[param]; hash }
+    def path2instances(request, path)
+        args = [:links, :ignore, :recurse].inject({}) { |hash, param| 
hash[param] = request.options[param] if request.options[param]; hash }
         Puppet::FileServing::Fileset.new(path, args).files.collect do |file|
-            inst = model.new(File.join(key, file), :path => path, 
:relative_path => file)
-            inst.links = options[:links] if options[:links]
+            inst = model.new(File.join(request.key, file), :path => path, 
:relative_path => file)
+            inst.links = request.options[:links] if request.options[:links]
             inst
         end
     end
diff --git a/lib/puppet/indirector/direct_file_server.rb 
b/lib/puppet/indirector/direct_file_server.rb
index 1711356..b3b4886 100644
--- a/lib/puppet/indirector/direct_file_server.rb
+++ b/lib/puppet/indirector/direct_file_server.rb
@@ -22,6 +22,6 @@ class Puppet::Indirector::DirectFileServer < 
Puppet::Indirector::Terminus
     def search(request)
         uri = key2uri(request.key)
         return nil unless FileTest.exists?(uri.path)
-        path2instances(request.key, uri.path, request.options)
+        path2instances(request, uri.path)
     end
 end
diff --git a/lib/puppet/indirector/file_server.rb 
b/lib/puppet/indirector/file_server.rb
index 2eb323d..b0df7ff 100644
--- a/lib/puppet/indirector/file_server.rb
+++ b/lib/puppet/indirector/file_server.rb
@@ -14,28 +14,28 @@ class Puppet::Indirector::FileServer < 
Puppet::Indirector::Terminus
     include Puppet::FileServing::TerminusHelper
 
     # Is the client authorized to perform this action?
-    def authorized?(method, key, options = {})
-        return false unless [:find, :search].include?(method)
+    def authorized?(request)
+        return false unless [:find, :search].include?(request.method)
 
-        uri = key2uri(key)
+        uri = key2uri(request.key)
 
-        configuration.authorized?(uri.path, :node => options[:node], 
:ipaddress => options[:ipaddress])
+        configuration.authorized?(uri.path, :node => request.node, :ipaddress 
=> request.ip)
     end
 
     # Find our key using the fileserver.
-    def find(key, options = {})
-        return nil unless path = find_path(key, options)
-        result =  model.new(key, :path => path)
-        result.links = options[:links] if options[:links]
+    def find(request)
+        return nil unless path = find_path(request)
+        result =  model.new(request.key, :path => path)
+        result.links = request.options[:links] if request.options[:links]
         return result
     end
 
     # Search for files.  This returns an array rather than a single
     # file.
-    def search(key, options = {})
-        return nil unless path = find_path(key, options)
+    def search(request)
+        return nil unless path = find_path(request)
 
-        path2instances(key, path, options)
+        path2instances(request, path)
     end
 
     private
@@ -46,10 +46,10 @@ class Puppet::Indirector::FileServer < 
Puppet::Indirector::Terminus
     end
 
     # Find our path; used by :find and :search.
-    def find_path(key, options)
-        uri = key2uri(key)
+    def find_path(request)
+        uri = key2uri(request.key)
 
-        return nil unless path = configuration.file_path(uri.path, :node => 
options[:node])
+        return nil unless path = configuration.file_path(uri.path, :node => 
request.node)
 
         return path
     end
diff --git a/lib/puppet/indirector/module_files.rb 
b/lib/puppet/indirector/module_files.rb
index 84286d8..cf5c29c 100644
--- a/lib/puppet/indirector/module_files.rb
+++ b/lib/puppet/indirector/module_files.rb
@@ -14,24 +14,24 @@ class Puppet::Indirector::ModuleFiles < 
Puppet::Indirector::Terminus
     include Puppet::FileServing::TerminusHelper
 
     # Is the client allowed access to this key with this method?
-    def authorized?(method, key, options = {})
-        return false unless [:find, :search].include?(method)
+    def authorized?(request)
+        return false unless [:find, :search].include?(request.method)
 
-        uri = key2uri(key)
+        uri = key2uri(request.key)
 
         # Make sure our file path starts with /modules, so that we authorize
         # against the 'modules' mount.
         path = uri.path =~ /^\/modules/ ? uri.path : "/modules" + uri.path
 
-        configuration.authorized?(path, :node => options[:node], :ipaddress => 
options[:ipaddress])
+        configuration.authorized?(path, :node => request.node, :ipaddress => 
request.ip)
     end
 
     # Find our key in a module.
-    def find(key, options = {})
-        return nil unless path = find_path(key, options)
+    def find(request)
+        return nil unless path = find_path(request)
 
-        result = model.new(key, :path => path)
-        result.links = options[:links] if options[:links]
+        result = model.new(request.key, :path => path)
+        result.links = request.options[:links] if request.options[:links]
         return result
     end
 
@@ -41,9 +41,9 @@ class Puppet::Indirector::ModuleFiles < 
Puppet::Indirector::Terminus
     end
 
     # Search for a list of files.
-    def search(key, options = {})
-        return nil unless path = find_path(key, options)
-        path2instances(key, path, options)
+    def search(request)
+        return nil unless path = find_path(request)
+        path2instances(request, path)
     end
 
     private
@@ -63,15 +63,15 @@ class Puppet::Indirector::ModuleFiles < 
Puppet::Indirector::Terminus
     end
 
     # The abstracted method for turning a key into a path; used by both :find 
and :search.
-    def find_path(key, options)
-        uri = key2uri(key)
+    def find_path(request)
+        uri = key2uri(request.key)
 
         # Strip off /modules if it's there -- that's how requests get routed 
to this terminus.
         # Also, strip off the leading slash if present.
         module_name, relative_path = uri.path.sub(/^\/modules\b/, 
'').sub(%r{^/}, '').split(File::Separator, 2)
 
         # And use the environment to look up the module.
-        return nil unless mod = find_module(module_name, options[:node])
+        return nil unless mod = find_module(module_name, request.node)
 
         path = File.join(mod.files, relative_path)
 
diff --git a/spec/integration/file_serving/metadata.rb 
b/spec/integration/file_serving/metadata.rb
index 5600365..067cb56 100755
--- a/spec/integration/file_serving/metadata.rb
+++ b/spec/integration/file_serving/metadata.rb
@@ -16,4 +16,3 @@ describe Puppet::FileServing::Metadata, " when finding files" 
do
         @indirection = Puppet::FileServing::Metadata.indirection
     end
 end
-
diff --git a/spec/integration/indirector/module_files.rb 
b/spec/integration/indirector/module_files.rb
index 1831bff..ae14aa5 100755
--- a/spec/integration/indirector/module_files.rb
+++ b/spec/integration/indirector/module_files.rb
@@ -20,7 +20,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting 
with Puppet::Module
 
         FileTest.expects(:exists?).with(filepath).returns(true)
 
-        @terminus.find("puppetmounts://host/modules/mymod/myfile").should 
be_instance_of(Puppet::FileServing::Content)
+        @request = Puppet::Indirector::Request.new(:content, :find, 
"puppetmounts://host/modules/mymod/myfile")
+
+        @terminus.find(@request).should 
be_instance_of(Puppet::FileServing::Content)
     end
 end
 
@@ -45,7 +47,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting 
with FileServing::F
 
         Dir.expects(:entries).with(filepath).returns(%w{one two})
 
-        result = @terminus.search("puppetmounts://host/modules/mymod/myfile", 
:recurse => true)
+        @request = Puppet::Indirector::Request.new(:content, :search, 
"puppetmounts://host/modules/mymod/myfile", :recurse => true)
+
+        result = @terminus.search(@request)
         result.should be_instance_of(Array)
         result.length.should == 3
         result.each { |r| r.should 
be_instance_of(Puppet::FileServing::Content) }
diff --git a/spec/shared_behaviours/file_server_terminus.rb 
b/spec/shared_behaviours/file_server_terminus.rb
index de08f29..bb6b671 100644
--- a/spec/shared_behaviours/file_server_terminus.rb
+++ b/spec/shared_behaviours/file_server_terminus.rb
@@ -24,6 +24,8 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => 
true do
 
         # Stub out the modules terminus
         @modules = mock 'modules terminus'
+
+        @request = Puppet::Indirector::Request.new(:indirection, :method, 
"puppetmounts://myhost/one/my/file")
     end
 
     it "should use the file server configuration to find files" do
@@ -35,6 +37,6 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => 
true do
         FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
         @mount1.expects(:file).with("my/file", :node => nil).returns(path)
 
-        @terminus.find("puppetmounts://myhost/one/my/file").should 
be_instance_of(@test_class)
+        @terminus.find(@request).should be_instance_of(@test_class)
     end
 end
diff --git a/spec/shared_behaviours/file_serving.rb 
b/spec/shared_behaviours/file_serving.rb
index 82f2072..ba01f75 100644
--- a/spec/shared_behaviours/file_serving.rb
+++ b/spec/shared_behaviours/file_serving.rb
@@ -5,13 +5,13 @@
 
 describe "Puppet::FileServing::Files", :shared => true do
     it "should use the rest terminus when the 'puppet' URI scheme is used and 
a host name is present" do
-        uri = "puppet://myhost/mymod/my/file"
+        uri = "puppet://myhost/fakemod/my/file"
         @indirection.terminus(:rest).expects(:find)
         @test_class.find(uri)
     end
 
     it "should use the rest terminus when the 'puppet' URI scheme is used, no 
host name is present, and the process name is not 'puppet'" do
-        uri = "puppet:///mymod/my/file"
+        uri = "puppet:///fakemod/my/file"
         Puppet.settings.stubs(:value).with(:name).returns("puppetd")
         Puppet.settings.stubs(:value).with(:modulepath).returns("")
         @indirection.terminus(:rest).expects(:find)
@@ -19,7 +19,7 @@ describe "Puppet::FileServing::Files", :shared => true do
     end
 
     it "should use the file_server terminus when the 'puppet' URI scheme is 
used, no host name is present, and the process name is 'puppet'" do
-        uri = "puppet:///mymod/my/file"
+        uri = "puppet:///fakemod/my/file"
         Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => 
"testing"))
         Puppet.settings.stubs(:value).with(:name).returns("puppet")
         Puppet.settings.stubs(:value).with(:modulepath, "testing").returns("")
@@ -33,22 +33,32 @@ describe "Puppet::FileServing::Files", :shared => true do
     end
 
     it "should use the file_server terminus when the 'puppetmounts' URI scheme 
is used" do
-        uri = "puppetmounts:///mymod/my/file"
+        uri = "puppetmounts:///fakemod/my/file"
         @indirection.terminus(:file_server).expects(:find)
         @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
         @test_class.find(uri)
     end
 
     it "should use the file terminus when the 'file' URI scheme is used" do
-        uri = "file:///mymod/my/file"
+        uri = "file:///fakemod/my/file"
         @indirection.terminus(:file).expects(:find)
         @test_class.find(uri)
     end
 
     it "should use the file terminus when a fully qualified path is provided" 
do
-        uri = "/mymod/my/file"
+        uri = "/fakemod/my/file"
         @indirection.terminus(:file).expects(:find)
         @test_class.find(uri)
     end
+
+    it "should use the configuration to test whether the request is allowed" do
+        uri = "puppetmounts:///fakemod/my/file"
+        config = mock 'configuration'
+        @indirection.terminus(:file_server).stubs(:configuration).returns 
config
+
+        @indirection.terminus(:file_server).expects(:find)
+        config.expects(:authorized?).returns(true)
+        @test_class.find(uri, :node => "foo", :ip => "bar")
+    end
 end
 
diff --git a/spec/unit/file_serving/terminus_helper.rb 
b/spec/unit/file_serving/terminus_helper.rb
index b919469..763ce9e 100755
--- a/spec/unit/file_serving/terminus_helper.rb
+++ b/spec/unit/file_serving/terminus_helper.rb
@@ -14,65 +14,63 @@ describe Puppet::FileServing::TerminusHelper do
 
         @model = mock 'model'
         @helper.stubs(:model).returns(@model)
+
+        @request = stub 'request', :key => "url", :options => {}
     end
 
     it "should use a fileset to find paths" do
         fileset = mock 'fileset', :files => []
         Puppet::FileServing::Fileset.expects(:new).with("/my/file", 
{}).returns(fileset)
-        @helper.path2instances("url", "/my/file")
+        @helper.path2instances(@request, "/my/file")
     end
 
     it "should pass :recurse, :ignore, and :links settings on to the fileset 
if present" do
         fileset = mock 'fileset', :files => []
         Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => 
:a, :ignore => :b, :recurse => :c).returns(fileset)
-        @helper.path2instances("url", "/my/file", :links => :a, :ignore => :b, 
:recurse => :c)
-    end
-end
-
-
-describe Puppet::FileServing::TerminusHelper, " when creating instances" do
-    before do
-        @helper = Object.new
-        @helper.extend(Puppet::FileServing::TerminusHelper)
-
-        @model = mock 'model'
-        @helper.stubs(:model).returns(@model)
-
-        @key = "puppet://host/mount/dir"
-
-        @fileset = mock 'fileset', :files => %w{one two}
-        Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
-    end
-
-    it "should create an instance of the model for each path returned by the 
fileset" do
-        @model.expects(:new).returns(:one)
-        @model.expects(:new).returns(:two)
-        @helper.path2instances(@key, "/my/file").length.should == 2
-    end
-
-    it "should set each instance's key to be the original key plus the 
file-specific path" do
-        @model.expects(:new).with { |key, options| key == @key + "/one" 
}.returns(:one)
-        @model.expects(:new).with { |key, options| key == @key + "/two" 
}.returns(:two)
-        @helper.path2instances(@key, "/my/file")
-    end
-
-    it "should set each returned instance's path to the original path" do
-        @model.expects(:new).with { |key, options| options[:path] == 
"/my/file" }.returns(:one)
-        @model.expects(:new).with { |key, options| options[:path] == 
"/my/file" }.returns(:two)
-        @helper.path2instances(@key, "/my/file")
-    end
-
-    it "should set each returned instance's relative path to the file-specific 
path" do
-        @model.expects(:new).with { |key, options| options[:relative_path] == 
"one" }.returns(:one)
-        @model.expects(:new).with { |key, options| options[:relative_path] == 
"two" }.returns(:two)
-        @helper.path2instances(@key, "/my/file")
+        @request.stubs(:options).returns(:links => :a, :ignore => :b, :recurse 
=> :c)
+        @helper.path2instances(@request, "/my/file")
     end
 
-    it "should set the links value on each instance if one is provided" do
-        one = mock 'one', :links= => :manage
-        two = mock 'two', :links= => :manage
-        @model.expects(:new).returns(one)
-        @model.expects(:new).returns(two)
-        @helper.path2instances(@key, "/my/file", :links => :manage)
+    describe "when creating instances" do
+        before do
+            @request.stubs(:key).returns "puppet://host/mount/dir"
+
+            @fileset = mock 'fileset', :files => %w{one two}
+            Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
+        end
+
+        it "should create an instance of the model for each path returned by 
the fileset" do
+            @model.expects(:new).returns(:one)
+            @model.expects(:new).returns(:two)
+            @helper.path2instances(@request, "/my/file").length.should == 2
+        end
+
+        it "should set each instance's key to be the original key plus the 
file-specific path" do
+            @model.expects(:new).with { |key, options| key == @request.key + 
"/one" }.returns(:one)
+            @model.expects(:new).with { |key, options| key == @request.key + 
"/two" }.returns(:two)
+            @helper.path2instances(@request, "/my/file")
+        end
+
+        it "should set each returned instance's path to the original path" do
+            @model.expects(:new).with { |key, options| options[:path] == 
"/my/file" }.returns(:one)
+            @model.expects(:new).with { |key, options| options[:path] == 
"/my/file" }.returns(:two)
+            @helper.path2instances(@request, "/my/file")
+        end
+
+        it "should set each returned instance's relative path to the 
file-specific path" do
+            @model.expects(:new).with { |key, options| options[:relative_path] 
== "one" }.returns(:one)
+            @model.expects(:new).with { |key, options| options[:relative_path] 
== "two" }.returns(:two)
+            @helper.path2instances(@request, "/my/file")
+        end
+
+        it "should set the links value on each instance if one is provided" do
+            one = mock 'one', :links= => :manage
+            two = mock 'two', :links= => :manage
+            @model.expects(:new).returns(one)
+            @model.expects(:new).returns(two)
+
+            @request.options[:links] = :manage
+            @helper.path2instances(@request, "/my/file")
+        end
     end
 end
diff --git a/spec/unit/indirector/direct_file_server.rb 
b/spec/unit/indirector/direct_file_server.rb
index a858371..0753f1b 100755
--- a/spec/unit/indirector/direct_file_server.rb
+++ b/spec/unit/indirector/direct_file_server.rb
@@ -69,29 +69,20 @@ describe Puppet::Indirector::DirectFileServer do
     end
 
     describe Puppet::Indirector::DirectFileServer, "when searching for 
multiple files" do
-
         it "should return nil if the file does not exist" do
             FileTest.expects(:exists?).with("/my/local").returns false
             @server.find(@request).should be_nil
         end
 
-        it "should pass the original key to :path2instances" do
-            FileTest.expects(:exists?).with("/my/local").returns true
-            @server.expects(:path2instances).with { |uri, path, options| uri 
== @uri }
-            @server.search(@request)
-        end
-
         it "should use :path2instances from the terminus_helper to return 
instances if the file exists" do
             FileTest.expects(:exists?).with("/my/local").returns true
             @server.expects(:path2instances)
             @server.search(@request)
         end
 
-        it "should pass any options on to :path2instances" do
+        it "should pass the original request to :path2instances" do
             FileTest.expects(:exists?).with("/my/local").returns true
-            @server.expects(:path2instances).with { |uri, path, options| 
options == {:testing => :one, :other => :two}}
-
-            @request.stubs(:options).returns(:testing => :one, :other => :two)
+            @server.expects(:path2instances).with(@request, "/my/local")
             @server.search(@request)
         end
     end
diff --git a/spec/unit/indirector/file_metadata/modules.rb 
b/spec/unit/indirector/file_metadata/modules.rb
index 62f0183..3905a49 100755
--- a/spec/unit/indirector/file_metadata/modules.rb
+++ b/spec/unit/indirector/file_metadata/modules.rb
@@ -23,11 +23,13 @@ describe Puppet::Indirector::FileMetadata::Modules, " when 
finding metadata" do
         @finder.stubs(:environment).returns(nil)
         @module = Puppet::Module.new("mymod", "/path/to")
         @finder.stubs(:find_module).returns(@module)
+
+        @request = Puppet::Indirector::Request.new(:metadata, :find, 
"puppetmounts://hostname/modules/mymod/my/file")
     end
 
     it "should return nil if the file is not found" do
         FileTest.expects(:exists?).with("/path/to/files/my/file").returns false
-        @finder.find("puppetmounts://hostname/modules/mymod/my/file").should 
be_nil
+        @finder.find(@request).should be_nil
     end
 
     it "should retrieve the instance's attributes if the file is found" do
@@ -35,6 +37,6 @@ describe Puppet::Indirector::FileMetadata::Modules, " when 
finding metadata" do
         instance = mock 'metadta'
         Puppet::FileServing::Metadata.expects(:new).returns instance
         instance.expects :collect_attributes
-        @finder.find("puppetmounts://hostname/modules/mymod/my/file")
+        @finder.find(@request)
     end
 end
diff --git a/spec/unit/indirector/file_server.rb 
b/spec/unit/indirector/file_server.rb
index 79be8cc..ba95173 100755
--- a/spec/unit/indirector/file_server.rb
+++ b/spec/unit/indirector/file_server.rb
@@ -27,34 +27,37 @@ describe Puppet::Indirector::FileServer do
         @uri = "puppetmounts://host/my/local/file"
         @configuration = mock 'configuration'
         
Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
+
+        @request = Puppet::Indirector::Request.new(:myind, :mymethod, @uri)
     end
 
     describe Puppet::Indirector::FileServer, " when finding files" do
 
         it "should use the path portion of the URI as the file name" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil)
-            @file_server.find(@uri)
+            @file_server.find(@request)
         end
 
         it "should use the FileServing configuration to convert the file name 
to a fully qualified path" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil)
-            @file_server.find(@uri)
+            @file_server.find(@request)
         end
 
         it "should pass the node name to the FileServing configuration if one 
is provided" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
"testing")
-            @file_server.find(@uri, :node => "testing")
+            @request.node = "testing"
+            @file_server.find(@request)
         end
 
         it "should return nil if no fully qualified path is found" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil).returns(nil)
-            @file_server.find(@uri).should be_nil
+            @file_server.find(@request).should be_nil
         end
 
         it "should return an instance of the model created with the full path 
if a file is found" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil).returns("/some/file")
             @model.expects(:new).returns(:myinstance)
-            @file_server.find(@uri).should == :myinstance
+            @file_server.find(@request).should == :myinstance
         end
     end
 
@@ -66,23 +69,24 @@ describe Puppet::Indirector::FileServer do
 
         it "should create the instance with the key used to find the instance" 
do
             @model.expects(:new).with { |key, *options| key == @uri }
-            @file_server.find(@uri)
+            @file_server.find(@request)
         end
 
         it "should create the instance with the path at which the instance was 
found" do
             @model.expects(:new).with { |key, options| options[:path] == 
"/some/file" }
-            @file_server.find(@uri)
+            @file_server.find(@request)
         end
 
         it "should set the provided :links setting on to the instance if one 
is provided" do
             @model.expects(:new).returns(@instance)
             @instance.expects(:links=).with(:mytest)
-            @file_server.find(@uri, :links => :mytest)
+            @request.options[:links] = :mytest
+            @file_server.find(@request)
         end
 
         it "should not set a :links value if no :links parameter is provided" 
do
             @model.expects(:new).returns(@instance)
-            @file_server.find(@uri)
+            @file_server.find(@request)
         end
     end
 
@@ -93,41 +97,52 @@ describe Puppet::Indirector::FileServer do
         end
 
         it "should deny the :destroy method" do
-            @file_server.authorized?(:destroy, "whatever").should be_false
+            @request.method = :destroy
+            @file_server.authorized?(@request).should be_false
         end
 
         it "should deny the :save method" do
-            @file_server.authorized?(:save, "whatever").should be_false
-        end
+            @request.method = :save
+            @file_server.authorized?(@request).should be_false
+        end
+        
+        describe "and finding file information" do
+            before do
+                @request.key =  "puppetmounts://host/my/file"
+                @request.method = :find 
+            end
 
-        it "should use the file server configuration to determine 
authorization" do
-            @configuration.expects(:authorized?)
-            @file_server.authorized?(:find, "puppetmounts://host/my/file")
-        end
+            it "should use the file server configuration to determine 
authorization" do
+                @configuration.expects(:authorized?)
+                @file_server.authorized?(@request)
+            end
 
-        it "should pass the file path from the URI to the file server 
configuration" do
-            @configuration.expects(:authorized?).with { |uri, *args| uri == 
"/my/file" }
-            @file_server.authorized?(:find, "puppetmounts://host/my/file")
-        end
+            it "should pass the file path from the URI to the file server 
configuration" do
+                @configuration.expects(:authorized?).with { |uri, *args| uri 
== "/my/file" }
+                @file_server.authorized?(@request)
+            end
 
-        it "should pass the node name to the file server configuration" do
-            @configuration.expects(:authorized?).with { |key, options| 
options[:node] == "mynode" }
-            @file_server.authorized?(:find, "puppetmounts://host/my/file", 
:node => "mynode")
-        end
+            it "should pass the node name to the file server configuration" do
+                @configuration.expects(:authorized?).with { |key, options| 
options[:node] == "mynode" }
+                @request.node = "mynode"
+                @file_server.authorized?(@request)
+            end
 
-        it "should pass the IP address to the file server configuration" do
-            @configuration.expects(:authorized?).with { |key, options| 
options[:ipaddress] == "myip" }
-            @file_server.authorized?(:find, "puppetmounts://host/my/file", 
:ipaddress => "myip")
-        end
+            it "should pass the IP address to the file server configuration" do
+                @configuration.expects(:authorized?).with { |key, options| 
options[:ipaddress] == "myip" }
+                @request.ip = "myip"
+                @file_server.authorized?(@request)
+            end
 
-        it "should return false if the file server configuration denies 
authorization" do
-            @configuration.expects(:authorized?).returns(false)
-            @file_server.authorized?(:find, 
"puppetmounts://host/my/file").should be_false
-        end
+            it "should return false if the file server configuration denies 
authorization" do
+                @configuration.expects(:authorized?).returns(false)
+                @file_server.authorized?(@request)
+            end
 
-        it "should return true if the file server configuration approves 
authorization" do
-            @configuration.expects(:authorized?).returns(true)
-            @file_server.authorized?(:find, 
"puppetmounts://host/my/file").should be_true
+            it "should return true if the file server configuration approves 
authorization" do
+                @configuration.expects(:authorized?).returns(true)
+                @file_server.authorized?(@request)
+            end
         end
     end
 
@@ -135,34 +150,35 @@ describe Puppet::Indirector::FileServer do
 
         it "should use the path portion of the URI as the file name" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil)
-            @file_server.search(@uri)
+            @file_server.search(@request)
         end
 
         it "should use the FileServing configuration to convert the file name 
to a fully qualified path" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil)
-            @file_server.search(@uri)
+            @file_server.search(@request)
         end
 
         it "should pass the node name to the FileServing configuration if one 
is provided" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
"testing")
-            @file_server.search(@uri, :node => "testing")
+            @request.node = "testing"
+            @file_server.search(@request)
         end
 
         it "should return nil if no fully qualified path is found" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil).returns(nil)
-            @file_server.search(@uri).should be_nil
+            @file_server.search(@request).should be_nil
         end
 
         it "should use :path2instances from the terminus_helper to return 
instances if a module is found and the file exists" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil).returns("/my/file")
-            @file_server.expects(:path2instances).with(@uri, "/my/file", {})
-            @file_server.search(@uri)
+            @file_server.expects(:path2instances)
+            @file_server.search(@request)
         end
 
-        it "should pass any options on to :path2instances" do
+        it "should pass the request on to :path2instances" do
             @configuration.expects(:file_path).with("/my/local/file", :node => 
nil).returns("/my/file")
-            @file_server.expects(:path2instances).with(@uri, "/my/file", 
:testing => :one, :other => :two)
-            @file_server.search(@uri, :testing => :one, :other => :two)
+            @file_server.expects(:path2instances).with(@request, "/my/file")
+            @file_server.search(@request)
         end
     end
 end
diff --git a/spec/unit/indirector/module_files.rb 
b/spec/unit/indirector/module_files.rb
index f5b92e1..32dedd4 100755
--- a/spec/unit/indirector/module_files.rb
+++ b/spec/unit/indirector/module_files.rb
@@ -27,61 +27,66 @@ describe Puppet::Indirector::ModuleFiles do
   
         @uri = "puppetmounts://host/modules/my/local/file"
         @module = Puppet::Module.new("mymod", "/module/path")
+
+        @request = stub 'request', :key => @uri, :options => {}, :node => nil, 
:ip => nil, :method => :find
     end
 
     describe Puppet::Indirector::ModuleFiles, " when finding files" do
 
         it "should strip off the leading '/modules' mount name" do
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
 
         it "should not strip off leading terms that start with '/modules' but 
are longer words" do
+            @request.stubs(:key).returns 
"puppetmounts://host/modulestart/my/local/file"
             Puppet::Module.expects(:find).with('modulestart', "myenv").returns 
nil
-            @module_files.find("puppetmounts://host/modulestart/my/local/file")
+            @module_files.find(@request)
         end
 
         it "should search for a module whose name is the first term in the 
remaining file path" do
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
 
         it "should search for a file relative to the module's files directory" 
do
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             FileTest.expects(:exists?).with("/module/path/files/local/file")
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
 
         it "should return nil if the module does not exist" do
             Puppet::Module.expects(:find).with('my', "myenv").returns nil
-            @module_files.find(@uri).should be_nil
+            @module_files.find(@request).should be_nil
         end
 
         it "should return nil if the module exists but the file does not" do
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
-            @module_files.find(@uri).should be_nil
+            @module_files.find(@request).should be_nil
         end
 
         it "should return an instance of the model if a module is found and 
the file exists" do
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
             @model.expects(:new).returns(:myinstance)
-            @module_files.find(@uri).should == :myinstance
+            @module_files.find(@request).should == :myinstance
         end
 
         it "should use the node's environment to look up the module if the 
node name is provided" do
             node = stub "node", :environment => "testing"
             Puppet::Node.expects(:find).with("mynode").returns(node)
             Puppet::Module.expects(:find).with('my', "testing")
-            @module_files.find(@uri, :node => "mynode")
+
+            @request.stubs(:node).returns "mynode"
+            @module_files.find(@request)
         end
 
         it "should use the default environment setting to look up the module 
if the node name is not provided" do
             env = stub "environment", :name => "testing"
             Puppet::Node::Environment.stubs(:new).returns(env)
             Puppet::Module.expects(:find).with('my', "testing")
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
     end
 
@@ -95,23 +100,25 @@ describe Puppet::Indirector::ModuleFiles do
 
         it "should create the instance with the key used to find the instance" 
do
             @model.expects(:new).with { |key, *options| key == @uri }
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
 
         it "should create the instance with the path at which the instance was 
found" do
             @model.expects(:new).with { |key, options| options[:path] == 
"/module/path/files/local/file" }
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
 
         it "should set the provided :links setting on to the instance if one 
is provided" do
             @model.expects(:new).returns(@instance)
             @instance.expects(:links=).with(:mytest)
-            @module_files.find(@uri, :links => :mytest)
+
+            @request.options[:links] = :mytest
+            @module_files.find(@request)
         end
 
         it "should not set a :links value if no :links parameter is provided" 
do
             @model.expects(:new).returns(@instance)
-            @module_files.find(@uri)
+            @module_files.find(@request)
         end
     end
 
@@ -127,46 +134,53 @@ describe Puppet::Indirector::ModuleFiles do
         end
 
         it "should deny the :destroy method" do
-            @module_files.authorized?(:destroy, "whatever").should be_false
+            @request.expects(:method).returns :destroy
+            @module_files.authorized?(@request).should be_false
         end
 
         it "should deny the :save method" do
-            @module_files.authorized?(:save, "whatever").should be_false
+            @request.expects(:method).returns :save
+            @module_files.authorized?(@request).should be_false
         end
 
         it "should use the file server configuration to determine 
authorization" do
             @configuration.expects(:authorized?)
-            @module_files.authorized?(:find, "puppetmounts://host/my/file")
+            @module_files.authorized?(@request)
         end
 
         it "should use the path directly from the URI if it already includes 
/modules" do
+            @request.expects(:key).returns 
"puppetmounts://host/modules/my/file"
             @configuration.expects(:authorized?).with { |uri, *args| uri == 
"/modules/my/file" }
-            @module_files.authorized?(:find, 
"puppetmounts://host/modules/my/file")
+            @module_files.authorized?(@request)
         end
 
         it "should add /modules to the file path if it's not included in the 
URI" do
+            @request.expects(:key).returns "puppetmounts://host/my/file"
             @configuration.expects(:authorized?).with { |uri, *args| uri == 
"/modules/my/file" }
-            @module_files.authorized?(:find, "puppetmounts://host/my/file")
+            @module_files.authorized?(@request)
         end
 
         it "should pass the node name to the file server configuration" do
+            @request.expects(:key).returns "puppetmounts://host/my/file"
             @configuration.expects(:authorized?).with { |key, options| 
options[:node] == "mynode" }
-            @module_files.authorized?(:find, "puppetmounts://host/my/file", 
:node => "mynode")
+            @request.stubs(:node).returns "mynode"
+            @module_files.authorized?(@request)
         end
 
         it "should pass the IP address to the file server configuration" do
+            @request.expects(:ip).returns "myip"
             @configuration.expects(:authorized?).with { |key, options| 
options[:ipaddress] == "myip" }
-            @module_files.authorized?(:find, "puppetmounts://host/my/file", 
:ipaddress => "myip")
+            @module_files.authorized?(@request)
         end
 
         it "should return false if the file server configuration denies 
authorization" do
             @configuration.expects(:authorized?).returns(false)
-            @module_files.authorized?(:find, 
"puppetmounts://host/my/file").should be_false
+            @module_files.authorized?(@request).should be_false
         end
 
         it "should return true if the file server configuration approves 
authorization" do
             @configuration.expects(:authorized?).returns(true)
-            @module_files.authorized?(:find, 
"puppetmounts://host/my/file").should be_true
+            @module_files.authorized?(@request).should be_true
         end
     end
 
@@ -175,69 +189,71 @@ describe Puppet::Indirector::ModuleFiles do
         it "should strip off the leading '/modules' mount name" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
-            @module_files.search(@uri)
+            @module_files.search(@request)
         end
 
         it "should not strip off leading terms that start with '/modules' but 
are longer words" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('modulestart', "myenv").returns 
nil
-            
@module_files.search("puppetmounts://host/modulestart/my/local/file")
+            @request.stubs(:key).returns 
"puppetmounts://host/modulestart/my/local/file"
+            @module_files.search @request
         end
 
         it "should search for a module whose name is the first term in the 
remaining file path" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
-            @module_files.search(@uri)
+            @module_files.search(@request)
         end
 
         it "should search for a file relative to the module's files directory" 
do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             FileTest.expects(:exists?).with("/module/path/files/local/file")
-            @module_files.search(@uri)
+            @module_files.search(@request)
         end
 
         it "should return nil if the module does not exist" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns nil
-            @module_files.search(@uri).should be_nil
+            @module_files.search(@request).should be_nil
         end
 
         it "should return nil if the module exists but the file does not" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
-            @module_files.search(@uri).should be_nil
+            @module_files.search(@request).should be_nil
         end
 
         it "should use the node's environment to look up the module if the 
node name is provided" do
             node = stub "node", :environment => "testing"
             Puppet::Node.expects(:find).with("mynode").returns(node)
             Puppet::Module.expects(:find).with('my', "testing")
-            @module_files.search(@uri, :node => "mynode")
+            @request.stubs(:node).returns "mynode"
+            @module_files.search(@request)
         end
 
         it "should use the default environment setting to look up the module 
if the node name is not provided and the environment is not set to ''" do
             env = stub 'env', :name => "testing"
             Puppet::Node::Environment.stubs(:new).returns(env)
             Puppet::Module.expects(:find).with('my', "testing")
-            @module_files.search(@uri)
+            @module_files.search(@request)
         end
 
         it "should use :path2instances from the terminus_helper to return 
instances if a module is found and the file exists" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
-            @module_files.expects(:path2instances).with(@uri, 
"/module/path/files/local/file", {})
-            @module_files.search(@uri)
+            @module_files.expects(:path2instances).with(@request, 
"/module/path/files/local/file")
+            @module_files.search(@request)
         end
 
-        it "should pass any options on to :path2instances" do
+        it "should pass the request directly to :path2instances" do
             Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => 
"myenv"))
             Puppet::Module.expects(:find).with('my', "myenv").returns @module
             
FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
-            @module_files.expects(:path2instances).with(@uri, 
"/module/path/files/local/file", :testing => :one, :other => :two)
-            @module_files.search(@uri, :testing => :one, :other => :two)
+            @module_files.expects(:path2instances).with(@request, 
"/module/path/files/local/file")
+            @module_files.search(@request)
         end
     end
 end
-- 
1.5.3.7


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to