public
Rubygem
Description: James Turnbull's Puppet remote
Homepage: http://reductivelabs.com/trac/puppet
Clone URL: git://github.com/jamtur01/puppet.git
Fixed all of the fileserving termini so they use indirection requests.

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 <luke@madstop.com>
lak (author)
Fri Jul 18 15:51:25 -0700 2008
commit  ebb219e496682862ac98d382afe014cf1c763f2f
tree    d754de01560f8724e2cfad5ff3a53d714e37e9ba
parent  d8937acb8c9b108e61330cbac703a17b2eaba9b3
...
8
9
10
11
12
 
 
13
14
15
 
 
16
17
18
...
8
9
10
 
 
11
12
13
 
 
14
15
16
17
18
0
@@ -8,11 +8,11 @@ require 'puppet/file_serving/fileset'
0
 # Define some common methods for FileServing termini.
0
 module Puppet::FileServing::TerminusHelper
0
     # Create model instances for all files in a fileset.
0
- def path2instances(key, path, options = {})
0
- args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = options[param] if options[param]; hash }
0
+ def path2instances(request, path)
0
+ args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = request.options[param] if request.options[param]; hash }
0
         Puppet::FileServing::Fileset.new(path, args).files.collect do |file|
0
- inst = model.new(File.join(key, file), :path => path, :relative_path => file)
0
- inst.links = options[:links] if options[:links]
0
+ inst = model.new(File.join(request.key, file), :path => path, :relative_path => file)
0
+ inst.links = request.options[:links] if request.options[:links]
0
             inst
0
         end
0
     end
...
22
23
24
25
 
26
27
...
22
23
24
 
25
26
27
0
@@ -22,6 +22,6 @@ class Puppet::Indirector::DirectFileServer < Puppet::Indirector::Terminus
0
     def search(request)
0
         uri = key2uri(request.key)
0
         return nil unless FileTest.exists?(uri.path)
0
- path2instances(request.key, uri.path, request.options)
0
+ path2instances(request, uri.path)
0
     end
0
 end
...
14
15
16
17
18
 
 
19
20
 
21
22
 
23
24
25
26
27
28
29
 
 
 
 
30
31
32
33
34
35
36
 
 
37
38
 
39
40
41
...
46
47
48
49
50
 
 
51
52
 
53
54
55
...
14
15
16
 
 
17
18
19
 
20
21
 
22
23
24
25
 
 
 
 
26
27
28
29
30
31
32
33
34
 
 
35
36
37
 
38
39
40
41
...
46
47
48
 
 
49
50
51
 
52
53
54
55
0
@@ -14,28 +14,28 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
0
     include Puppet::FileServing::TerminusHelper
0
 
0
     # Is the client authorized to perform this action?
0
- def authorized?(method, key, options = {})
0
- return false unless [:find, :search].include?(method)
0
+ def authorized?(request)
0
+ return false unless [:find, :search].include?(request.method)
0
 
0
- uri = key2uri(key)
0
+ uri = key2uri(request.key)
0
 
0
- configuration.authorized?(uri.path, :node => options[:node], :ipaddress => options[:ipaddress])
0
+ configuration.authorized?(uri.path, :node => request.node, :ipaddress => request.ip)
0
     end
0
 
0
     # Find our key using the fileserver.
0
- def find(key, options = {})
0
- return nil unless path = find_path(key, options)
0
- result = model.new(key, :path => path)
0
- result.links = options[:links] if options[:links]
0
+ def find(request)
0
+ return nil unless path = find_path(request)
0
+ result = model.new(request.key, :path => path)
0
+ result.links = request.options[:links] if request.options[:links]
0
         return result
0
     end
0
 
0
     # Search for files. This returns an array rather than a single
0
     # file.
0
- def search(key, options = {})
0
- return nil unless path = find_path(key, options)
0
+ def search(request)
0
+ return nil unless path = find_path(request)
0
 
0
- path2instances(key, path, options)
0
+ path2instances(request, path)
0
     end
0
 
0
     private
0
@@ -46,10 +46,10 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
0
     end
0
 
0
     # Find our path; used by :find and :search.
0
- def find_path(key, options)
0
- uri = key2uri(key)
0
+ def find_path(request)
0
+ uri = key2uri(request.key)
0
 
