|
170 | 170 | end
|
171 | 171 | end
|
172 | 172 |
|
173 |
| - describe "when finding the mount name and relative path in a request key" do |
174 |
| - before do |
175 |
| - @config = Puppet::FileServing::Configuration.create |
176 |
| - @config.stubs(:find_mount) |
| 173 | + describe "#split_path" do |
| 174 | + let(:config) { Puppet::FileServing::Configuration.create } |
| 175 | + let(:request) { stub 'request', :key => "foo/bar/baz", :options => {}, :node => nil, :environment => mock("env") } |
177 | 176 |
|
178 |
| - @request = stub 'request', :key => "foo/bar/baz", :options => {}, :node => nil, :environment => mock("env") |
| 177 | + before do |
| 178 | + config.stubs(:find_mount) |
179 | 179 | end
|
180 | 180 |
|
181 | 181 | it "should reread the configuration" do
|
182 |
| - @config.expects(:readconfig) |
| 182 | + config.expects(:readconfig) |
183 | 183 |
|
184 |
| - @config.split_path(@request) |
| 184 | + config.split_path(request) |
185 | 185 | end
|
186 | 186 |
|
187 | 187 | it "should treat the first field of the URI path as the mount name" do
|
188 |
| - @config.expects(:find_mount).with { |name, node| name == "foo" } |
| 188 | + config.expects(:find_mount).with { |name, node| name == "foo" } |
189 | 189 |
|
190 |
| - @config.split_path(@request) |
| 190 | + config.split_path(request) |
191 | 191 | end
|
192 | 192 |
|
193 | 193 | it "should fail if the mount name is not alpha-numeric" do
|
194 |
| - @request.expects(:key).returns "foo&bar/asdf" |
| 194 | + request.expects(:key).returns "foo&bar/asdf" |
195 | 195 |
|
196 |
| - lambda { @config.split_path(@request) }.should raise_error(ArgumentError) |
| 196 | + lambda { config.split_path(request) }.should raise_error(ArgumentError) |
197 | 197 | end
|
198 | 198 |
|
199 | 199 | it "should support dashes in the mount name" do
|
200 |
| - @request.expects(:key).returns "foo-bar/asdf" |
| 200 | + request.expects(:key).returns "foo-bar/asdf" |
201 | 201 |
|
202 |
| - lambda { @config.split_path(@request) }.should_not raise_error(ArgumentError) |
| 202 | + lambda { config.split_path(request) }.should_not raise_error(ArgumentError) |
203 | 203 | end
|
204 | 204 |
|
205 | 205 | it "should use the mount name and environment to find the mount" do
|
206 |
| - @config.expects(:find_mount).with { |name, env| name == "foo" and env == @request.environment } |
207 |
| - @request.stubs(:node).returns("mynode") |
| 206 | + config.expects(:find_mount).with { |name, env| name == "foo" and env == request.environment } |
| 207 | + request.stubs(:node).returns("mynode") |
208 | 208 |
|
209 |
| - @config.split_path(@request) |
| 209 | + config.split_path(request) |
210 | 210 | end
|
211 | 211 |
|
212 | 212 | it "should return nil if the mount cannot be found" do
|
213 |
| - @config.expects(:find_mount).returns nil |
| 213 | + config.expects(:find_mount).returns nil |
214 | 214 |
|
215 |
| - @config.split_path(@request).should be_nil |
| 215 | + config.split_path(request).should be_nil |
216 | 216 | end
|
217 | 217 |
|
218 | 218 | it "should return the mount and the relative path if the mount is found" do
|
219 | 219 | mount = stub 'mount', :name => "foo"
|
220 |
| - @config.expects(:find_mount).returns mount |
| 220 | + config.expects(:find_mount).returns mount |
221 | 221 |
|
222 |
| - @config.split_path(@request).should == [mount, "bar/baz"] |
| 222 | + config.split_path(request).should == [mount, "bar/baz"] |
223 | 223 | end
|
224 | 224 |
|
225 | 225 | it "should remove any double slashes" do
|
226 |
| - @request.stubs(:key).returns "foo/bar//baz" |
| 226 | + request.stubs(:key).returns "foo/bar//baz" |
227 | 227 | mount = stub 'mount', :name => "foo"
|
228 |
| - @config.expects(:find_mount).returns mount |
| 228 | + config.expects(:find_mount).returns mount |
| 229 | + |
| 230 | + config.split_path(request).should == [mount, "bar/baz"] |
| 231 | + end |
| 232 | + |
| 233 | + it "should fail if the path contains .." do |
| 234 | + request.stubs(:key).returns 'module/foo/../../bar' |
229 | 235 |
|
230 |
| - @config.split_path(@request).should == [mount, "bar/baz"] |
| 236 | + expect do |
| 237 | + config.split_path(request) |
| 238 | + end.to raise_error(ArgumentError, /Invalid relative path/) |
231 | 239 | end
|
232 | 240 |
|
233 | 241 | it "should return the relative path as nil if it is an empty string" do
|
234 |
| - @request.expects(:key).returns "foo" |
| 242 | + request.expects(:key).returns "foo" |
235 | 243 | mount = stub 'mount', :name => "foo"
|
236 |
| - @config.expects(:find_mount).returns mount |
| 244 | + config.expects(:find_mount).returns mount |
237 | 245 |
|
238 |
| - @config.split_path(@request).should == [mount, nil] |
| 246 | + config.split_path(request).should == [mount, nil] |
239 | 247 | end
|
240 | 248 |
|
241 | 249 | it "should add 'modules/' to the relative path if the modules mount is used but not specified, for backward compatibility" do
|
242 |
| - @request.expects(:key).returns "foo/bar" |
| 250 | + request.expects(:key).returns "foo/bar" |
243 | 251 | mount = stub 'mount', :name => "modules"
|
244 |
| - @config.expects(:find_mount).returns mount |
| 252 | + config.expects(:find_mount).returns mount |
245 | 253 |
|
246 |
| - @config.split_path(@request).should == [mount, "foo/bar"] |
| 254 | + config.split_path(request).should == [mount, "foo/bar"] |
247 | 255 | end
|
248 | 256 | end
|
249 | 257 | end
|
0 commit comments