summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZehan Zhao <cnallenzhao@gmail.com>2016-07-25 17:02:39 +0800
committerZehan Zhao <cnallenzhao@gmail.com>2016-08-06 04:29:58 +0800
commit73f8e9a865d4cd2a0cf68b6effc5ff5bc0d027ad (patch)
tree6db1e26ce9e28927e539031880c3dbb43f38bcb9
parente00179ea7211ac902e64ad1e08d5b0a26d14adb7 (diff)
downloadbundler-73f8e9a865d4cd2a0cf68b6effc5ff5bc0d027ad.tar.gz
Add spec test
-rw-r--r--lib/bundler.rb4
-rw-r--r--spec/bundler/bundler_spec.rb18
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 15b38869f2..aa30663a46 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -202,8 +202,8 @@ It is a security vulnerability to allow your home directory to be world-writable
You should probably consider fixing this issue by running `chmod o-w ~` on *nix.
Please refer to http://ruby-doc.org/stdlib-2.1.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure for details.
EOF
- Bundler.ui.warn(message) if File.expand_path(path).world_writable?
- raise
+ File.world_writable?(path) ? Bundler.ui.warn(message) : raise
+ raise PathError, "Please fix the world-writable issue with your #{path} directory"
end
def settings
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index f338b5268d..b9a8e52cc9 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -152,4 +152,22 @@ describe Bundler do
end
end
end
+
+ describe "#rm_rf" do
+ context "the directory is world writable" do
+ let(:bundler_ui) { Bundler.ui }
+ it "should show a fridenly error" do
+ allow(File).to receive(:exist?).and_return(true)
+ allow(FileUtils).to receive(:remove_entry_secure).and_raise(ArgumentError)
+ allow(File).to receive(:world_writable?).and_return(true)
+ message = <<EOF
+It is a security vulnerability to allow your home directory to be world-writable, and bundler can not continue.
+You should probably consider fixing this issue by running `chmod o-w ~` on *nix.
+Please refer to http://ruby-doc.org/stdlib-2.1.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure for details.
+EOF
+ expect(bundler_ui).to receive(:warn).with(message)
+ expect { Bundler.send(:rm_rf, bundled_app) }.to raise_error(Bundler::PathError)
+ end
+ end
+ end
end