2017-02-27 17:38:07 +01:00
|
|
|
require "sandbox"
|
|
|
|
|
|
|
|
describe Sandbox do
|
2017-05-09 23:00:51 +02:00
|
|
|
define_negated_matcher :not_matching, :matching
|
|
|
|
|
2017-02-28 14:50:46 +01:00
|
|
|
let(:dir) { mktmpdir }
|
2017-02-27 17:38:07 +01:00
|
|
|
let(:file) { dir/"foo" }
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
skip "Sandbox not implemented." unless described_class.available?
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#formula?" do
|
|
|
|
f = formula { url "foo-1.0" }
|
2017-07-14 17:00:06 +01:00
|
|
|
expect(described_class).to be_formula(f), "Formulae should be sandboxed."
|
2017-02-27 17:38:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "#test?" do
|
|
|
|
ENV.delete("HOMEBREW_NO_SANDBOX")
|
|
|
|
expect(described_class).to be_test, "Tests should be sandboxed unless --no-sandbox was passed."
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#allow_write" do
|
|
|
|
subject.allow_write file
|
|
|
|
subject.exec "touch", file
|
|
|
|
|
|
|
|
expect(file).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#exec" do
|
|
|
|
it "fails when writing to file not specified with ##allow_write" do
|
2017-07-29 19:55:05 +02:00
|
|
|
expect {
|
|
|
|
subject.exec "touch", file
|
|
|
|
}.to raise_error(ErrorDuringExecution)
|
2017-02-27 17:38:07 +01:00
|
|
|
|
|
|
|
expect(file).not_to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "complains on failure" do
|
|
|
|
ENV["HOMEBREW_VERBOSE"] = "1"
|
|
|
|
|
|
|
|
expect(Utils).to receive(:popen_read).and_return("foo")
|
|
|
|
|
|
|
|
expect { subject.exec "false" }
|
|
|
|
.to raise_error(ErrorDuringExecution)
|
|
|
|
.and output(/foo/).to_stdout
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores bogus Python error" do
|
|
|
|
ENV["HOMEBREW_VERBOSE"] = "1"
|
|
|
|
|
|
|
|
with_bogus_error = <<-EOS.undent
|
|
|
|
foo
|
|
|
|
Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc
|
|
|
|
bar
|
|
|
|
EOS
|
|
|
|
expect(Utils).to receive(:popen_read).and_return(with_bogus_error)
|
|
|
|
|
|
|
|
expect { subject.exec "false" }
|
|
|
|
.to raise_error(ErrorDuringExecution)
|
|
|
|
.and output(a_string_matching(/foo/).and(matching(/bar/).and(not_matching(/Python/)))).to_stdout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|