~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to spec/unit/file_serving/indirection_hooks.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
        @object = Object.new
13
13
        @object.extend(Puppet::FileServing::IndirectionHooks)
14
14
 
15
 
        @request = stub 'request', :key => "http://myhost/blah", :options => {:node => "whatever"}
 
15
        @request = stub 'request', :key => "mymod/myfile", :options => {:node => "whatever"}, :server => nil, :protocol => nil
16
16
    end
17
17
 
18
18
    describe "when being used to select termini" do
19
 
        it "should escape the key before parsing" do
20
 
            uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something"
21
 
            URI.expects(:escape).with("http://myhost/blah").returns("escaped_blah")
22
 
            URI.expects(:parse).with("escaped_blah").returns(uri)
23
 
            @object.select_terminus(@request)
24
 
        end
25
 
 
26
 
        it "should use the URI class to parse the key" do
27
 
            uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something"
28
 
            URI.expects(:parse).with("http://myhost/blah").returns(uri)
29
 
            @object.select_terminus @request
30
 
        end
31
 
 
32
 
        it "should choose :rest when the protocol is 'puppet'" do
33
 
            @request.stubs(:key).returns "puppet://host/module/file"
34
 
            @object.select_terminus(@request).should == :rest
35
 
        end
36
 
 
37
 
        it "should choose :file_server when the protocol is 'puppetmounts' and the mount name is not 'modules'" do
38
 
            modules = mock 'modules'
39
 
            @object.stubs(:terminus).with(:modules).returns(modules)
40
 
            modules.stubs(:find_module).returns(nil)
41
 
 
42
 
            @request.stubs(:key).returns "puppetmounts://host/notmodules/file"
43
 
 
44
 
            @object.select_terminus(@request).should == :file_server
45
 
        end
46
 
 
47
 
        it "should choose :file_server when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do
48
 
            modules = mock 'modules'
49
 
            @object.stubs(:terminus).with(:modules).returns(modules)
50
 
            modules.stubs(:find_module).returns(nil)
51
 
 
52
 
            Puppet.settings.expects(:value).with(:name).returns("puppet")
53
 
            @request.stubs(:key).returns "puppet:///notmodules/file"
54
 
            @object.select_terminus(@request).should == :file_server
55
 
        end
56
 
 
57
 
        it "should choose :modules if it would normally choose :file_server but the mount name is 'modules'" do
58
 
            @request.stubs(:key).returns "puppetmounts://host/modules/mymod/file"
59
 
            @object.select_terminus(@request).should == :modules
60
 
        end
61
 
 
62
 
        it "should choose :modules if it would normally choose :file_server but a module exists with the mount name" do
63
 
            modules = mock 'modules'
64
 
 
65
 
            @object.expects(:terminus).with(:modules).returns(modules)
66
 
            modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:thing)
67
 
 
68
 
            @request.stubs(:key).returns "puppetmounts://host/mymod/file"
69
 
            @object.select_terminus(@request).should == :modules
70
 
        end
71
 
 
72
 
        it "should choose :rest when no server name is provided and the process name is not 'puppet'" do
73
 
            Puppet.settings.expects(:value).with(:name).returns("puppetd")
74
 
            @request.stubs(:key).returns "puppet:///module/file"
75
 
            @object.select_terminus(@request).should == :rest
76
 
        end
77
 
 
78
 
        it "should choose :file when the protocol is 'file'" do
79
 
            @request.stubs(:key).returns "file://host/module/file"
80
 
            @object.select_terminus(@request).should == :file
81
 
        end
82
 
 
83
 
        it "should choose :file when the URI is a normal path name" do
84
 
            @request.stubs(:key).returns "/module/file"
85
 
            @object.select_terminus(@request).should == :file
86
 
        end
87
 
 
88
 
        # This is so that we only choose modules over mounts, not file
89
 
        it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do
90
 
            @request.stubs(:key).returns "/module/file"
91
 
            @object.select_terminus(@request).should == :file
92
 
        end
93
 
 
94
 
        it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do
95
 
            @request.stubs(:key).returns "http:///module/file"
 
19
        it "should return :file if the request key is fully qualified" do
 
20
            @request.expects(:key).returns "#{File::SEPARATOR}foo"
 
21
            @object.select_terminus(@request).should == :file
 
22
        end
 
23
 
 
24
        it "should return :file if the URI protocol is set to 'file'" do
 
25
            @request.expects(:protocol).returns "file"
 
26
            @object.select_terminus(@request).should == :file
 
27
        end
 
28
 
 
29
        it "should fail when a protocol other than :puppet or :file is used" do
 
30
            @request.stubs(:protocol).returns "http"
96
31
            proc { @object.select_terminus(@request) }.should raise_error(ArgumentError)
97
32
        end
98
 
    end
99
 
 
100
 
    describe "when looking for a module whose name matches the mount name" do
101
 
        before do
102
 
            @modules = mock 'modules'
103
 
            @object.stubs(:terminus).with(:modules).returns(@modules)
104
 
 
105
 
            @request.stubs(:key).returns "puppetmounts://host/mymod/file"
106
 
        end
107
 
 
108
 
        it "should use the modules terminus to look up the module" do
109
 
            @modules.expects(:find_module).with("mymod", @request.options[:node])
110
 
            @object.select_terminus @request
111
 
        end
112
 
 
113
 
        it "should pass the node name to the modules terminus" do
114
 
            @modules.expects(:find_module).with("mymod", @request.options[:node])
115
 
            @object.select_terminus @request
116
 
        end
117
 
 
118
 
        it "should log a deprecation warning if a module is found" do
119
 
            @modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:something)
120
 
            Puppet.expects(:warning)
121
 
            @object.select_terminus @request
 
33
 
 
34
        describe "and the protocol is 'puppet'" do
 
35
            before do
 
36
                @request.stubs(:protocol).returns "puppet"
 
37
            end
 
38
 
 
39
            it "should choose :rest when a server is specified" do
 
40
                @request.stubs(:protocol).returns "puppet"
 
41
                @request.expects(:server).returns "foo"
 
42
                @object.select_terminus(@request).should == :rest
 
43
            end
 
44
 
 
45
            # This is so a given file location works when bootstrapping with no server.
 
46
            it "should choose :rest when the Settings name isn't 'puppet'" do
 
47
                @request.stubs(:protocol).returns "puppet"
 
48
                @request.stubs(:server).returns "foo"
 
49
                Puppet.settings.stubs(:value).with(:name).returns "foo"
 
50
                @object.select_terminus(@request).should == :rest
 
51
            end
 
52
 
 
53
            it "should choose :file_server when the settings name is 'puppet' and no server is specified" do
 
54
                modules = mock 'modules'
 
55
 
 
56
                @request.expects(:protocol).returns "puppet"
 
57
                @request.expects(:server).returns nil
 
58
                Puppet.settings.expects(:value).with(:name).returns "puppet"
 
59
                @object.select_terminus(@request).should == :file_server
 
60
            end
122
61
        end
123
62
    end
124
63
end