0
- return nil unless path = configuration.file_path(uri.path, :node => options[:node])
0
+ return nil unless path = configuration.file_path(uri.path, :node => request.node)
0
 
0
         return path
0
     end
...
14
15
16
17
18
 
 
19
20
 
21
22
23
24
25
26
 
27
28
29
30
31
 
 
32
33
34
 
 
35
36
37
...
41
42
43
44
45
46
 
 
 
47
48
49
...
63
64
65
66
67
 
 
68
69
70
71
72
73
74
 
75
76
77
...
14
15
16
 
 
17
18
19
 
20
21
22
23
24
25
 
26
27
28
29
 
 
30
31
32
 
 
33
34
35
36
37
...
41
42
43
 
 
 
44
45
46
47
48
49
...
63
64
65
 
 
66
67
68
69
70
71
72
73
 
74
75
76
77
0
@@ -14,24 +14,24 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
0
     include Puppet::FileServing::TerminusHelper
0
 
0
     # Is the client allowed access to this key with this method?
0
- def authorized?(method, key, options = {})
0
- return false unless [:find, :search].include?(method)
0
+ def authorized?(request)
0
+ return false unless [:find, :search].include?(request.method)
0
 
0
- uri = key2uri(key)
0
+ uri = key2uri(request.key)
0
 
0
         # Make sure our file path starts with /modules, so that we authorize
0
         # against the 'modules' mount.
0
         path = uri.path =~ /^\/modules/ ? uri.path : "/modules" + uri.path
0
 
0
- configuration.authorized?(path, :node => options[:node], :ipaddress => options[:ipaddress])
0
+ configuration.authorized?(path, :node => request.node, :ipaddress => request.ip)
0
     end
0
 
0
     # Find our key in a module.
0
- def find(key, options = {})
0
- return nil unless path = find_path(key, options)
0
+ def find(request)
0
+ return nil unless path = find_path(request)
0
 
0
- result = model.new(key, :path => path)
0
- result.links = options[:links] if options[:links]
0
+ result = model.new(request.key, :path => path)
0
+ result.links = request.options[:links] if request.options[:links]
0
         return result
0
     end
0
 
0
@@ -41,9 +41,9 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
0
     end
0
 
0
     # Search for a list of files.
0
- def search(key, options = {})
0
- return nil unless path = find_path(key, options)
0
- path2instances(key, path, options)
0
+ def search(request)
0
+ return nil unless path = find_path(request)
0
+ path2instances(request, path)
0
     end
0
 
0
     private
0
@@ -63,15 +63,15 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus
0
     end
0
 
0
     # The abstracted method for turning a key into a path; used by both :find and :search.
0
- def find_path(key, options)
0
- uri = key2uri(key)
0
+ def find_path(request)
0
+ uri = key2uri(request.key)
0
 
0
         # Strip off /modules if it's there -- that's how requests get routed to this terminus.
0
         # Also, strip off the leading slash if present.
0
         module_name, relative_path = uri.path.sub(/^\/modules\b/, '').sub(%r{^/}, '').split(File::Separator, 2)
0
 
0
         # And use the environment to look up the module.
0
- return nil unless mod = find_module(module_name, options[:node])
0
+ return nil unless mod = find_module(module_name, request.node)
0
 
0
         path = File.join(mod.files, relative_path)
0
 
...
16
17
18
19
...
16
17
18
 
0
@@ -16,4 +16,3 @@ describe Puppet::FileServing::Metadata, " when finding files" do
0
         @indirection = Puppet::FileServing::Metadata.indirection
0
     end
0
 end
0
-
...
20
21
22
23
 
 
 
24
25
26
...
45
46
47
48
 
 
 
49
50
51
...
20
21
22
 
23
24
25
26
27
28
...
47
48
49
 
50
51
52
53
54
55
0
@@ -20,7 +20,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module
0
 
0
         FileTest.expects(:exists?).with(filepath).returns(true)
0
 
0
- @terminus.find("puppetmounts://host/modules/mymod/myfile").should be_instance_of(Puppet::FileServing::Content)
0
+ @request = Puppet::Indirector::Request.new(:content, :find, "puppetmounts://host/modules/mymod/myfile")
0
+
0
+ @terminus.find(@request).should be_instance_of(Puppet::FileServing::Content)
0
     end
0
 end
0
 
0
@@ -45,7 +47,9 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with FileServing::F
0
 
