|
1 | 1 | #!/usr/bin/env rspec
|
2 |
| -shared_examples_for "Puppet::FileServing::Files" do |
3 |
| - it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do |
4 |
| - uri = "puppet://myhost/fakemod/my/file" |
5 |
| - |
6 |
| - # It appears that the mocking somehow interferes with the caching subsystem. |
7 |
| - # This mock somehow causes another terminus to get generated. |
8 |
| - @indirection.terminus(:rest).expects(:find) |
9 |
| - @indirection.find(uri) |
10 |
| - end |
11 | 2 |
|
12 |
| - 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' or 'apply'" do |
13 |
| - uri = "puppet:///fakemod/my/file" |
14 |
| - Puppet.settings.stubs(:value).returns "foo" |
15 |
| - Puppet.settings.stubs(:value).with(:name).returns("puppetd") |
16 |
| - Puppet.settings.stubs(:value).with(:modulepath).returns("") |
17 |
| - @indirection.terminus(:rest).expects(:find) |
18 |
| - @indirection.find(uri) |
19 |
| - end |
| 3 | +shared_examples_for "Puppet::FileServing::Files" do |indirection| |
| 4 | + %w[find search].each do |method| |
| 5 | + let(:request) { Puppet::Indirector::Request.new(indirection, method, 'foo') } |
20 | 6 |
|
21 |
| - 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 |
22 |
| - uri = "puppet:///fakemod/my/file" |
23 |
| - Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => [])) |
24 |
| - Puppet.settings.stubs(:value).returns "" |
25 |
| - Puppet.settings.stubs(:value).with(:name).returns("puppet") |
26 |
| - Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever") |
27 |
| - @indirection.terminus(:file_server).expects(:find) |
28 |
| - @indirection.terminus(:file_server).stubs(:authorized?).returns(true) |
29 |
| - @indirection.find(uri) |
30 |
| - end |
| 7 | + before :each do |
| 8 | + # Stub this so we can set the :name setting |
| 9 | + Puppet::Util::Settings::ReadOnly.stubs(:include?) |
| 10 | + end |
31 | 11 |
|
32 |
| - it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'apply'" do |
33 |
| - uri = "puppet:///fakemod/my/file" |
34 |
| - Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => [])) |
35 |
| - Puppet.settings.stubs(:value).returns "" |
36 |
| - Puppet.settings.stubs(:value).with(:name).returns("apply") |
37 |
| - Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever") |
38 |
| - @indirection.terminus(:file_server).expects(:find) |
39 |
| - @indirection.terminus(:file_server).stubs(:authorized?).returns(true) |
40 |
| - @indirection.find(uri) |
41 |
| - end |
| 12 | + describe "##{method}" do |
| 13 | + it "should proxy to file terminus if the path is absolute" do |
| 14 | + request.key = make_absolute('/tmp/foo') |
42 | 15 |
|
43 |
| - it "should use the file terminus when the 'file' URI scheme is used" do |
44 |
| - uri = Puppet::Util.path_to_uri(File.expand_path('/fakemod/my/other file')) |
45 |
| - uri.scheme.should == 'file' |
46 |
| - @indirection.terminus(:file).expects(:find) |
47 |
| - @indirection.find(uri.to_s) |
48 |
| - end |
| 16 | + described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request) |
49 | 17 |
|
50 |
| - it "should use the file terminus when a fully qualified path is provided" do |
51 |
| - uri = File.expand_path("/fakemod/my/file") |
52 |
| - @indirection.terminus(:file).expects(:find) |
53 |
| - @indirection.find(uri) |
54 |
| - end |
| 18 | + subject.send(method, request) |
| 19 | + end |
| 20 | + |
| 21 | + it "should proxy to file terminus if the protocol is file" do |
| 22 | + request.protocol = 'file' |
| 23 | + |
| 24 | + described_class.indirection.terminus(:file).class.any_instance.expects(method).with(request) |
| 25 | + |
| 26 | + subject.send(method, request) |
| 27 | + end |
| 28 | + |
| 29 | + describe "when the protocol is puppet" do |
| 30 | + before :each do |
| 31 | + request.protocol = 'puppet' |
| 32 | + end |
| 33 | + |
| 34 | + describe "and a server is specified" do |
| 35 | + before :each do |
| 36 | + request.server = 'puppet_server' |
| 37 | + end |
| 38 | + |
| 39 | + it "should proxy to rest terminus if we're 'apply'" do |
| 40 | + Puppet[:name] = 'apply' |
| 41 | + |
| 42 | + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request) |
| 43 | + |
| 44 | + subject.send(method, request) |
| 45 | + end |
| 46 | + |
| 47 | + it "should proxy to rest terminus if we aren't 'apply'" do |
| 48 | + Puppet[:name] = 'not_apply' |
| 49 | + |
| 50 | + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request) |
| 51 | + |
| 52 | + subject.send(method, request) |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + describe "and no server is specified" do |
| 57 | + before :each do |
| 58 | + request.server = nil |
| 59 | + end |
| 60 | + |
| 61 | + it "should proxy to file_server if we're 'apply'" do |
| 62 | + Puppet[:name] = 'apply' |
| 63 | + |
| 64 | + described_class.indirection.terminus(:file_server).class.any_instance.expects(method).with(request) |
| 65 | + |
| 66 | + subject.send(method, request) |
| 67 | + end |
| 68 | + |
| 69 | + it "should proxy to rest if we're not 'apply'" do |
| 70 | + Puppet[:name] = 'not_apply' |
55 | 71 |
|
56 |
| - it "should use the configuration to test whether the request is allowed" do |
57 |
| - uri = "fakemod/my/file" |
58 |
| - mount = mock 'mount' |
59 |
| - config = stub 'configuration', :split_path => [mount, "eh"] |
60 |
| - @indirection.terminus(:file_server).stubs(:configuration).returns config |
| 72 | + described_class.indirection.terminus(:rest).class.any_instance.expects(method).with(request) |
61 | 73 |
|
62 |
| - @indirection.terminus(:file_server).expects(:find) |
63 |
| - mount.expects(:allowed?).returns(true) |
64 |
| - @indirection.find(uri, :node => "foo", :ip => "bar") |
| 74 | + subject.send(method, request) |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | + end |
65 | 79 | end
|
66 | 80 | end
|
0 commit comments