File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def run
80
80
81
81
exec_args << "--HEAD" if f . head?
82
82
83
- Utils . safe_fork do
83
+ Utils . safe_fork do | error_pipe |
84
84
if Sandbox . available?
85
85
sandbox = Sandbox . new
86
86
f . logs . mkpath
@@ -92,6 +92,10 @@ def run
92
92
sandbox . allow_write_path ( HOMEBREW_PREFIX /"var/homebrew/locks" )
93
93
sandbox . allow_write_path ( HOMEBREW_PREFIX /"var/log" )
94
94
sandbox . allow_write_path ( HOMEBREW_PREFIX /"var/run" )
95
+ if f . class . offline_phase? ( :test )
96
+ sandbox . deny_all_network
97
+ sandbox . allow_network ( error_pipe , type : :literal )
98
+ end
95
99
sandbox . exec ( *exec_args )
96
100
else
97
101
exec ( *exec_args )
Original file line number Diff line number Diff line change 2
2
3
3
require "cmd/shared_examples/args_parse"
4
4
require "dev-cmd/test"
5
+ require "sandbox"
5
6
6
7
RSpec . describe Homebrew ::DevCmd ::Test do
7
8
it_behaves_like "parseable arguments"
18
19
. and not_to_output . to_stderr
19
20
. and be_a_success
20
21
end
22
+
23
+ it "blocks network access when test phase is offline" , :integration_test do
24
+ if Sandbox . available?
25
+ install_test_formula "testball_offline_test" , <<~RUBY
26
+ enable_offline_phase [:test]
27
+ test do
28
+ system "curl", "example.org"
29
+ end
30
+ RUBY
31
+
32
+ expect { brew "test" , "--verbose" , "testball_offline_test" }
33
+ . to output ( /curl: \( 6\) Could not resolve host: example\. org/ ) . to_stdout
34
+ . and be_a_failure
35
+ end
36
+ end
21
37
end
You can’t perform that action at this time.
0 commit comments