|
238 | 238 | expect(new_index.load_paths(plugin_name)).to eq([plugin_root.join(plugin_name, "lib").to_s]) |
239 | 239 | end |
240 | 240 |
|
| 241 | + it "ignores entries that climb out only after an interior parent reference" do |
| 242 | + require "rubygems/yaml_serializer" |
| 243 | + |
| 244 | + escaping_index = { |
| 245 | + "commands" => {}, |
| 246 | + "hooks" => {}, |
| 247 | + "load_paths" => { "escaping-plugin" => [File.join("escaping-plugin", "..", "..", "elsewhere", "lib")] }, |
| 248 | + "plugin_paths" => { "escaping-plugin" => File.join("escaping-plugin", "..", "..", "elsewhere") }, |
| 249 | + "sources" => {}, |
| 250 | + } |
| 251 | + |
| 252 | + File.open(index.index_file, "w") {|f| f.puts Gem::YAMLSerializer.dump(escaping_index) } |
| 253 | + |
| 254 | + new_index = Index.new |
| 255 | + |
| 256 | + expect(new_index.installed?("escaping-plugin")).to be_nil |
| 257 | + expect(new_index.load_paths("escaping-plugin")).to be_nil |
| 258 | + end |
| 259 | + |
| 260 | + it "reads a leading tilde in a relative path literally" do |
| 261 | + require "rubygems/yaml_serializer" |
| 262 | + |
| 263 | + plugin_root = Bundler::Plugin.root |
| 264 | + |
| 265 | + tilde_index = { |
| 266 | + "commands" => {}, |
| 267 | + "hooks" => {}, |
| 268 | + "load_paths" => { plugin_name => [File.join("~nosuchuser", "lib")] }, |
| 269 | + "plugin_paths" => { plugin_name => "~nosuchuser" }, |
| 270 | + "sources" => {}, |
| 271 | + } |
| 272 | + |
| 273 | + File.open(index.index_file, "w") {|f| f.puts Gem::YAMLSerializer.dump(tilde_index) } |
| 274 | + |
| 275 | + new_index = Index.new |
| 276 | + expect(new_index.plugin_path(plugin_name)).to eq(plugin_root.join("~nosuchuser")) |
| 277 | + expect(new_index.load_paths(plugin_name)).to eq([plugin_root.join("~nosuchuser", "lib").to_s]) |
| 278 | + end |
| 279 | + |
241 | 280 | it "keeps paths outside the plugin root as absolute" do |
242 | 281 | outside_path = tmp.join("outside", "external-plugin") |
243 | 282 | FileUtils.mkdir_p(outside_path.join("lib")) |
|
251 | 290 | expect(data["load_paths"]["external-plugin"]).to eq([outside_path.join("lib").to_s]) |
252 | 291 | end |
253 | 292 |
|
| 293 | + it "ignores entries whose relative paths climb out of the plugin root" do |
| 294 | + require "rubygems/yaml_serializer" |
| 295 | + |
| 296 | + escaping_index = { |
| 297 | + "commands" => { "escape" => "escaping-plugin" }, |
| 298 | + "hooks" => { "before-eval" => ["escaping-plugin", plugin_name] }, |
| 299 | + "load_paths" => { |
| 300 | + "escaping-plugin" => ["../../elsewhere/lib"], |
| 301 | + plugin_name => [File.join(plugin_name, "lib")], |
| 302 | + }, |
| 303 | + "plugin_paths" => { "escaping-plugin" => "../../elsewhere", plugin_name => plugin_name }, |
| 304 | + "sources" => { "escape" => "escaping-plugin" }, |
| 305 | + } |
| 306 | + |
| 307 | + File.open(index.index_file, "w") {|f| f.puts Gem::YAMLSerializer.dump(escaping_index) } |
| 308 | + |
| 309 | + new_index = Index.new |
| 310 | + |
| 311 | + expect(new_index.installed?("escaping-plugin")).to be_nil |
| 312 | + expect(new_index.load_paths("escaping-plugin")).to be_nil |
| 313 | + expect(new_index.command_plugin("escape")).to be_nil |
| 314 | + expect(new_index.source_plugin("escape")).to be_nil |
| 315 | + expect(new_index.hook_plugins("before-eval")).to eq([plugin_name]) |
| 316 | + expect(new_index.installed?(plugin_name)).to eq(Bundler::Plugin.root.join(plugin_name).to_s) |
| 317 | + end |
| 318 | + |
| 319 | + it "ignores entries whose load paths alone climb out of the plugin root" do |
| 320 | + require "rubygems/yaml_serializer" |
| 321 | + |
| 322 | + escaping_index = { |
| 323 | + "commands" => {}, |
| 324 | + "hooks" => {}, |
| 325 | + "load_paths" => { "escaping-plugin" => ["../../elsewhere/lib"] }, |
| 326 | + "plugin_paths" => { "escaping-plugin" => "escaping-plugin" }, |
| 327 | + "sources" => {}, |
| 328 | + } |
| 329 | + |
| 330 | + File.open(index.index_file, "w") {|f| f.puts Gem::YAMLSerializer.dump(escaping_index) } |
| 331 | + |
| 332 | + new_index = Index.new |
| 333 | + |
| 334 | + expect(new_index.installed?("escaping-plugin")).to be_nil |
| 335 | + expect(new_index.load_paths("escaping-plugin")).to be_nil |
| 336 | + end |
| 337 | + |
| 338 | + it "drops hook events whose plugins all climb out of the plugin root" do |
| 339 | + require "rubygems/yaml_serializer" |
| 340 | + |
| 341 | + escaping_index = { |
| 342 | + "commands" => {}, |
| 343 | + "hooks" => { "before-eval" => ["escaping-plugin"] }, |
| 344 | + "load_paths" => { "escaping-plugin" => ["../../elsewhere/lib"] }, |
| 345 | + "plugin_paths" => { "escaping-plugin" => "../../elsewhere" }, |
| 346 | + "sources" => {}, |
| 347 | + } |
| 348 | + |
| 349 | + File.open(index.index_file, "w") {|f| f.puts Gem::YAMLSerializer.dump(escaping_index) } |
| 350 | + |
| 351 | + new_index = Index.new |
| 352 | + new_index.register_plugin("aplugin", lib_path("aplugin").to_s, [lib_path("aplugin").join("lib").to_s], [], [], []) |
| 353 | + |
| 354 | + expect(new_index.index_file.read).to_not include("before-eval") |
| 355 | + end |
| 356 | + |
254 | 357 | it "reads legacy index files with absolute paths" do |
255 | 358 | require "rubygems/yaml_serializer" |
256 | 359 |
|
|
0 commit comments