~ubuntu-branches/ubuntu/precise/puppet/precise-security

« back to all changes in this revision

Viewing changes to .pc/2.7.17-Puppet-July-2012-CVE-fixes.patch/spec/unit/file_serving/configuration_spec.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-10 07:58:03 UTC
  • Revision ID: package-import@ubuntu.com-20120710075803-og8iubg2a90dtk7f
Tags: 2.7.11-1ubuntu2.1
* SECURITY UPDATE: Multiple July 2012 security issues
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch: upstream
    patch to fix multiple security issues.
  - CVE-2012-3864: arbitrary file read on master from authenticated
    clients
  - CVE-2012-3865: arbitrary file delete or denial of service on master
    from authenticated clients
  - CVE-2012-3866: last_run_report.yaml report file is world readable and
    leads to arbitrary file read on master by an agent
  - CVE-2012-3867: insufficient input validation for agent cert hostnames

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env rspec
 
2
require 'spec_helper'
 
3
 
 
4
require 'puppet/file_serving/configuration'
 
5
 
 
6
describe Puppet::FileServing::Configuration do
 
7
  include PuppetSpec::Files
 
8
 
 
9
  before :each do
 
10
    @path = make_absolute("/path/to/configuration/file.conf")
 
11
    Puppet.settings.stubs(:value).with(:trace).returns(false)
 
12
    Puppet.settings.stubs(:value).with(:fileserverconfig).returns(@path)
 
13
  end
 
14
 
 
15
  after :each do
 
16
    Puppet::FileServing::Configuration.instance_variable_set(:@configuration, nil)
 
17
  end
 
18
 
 
19
  it "should make :new a private method" do
 
20
    proc { Puppet::FileServing::Configuration.new }.should raise_error
 
21
  end
 
22
 
 
23
  it "should return the same configuration each time 'configuration' is called" do
 
24
    Puppet::FileServing::Configuration.configuration.should equal(Puppet::FileServing::Configuration.configuration)
 
25
  end
 
26
 
 
27
  describe "when initializing" do
 
28
 
 
29
    it "should work without a configuration file" do
 
30
      FileTest.stubs(:exists?).with(@path).returns(false)
 
31
      proc { Puppet::FileServing::Configuration.configuration }.should_not raise_error
 
32
    end
 
33
 
 
34
    it "should parse the configuration file if present" do
 
35
      FileTest.stubs(:exists?).with(@path).returns(true)
 
36
      @parser = mock 'parser'
 
37
      @parser.expects(:parse).returns({})
 
38
      Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
 
39
      Puppet::FileServing::Configuration.configuration
 
40
    end
 
41
 
 
42
    it "should determine the path to the configuration file from the Puppet settings" do
 
43
      Puppet::FileServing::Configuration.configuration
 
44
    end
 
45
  end
 
46
 
 
47
  describe "when parsing the configuration file" do
 
48
 
 
49
    before do
 
50
      FileTest.stubs(:exists?).with(@path).returns(true)
 
51
      @parser = mock 'parser'
 
52
      Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
 
53
    end
 
54
 
 
55
    it "should set the mount list to the results of parsing" do
 
56
      @parser.expects(:parse).returns("one" => mock("mount"))
 
57
      config = Puppet::FileServing::Configuration.configuration
 
58
      config.mounted?("one").should be_true
 
59
    end
 
60
 
 
61
    it "should not raise exceptions" do
 
62
      @parser.expects(:parse).raises(ArgumentError)
 
63
      proc { Puppet::FileServing::Configuration.configuration }.should_not raise_error
 
64
    end
 
65
 
 
66
    it "should replace the existing mount list with the results of reparsing" do
 
67
      @parser.expects(:parse).returns("one" => mock("mount"))
 
68
      config = Puppet::FileServing::Configuration.configuration
 
69
      config.mounted?("one").should be_true
 
70
      # Now parse again
 
71
      @parser.expects(:parse).returns("two" => mock('other'))
 
72
      config.send(:readconfig, false)
 
73
      config.mounted?("one").should be_false
 
74
      config.mounted?("two").should be_true
 
75
    end
 
76
 
 
77
    it "should not replace the mount list until the file is entirely parsed successfully" do
 
78
      @parser.expects(:parse).returns("one" => mock("mount"))
 
79
      @parser.expects(:parse).raises(ArgumentError)
 
80
      config = Puppet::FileServing::Configuration.configuration
 
81
      # Now parse again, so the exception gets thrown
 
82
      config.send(:readconfig, false)
 
83
      config.mounted?("one").should be_true
 
84
    end
 
85
 
 
86
    it "should add modules and plugins mounts even if the file does not exist" do
 
87
      FileTest.expects(:exists?).returns false # the file doesn't exist
 
88
      config = Puppet::FileServing::Configuration.configuration
 
89
      config.mounted?("modules").should be_true
 
90
      config.mounted?("plugins").should be_true
 
91
    end
 
92
 
 
93
    it "should allow all access to modules and plugins if no fileserver.conf exists" do
 
94
      FileTest.expects(:exists?).returns false # the file doesn't exist
 
95
      modules = stub 'modules', :empty? => true
 
96
      Puppet::FileServing::Mount::Modules.stubs(:new).returns(modules)
 
97
      modules.expects(:allow).with('*')
 
98
 
 
99
      plugins = stub 'plugins', :empty? => true
 
100
      Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
 
101
      plugins.expects(:allow).with('*')
 
102
 
 
103
      Puppet::FileServing::Configuration.configuration
 
104
    end
 
105
 
 
106
    it "should not allow access from all to modules and plugins if the fileserver.conf provided some rules" do
 