0
         Dir.expects(:entries).with(filepath).returns(%w{one two})
0
 
0
- result = @terminus.search("puppetmounts://host/modules/mymod/myfile", :recurse => true)
0
+ @request = Puppet::Indirector::Request.new(:content, :search, "puppetmounts://host/modules/mymod/myfile", :recurse => true)
0
+
0
+ result = @terminus.search(@request)
0
         result.should be_instance_of(Array)
0
         result.length.should == 3
0
         result.each { |r| r.should be_instance_of(Puppet::FileServing::Content) }
...
24
25
26
 
 
27
28
29
...
35
36
37
38
 
39
40
...
24
25
26
27
28
29
30
31
...
37
38
39
 
40
41
42
0
@@ -24,6 +24,8 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
0
 
0
         # Stub out the modules terminus
0
         @modules = mock 'modules terminus'
0
+
0
+ @request = Puppet::Indirector::Request.new(:indirection, :method, "puppetmounts://myhost/one/my/file")
0
     end
0
 
0
     it "should use the file server configuration to find files" do
0
@@ -35,6 +37,6 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
0
         FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
0
         @mount1.expects(:file).with("my/file", :node => nil).returns(path)
0
 
0
- @terminus.find("puppetmounts://myhost/one/my/file").should be_instance_of(@test_class)
0
+ @terminus.find(@request).should be_instance_of(@test_class)
0
     end
0
 end
...
5
6
7
8
 
9
10
11
12
13
14
 
15
16
17
...
19
20
21
22
 
23
24
25
...
33
34
35
36
 
37
38
39
40
41
42
43
 
44
45
46
47
48
49
 
50
51
52
 
 
 
 
 
 
 
 
 
 
53
54
...
5
6
7
 
8
9
10
11
12
13
 
14
15
16
17
...
19
20
21
 
22
23
24
25
...
33
34
35
 
36
37
38
39
40
41
42
 
43
44
45
46
47
48
 
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
0
@@ -5,13 +5,13 @@
0
 
0
 describe "Puppet::FileServing::Files", :shared => true do
0
     it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
0
- uri = "puppet://myhost/mymod/my/file"
0
+ uri = "puppet://myhost/fakemod/my/file"
0
         @indirection.terminus(:rest).expects(:find)
0
         @test_class.find(uri)
0
     end
0
 
0
     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
0
- uri = "puppet:///mymod/my/file"
0
+ uri = "puppet:///fakemod/my/file"
0
         Puppet.settings.stubs(:value).with(:name).returns("puppetd")
0
         Puppet.settings.stubs(:value).with(:modulepath).returns("")
0
         @indirection.terminus(:rest).expects(:find)
0
@@ -19,7 +19,7 @@ describe "Puppet::FileServing::Files", :shared => true do
0
     end
0
 
0
     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
0
- uri = "puppet:///mymod/my/file"
0
+ uri = "puppet:///fakemod/my/file"
0
         Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing"))
0
         Puppet.settings.stubs(:value).with(:name).returns("puppet")
0
         Puppet.settings.stubs(:value).with(:modulepath, "testing").returns("")
0
@@ -33,22 +33,32 @@ describe "Puppet::FileServing::Files", :shared => true do
0
     end
0
 
0
     it "should use the file_server terminus when the 'puppetmounts' URI scheme is used" do
0
- uri = "puppetmounts:///mymod/my/file"
0
+ uri = "puppetmounts:///fakemod/my/file"
0
         @indirection.terminus(:file_server).expects(:find)
0
         @indirection.terminus(:file_server).stubs(:authorized?).returns(true)
0
         @test_class.find(uri)
0
     end
0
 
0
     it "should use the file terminus when the 'file' URI scheme is used" do
0
- uri = "file:///mymod/my/file"
0
+ uri = "file:///fakemod/my/file"
0
         @indirection.terminus(:file).expects(:find)
0
         @test_class.find(uri)
0
     end
0
 
0
     it "should use the file terminus when a fully qualified path is provided" do
0
- uri = "/mymod/my/file"
0
+ uri = "/fakemod/my/file"
0
         @indirection.terminus(:file).expects(:find)
0
         @test_class.find(uri)
0
     end