107
      FileTest.expects(:exists?).returns false # the file doesn't exist
 
108
 
 
109
      modules = stub 'modules', :empty? => false
 
110
      Puppet::FileServing::Mount::Modules.stubs(:new).returns(modules)
 
111
      modules.expects(:allow).with('*').never
 
112
 
 
113
      plugins = stub 'plugins', :empty? => false
 
114
      Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
 
115
      plugins.expects(:allow).with('*').never
 
116
 
 
117
      Puppet::FileServing::Configuration.configuration
 
118
    end
 
119
 
 
120
    it "should add modules and plugins mounts even if they are not returned by the parser" do
 
121
      @parser.expects(:parse).returns("one" => mock("mount"))
 
122
      FileTest.expects(:exists?).returns true # the file doesn't exist
 
123
      config = Puppet::FileServing::Configuration.configuration
 
124
      config.mounted?("modules").should be_true
 
125
      config.mounted?("plugins").should be_true
 
126
    end
 
127
  end
 
128
 
 
129
  describe "when finding the specified mount" do
 
130
    it "should choose the named mount if one exists" do
 
131
      config = Puppet::FileServing::Configuration.configuration
 
132
      config.expects(:mounts).returns("one" => "foo")
 
133
      config.find_mount("one", mock('env')).should == "foo"
 
134
    end
 
135
 
 
136
    it "should use the provided environment to find a matching module if the named module cannot be found" do
 
137
      config = Puppet::FileServing::Configuration.configuration
 
138
 
 
139
      mod = mock 'module'
 
140
      env = mock 'environment'
 
141
      env.expects(:module).with("foo").returns mod
 
142
      mount = mock 'mount'
 
143
 
 
144
      config.stubs(:mounts).returns("modules" => mount)
 
145
      Puppet::Util::Warnings.expects(:notice_once)
 
146
      config.find_mount("foo", env).should equal(mount)
 
147
    end
 
148
 
 
149
    it "should return nil if there is no such named mount and no module with the same name exists" do
 
150
      config = Puppet::FileServing::Configuration.configuration
 
151
 
 
152
      env = mock 'environment'
 
153
      env.expects(:module).with("foo").returns nil
 
154
 
 
155
      mount = mock 'mount'
 
156
      config.stubs(:mounts).returns("modules" => mount)
 
157
      config.find_mount("foo", env).should be_nil
 
158
    end
 
159
  end
 
160
 
 
161
  describe "when finding the mount name and relative path in a request key" do
 
162
    before do
 
163
      @config = Puppet::FileServing::Configuration.configuration
 
164
      @config.stubs(:find_mount)
 
165
 
 
166
      @request = stub 'request', :key => "foo/bar/baz", :options => {}, :node => nil, :environment => mock("env")
 
167
    end
 
168
 
 
169
    it "should reread the configuration" do
 
170
      @config.expects(:readconfig)
 
171
 
 
172
      @config.split_path(@request)
 
173
    end
 
174
 
 
175
    it "should treat the first field of the URI path as the mount name" do
 
176
      @config.expects(:find_mount).with { |name, node| name == "foo" }
 
177
 
 
178
      @config.split_path(@request)
 
179
    end
 
180
 
 
181
    it "should fail if the mount name is not alpha-numeric" do
 
182
      @request.expects(:key).returns "foo&bar/asdf"
 
183
 
 
184
      lambda { @config.split_path(@request) }.should raise_error(ArgumentError)
 
185
    end
 
186
 
 
187
    it "should support dashes in the mount name" do
 
188
      @request.expects(:key).returns "foo-bar/asdf"
 
189
 
 
190
      lambda { @config.split_path(@request) }.should_not raise_error(ArgumentError)
 
191
    end
 
192
 
 
193
    it "should use the mount name and environment to find the mount" do
 
194
      @config.expects(:find_mount).with { |name, env| name == "foo" and env == @request.environment }
 
195
      @request.stubs(:node).returns("mynode")
 
196
 
 
197
      @config.split_path(@request)
 
198
    end
 
199
 
 
200
    it "should return nil if the mount cannot be found" do
 
201
      @config.expects(:find_mount).returns nil
 
202
 
 
203
      @config.split_path(@request).should be_nil
 
204
    end
 
205
 
 
206
    it "should return the mount and the relative path if the mount is found" do
 
207
      mount = stub 'mount', :name => "foo"
 
208
      @config.expects(:find_mount).returns mount
 
209
 
 
210
      @config.split_path(@request).should == [mount, "bar/baz"]
 
211
    end
 
212
 
 
213
    it "should remove any double slashes" do
 
214
      @request.stubs(:key).returns "foo/bar//baz"
 
215
      mount = stub 'mount', :name => "foo"
 
216
      @config.expects(:find_mount).returns mount
 
217
 
 
218
      @config.split_path(@request).should == [mount, "bar/baz"]
 
219
    end
 
220
 
 
221
    it "should return the relative path as nil if it is an empty string" do
 
222
      @request.expects(:key).returns "foo"
 
223
      mount = stub 'mount', :name => "foo"
 
224
      @config.expects(:find_mount).returns mount
 
225
 
 
226
      @config.split_path(@request).should == [mount, nil]
 
227
    end
 
228
 
 
229
    it "should add 'modules/' to the relative path if the modules mount is used but not specified, for backward compatibility" do
 
230
      @request.expects(:key).returns "foo/bar"
 
231
      mount = stub 'mount', :name => "modules"
 
232
      @config.expects(:find_mount).returns mount
 
233
 
 
234
      @config.split_path(@request).should == [mount, "foo/bar"]
 
235
    end
 
236
  end
 
237
end