0
+
0
+ it "should use the configuration to test whether the request is allowed" do
0
+ uri = "puppetmounts:///fakemod/my/file"
0
+ config = mock 'configuration'
0
+ @indirection.terminus(:file_server).stubs(:configuration).returns config
0
+
0
+ @indirection.terminus(:file_server).expects(:find)
0
+ config.expects(:authorized?).returns(true)
0
+ @test_class.find(uri, :node => "foo", :ip => "bar")
0
+ end
0
 end
0
 
...
14
15
16
 
 
17
18
19
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
 
69
70
71
72
73
74
75
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
78
...
14
15
16
17
18
19
20
21
22
23
 
24
25
26
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
33
 
 
 
 
 
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -14,65 +14,63 @@ describe Puppet::FileServing::TerminusHelper do
0
 
0
         @model = mock 'model'
0
         @helper.stubs(:model).returns(@model)
0
+
0
+ @request = stub 'request', :key => "url", :options => {}
0
     end
0
 
0
     it "should use a fileset to find paths" do
0
         fileset = mock 'fileset', :files => []
0
         Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset)
0
- @helper.path2instances("url", "/my/file")
0
+ @helper.path2instances(@request, "/my/file")
0
     end
0
 
0
     it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do
0
         fileset = mock 'fileset', :files => []
0
         Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset)
0
- @helper.path2instances("url", "/my/file", :links => :a, :ignore => :b, :recurse => :c)
0
- end
0
-end
0
-
0
-
0
-describe Puppet::FileServing::TerminusHelper, " when creating instances" do
0
- before do
0
- @helper = Object.new
0
- @helper.extend(Puppet::FileServing::TerminusHelper)
0
-
0
- @model = mock 'model'
0
- @helper.stubs(:model).returns(@model)
0
-
0
- @key = "puppet://host/mount/dir"
0
-
0
- @fileset = mock 'fileset', :files => %w{one two}
0
- Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
0
- end
0
-
0
- it "should create an instance of the model for each path returned by the fileset" do
0
- @model.expects(:new).returns(:one)
0
- @model.expects(:new).returns(:two)
0
- @helper.path2instances(@key, "/my/file").length.should == 2
0
- end
0
-
0
- it "should set each instance's key to be the original key plus the file-specific path" do
0
- @model.expects(:new).with { |key, options| key == @key + "/one" }.returns(:one)
0
- @model.expects(:new).with { |key, options| key == @key + "/two" }.returns(:two)
0
- @helper.path2instances(@key, "/my/file")
0
- end
0
-
0
- it "should set each returned instance's path to the original path" do
0
- @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one)
0
- @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two)
0
- @helper.path2instances(@key, "/my/file")
0
- end
0
-
0
- it "should set each returned instance's relative path to the file-specific path" do
0
- @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one)
0
- @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two)
0
- @helper.path2instances(@key, "/my/file")
0
+ @request.stubs(:options).returns(:links => :a, :ignore => :b, :recurse => :c)
0
+ @helper.path2instances(@request, "/my/file")
0
     end
0
 
0
- it "should set the links value on each instance if one is provided" do
0
- one = mock 'one', :links= => :manage
0
- two = mock 'two', :links= => :manage
0
- @model.expects(:new).returns(one)
0
- @model.expects(:new).returns(two)
0
- @helper.path2instances(@key, "/my/file", :links => :manage)
0
+ describe "when creating instances" do
0
+ before do
0
+ @request.stubs(:key).returns "puppet://host/mount/dir"
0
+
0
+ @fileset = mock 'fileset', :files => %w{one two}
0
+ Puppet::FileServing::Fileset.expects(:new).returns(@fileset)
0
+ end
0
+
0
+ it "should create an instance of the model for each path returned by the fileset" do
0
+ @model.expects(:new).returns(:one)
0
+ @model.expects(:new).returns(:two)
0
+ @helper.path2instances(@request, "/my/file").length.should == 2
0
+ end
0
+
0
+ it "should set each instance's key to be the original key plus the file-specific path" do
0
+ @model.expects(:new).with { |key, options| key == @request.key + "/one" }.returns(:one)
0
+ @model.expects(:new).with { |key, options| key == @request.key + "/two" }.returns(:two)
0
+ @helper.path2instances(@request, "/my/file")
0
+ end
0
+
0
+ it "should set each returned instance's path to the original path" do
0
+ @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one)
0
+ @model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two)
0
+ @helper.path2instances(@request, "/my/file")
0
+ end
0
+
0
+ it "should set each returned instance's relative path to the file-specific path" do
0
+ @model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one)
0
+ @model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two)
0
+ @helper.path2instances(@request, "/my/file")
0
+ end
0
+
0
+ it "should set the links value on each instance if one is provided" do
0
+ one = mock 'one', :links= => :manage
0
+ two = mock 'two', :links= => :manage
0
+ @model.expects(:new).returns(one)
0
+ @model.expects(:new).returns(two)
0
+
0
+ @request.options[:links] = :manage
0
+ @helper.path2instances(@request, "/my/file")
0
+ end
0
     end
0
 end
...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
91
92
93
94
 
95
96
97
...
69
70
71
 
72
73
74
75
76
 
 
 
 
 
 
77
78
79
80
81
82
 
83
84
 
 
 
85
86
87
88
0
@@ -69,29 +69,20 @@ describe Puppet::Indirector::DirectFileServer do
0
     end
0
 
0
     describe Puppet::Indirector::DirectFileServer, "when searching for multiple files" do
0
-
0
         it "should return nil if the file does not exist" do
0
             FileTest.expects(:exists?).with("/my/local").returns false
0
             @server.find(@request).should be_nil
0
         end
0
 
0
- it "should pass the original key to :path2instances" do
0
- FileTest.expects(:exists?).with("/my/local").returns true
0
- @server.expects(:path2instances).with { |uri, path, options| uri == @uri }
0
- @server.search(@request)
0
- end
0
-
0
         it "should use :path2instances from the terminus_helper to return instances if the file exists" do
0
             FileTest.expects(:exists?).with("/my/local").returns true
0
             @server.expects(:path2instances)
0
             @server.search(@request)
0
         end
0
 
0
- it "should pass any options on to :path2instances" do
0
+ it "should pass the original request to :path2instances" do
0
             FileTest.expects(:exists?).with("/my/local").returns true
0
- @server.expects(:path2instances).with { |uri, path, options| options == {:testing => :one, :other => :two}}
0
-
0
- @request.stubs(:options).returns(:testing => :one, :other => :two)
0
+ @server.expects(:path2instances).with(@request, "/my/local")
0
             @server.search(@request)
0
         end
0
     end
...
23
24
25
 
 
26
27
28
29
30
 
31
32
33
...
35
36
37
38
 
39
40
...
23
24
25
26
27
28
29
30
31
 
32
33
34
35
...
37
38
39
 
40
41
42
0
@@ -23,11 +23,13 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do
0
         @finder.stubs(:environment).returns(nil)
0
         @module = Puppet::Module.new("mymod", "/path/to")
0
         @finder.stubs(:find_module).returns(@module)
0
+
0
+ @request = Puppet::Indirector::Request.new(:metadata, :find, "puppetmounts://hostname/modules/mymod/my/file")
0
     end
0
 
0
     it "should return nil if the file is not found" do
0
         FileTest.expects(:exists?).with("/path/to/files/my/file").returns false
0
- @finder.find("puppetmounts://hostname/modules/mymod/my/file").should be_nil
0
+ @finder.find(@request).should be_nil
0
     end
0
 
0
     it "should retrieve the instance's attributes if the file is found" do
0
@@ -35,6 +37,6 @@ describe Puppet::Indirector::FileMetadata::Modules, " when finding metadata" do
0
         instance = mock 'metadta'
0
         Puppet::FileServing::Metadata.expects(:new).returns instance
0
         instance.expects :collect_attributes
0
- @finder.find("puppetmounts://hostname/modules/mymod/my/file")
0
+ @finder.find(@request)
0
     end
0
 end
...
27
28
29
 
 
30
31
32
33
34
35
36
 
37
38
39
40
41
 
42
43
44
45
46
 
 
47
48
49
50
51
 
52
53
54
55
56
57
 
58
59
60
...
66
67
68
69
 
70
71
72
73
74
 
75
76
77
78
79
80
 
 
81
82
83
84
85
 
86
87
88
...
93
94
95
96
 
 
97
98
99
100
101
 
 
 
 
 
 
 
 
 
102
103
104
105
106
 
 
 
 
107
108
109
110
111
 
 
 
 
112
113
114
115
116
 
 
 
 
 
117
118
119
120
121
 
 
 
 
 
122
123
124
125
126
 
 
 
 
127
128
129
130
 
 
 
 
131
132
133
...
135
136
137
138
 
139
140
141
142
143
 
144
145
146
147
148
 
 
149
150
151
152
153
 
154
155
156
157
158
159
 
 
160
161
162
 
163
164
165
 
 
166
167
168
...
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
41
42
 
43
44
45
46
47
 
48
49
50
51
52
53
 
54
55
56
57
58
59
 
60
61
62
63
...
69
70
71
 
72
73
74
75
76
 
77
78
79
80
81
82
 
83
84
85
86
87
88
 
89
90
91
92
...
97
98
99
 
100
101
102
103
104
 
 
105
106
107
108
109
110
111
112
113
114
 
 
 
 
115
116
117
118
119
 
 
 
 
120
121
122
123
124
 
 
 
 
125
126
127
128
129
130
 
 
 
 
131
132
133
134
135
136
 
 
 
 
137
138
139
140
141
 
 
 
142
143
144
145
146
147
148
...
150
151
152
 
153
154
155
156
157
 
158
159
160
161
162
 
163
164
165
166
167
168
 
169
170
171
172
173
 
 
174
175
176
177
 
178
179
 
 
180
181
182
183
184
0
@@ -27,34 +27,37 @@ describe Puppet::Indirector::FileServer do
0
         @uri = "puppetmounts://host/my/local/file"
0
         @configuration = mock 'configuration'
0
         Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
0
+
0
+ @request = Puppet::Indirector::Request.new(:myind, :mymethod, @uri)
0
     end
0
 
0
     describe Puppet::Indirector::FileServer, " when finding files" do
0
 
0
         it "should use the path portion of the URI as the file name" do
0
             @configuration.expects(:file_path).with("/my/local/file", :node => nil)
0
- @file_server.find(@uri)
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should use the FileServing configuration to convert the file name to a fully qualified path" do
0
             @configuration.expects(:file_path).with("/my/local/file", :node => nil)
0
- @file_server.find(@uri)
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should pass the node name to the FileServing configuration if one is provided" do
0
             @configuration.expects(:file_path).with("/my/local/file", :node => "testing")
0
- @file_server.find(@uri, :node => "testing")
0
+ @request.node = "testing"
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should return nil if no fully qualified path is found" do
0
             @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
0
- @file_server.find(@uri).should be_nil
0
+ @file_server.find(@request).should be_nil
0
         end
0
 
0
         it "should return an instance of the model created with the full path if a file is found" do
0
             @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
0
             @model.expects(:new).returns(:myinstance)
0
- @file_server.find(@uri).should == :myinstance
0
+ @file_server.find(@request).should == :myinstance
0
         end
0
     end
0
 
0
@@ -66,23 +69,24 @@ describe Puppet::Indirector::FileServer do
0
 
0
         it "should create the instance with the key used to find the instance" do
0
             @model.expects(:new).with { |key, *options| key == @uri }
0
- @file_server.find(@uri)
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should create the instance with the path at which the instance was found" do
0
             @model.expects(:new).with { |key, options| options[:path] == "/some/file" }
0
- @file_server.find(@uri)
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should set the provided :links setting on to the instance if one is provided" do
0
             @model.expects(:new).returns(@instance)
0
             @instance.expects(:links=).with(:mytest)
0
- @file_server.find(@uri, :links => :mytest)
0
+ @request.options[:links] = :mytest
0
+ @file_server.find(@request)
0
         end
0
 
0
         it "should not set a :links value if no :links parameter is provided" do
0
             @model.expects(:new).returns(@instance)
0
- @file_server.find(@uri)
0
+ @file_server.find(@request)
0
         end
0
     end
0
 
0
@@ -93,41 +97,52 @@ describe Puppet::Indirector::FileServer do
0
         end
0
 
0
         it "should deny the :destroy method" do
0
- @file_server.authorized?(:destroy, "whatever").should be_false
0
+ @request.method = :destroy
0
+ @file_server.authorized?(@request).should be_false
0
         end
0
 
0
         it "should deny the :save method" do
0
- @file_server.authorized?(:save, "whatever").should be_false
0
- end
0
+ @request.method = :save
0
+ @file_server.authorized?(@request).should be_false
0
+ end
0
+
0
+ describe "and finding file information" do
0
+ before do
0
+ @request.key = "pupp