|
40 | 40 | instance_double(Sandbox).tap do |sandbox| |
41 | 41 | allow(sandbox).to receive(:allow_read) |
42 | 42 | allow(sandbox).to receive(:allow_write_temp_and_cache) |
| 43 | + allow(sandbox).to receive(:deny_read_home) |
43 | 44 | allow(sandbox).to receive(:deny_all_network) |
44 | 45 | allow(sandbox).to receive(:run) do |*args| |
45 | | - Pathname(args.fetch(6)).write("#{args.fetch(1).delete_prefix("SHELL=")} completion output") |
| 46 | + Pathname(args.fetch(7)).write("#{args.grep(/^SHELL=/).first.delete_prefix("SHELL=")} completion output") |
46 | 47 | end |
47 | 48 | end |
48 | 49 | end |
|
57 | 58 | expect((fish_dir/"foo.fish").read).to eq("fish completion output") |
58 | 59 | end |
59 | 60 |
|
60 | | - it "sandboxes completion generation" do |
| 61 | + it "sandboxes completion generation without network access" do |
61 | 62 | artifact = cask.artifacts.grep(klass).first |
62 | 63 | sandboxes = [] |
| 64 | + calls = [] |
| 65 | + homes = [] |
63 | 66 |
|
64 | 67 | allow(Sandbox).to receive_messages(ensure_sandbox_installed!: nil, available?: true) |
65 | 68 | allow(Sandbox).to receive(:new) do |
66 | 69 | instance_double(Sandbox).tap do |sandbox| |
67 | 70 | expect(sandbox).to receive(:allow_read).with(path: staged_path, type: :subpath) |
68 | 71 | expect(sandbox).to receive(:allow_write_temp_and_cache) |
69 | | - expect(sandbox).to receive(:deny_all_network) |
70 | | - allow(sandbox).to receive(:run) { |*args| Pathname(args.fetch(6)).write("completion") } |
| 72 | + expect(sandbox).to receive(:deny_read_home) |
| 73 | + expect(sandbox).to receive(:deny_all_network) { calls << :deny_all_network } |
| 74 | + allow(sandbox).to receive(:run) do |*args| |
| 75 | + calls << :run |
| 76 | + homes << Pathname(args.grep(/^HOME=/).first.delete_prefix("HOME=")) |
| 77 | + Pathname(args.fetch(7)).write("completion") |
| 78 | + end |
71 | 79 | sandboxes << sandbox |
72 | 80 | end |
73 | 81 | end |
74 | 82 |
|
75 | 83 | artifact.install_phase |
76 | 84 |
|
77 | 85 | expect(sandboxes.length).to eq(3) |
| 86 | + expect(calls).to eq([:deny_all_network, :run, :deny_all_network, :run, :deny_all_network, :run]) |
| 87 | + expect(homes.uniq.length).to eq(3) |
| 88 | + expect(homes).to all(satisfy { |home| !home.exist? }) |
78 | 89 | end |
79 | 90 |
|
80 | 91 | it "does not sandbox when HOMEBREW_NO_SANDBOX_CASK is set" do |
|
101 | 112 | instance_double(Sandbox).tap do |sandbox| |
102 | 113 | allow(sandbox).to receive(:allow_read) |
103 | 114 | allow(sandbox).to receive(:allow_write_temp_and_cache) |
| 115 | + allow(sandbox).to receive(:deny_read_home) |
104 | 116 | allow(sandbox).to receive(:deny_all_network) |
105 | 117 | allow(sandbox).to receive(:run) do |*args| |
106 | | - raise "boom" if args.fetch(1) == "SHELL=bash" |
| 118 | + raise "boom" if args.include?("SHELL=bash") |
107 | 119 |
|
108 | | - Pathname(args.fetch(6)).write("zsh completion") |
| 120 | + Pathname(args.fetch(7)).write("zsh completion") |
109 | 121 | end |
110 | 122 | end |
111 | 123 | end |
|
159 | 171 | instance_double(Sandbox).tap do |sandbox| |
160 | 172 | allow(sandbox).to receive(:allow_read) |
161 | 173 | allow(sandbox).to receive(:allow_write_temp_and_cache) |
| 174 | + allow(sandbox).to receive(:deny_read_home) |
162 | 175 | allow(sandbox).to receive(:deny_all_network) |
163 | 176 | allow(sandbox).to receive(:run) do |*args| |
164 | 177 | captured_args = args |
165 | | - Pathname(args.fetch(6)).write("zsh completion") |
| 178 | + Pathname(args.fetch(7)).write("zsh completion") |
166 | 179 | end |
167 | 180 | end |
168 | 181 | end |
169 | 182 |
|
170 | 183 | artifact.install_phase |
171 | 184 |
|
172 | 185 | expect(captured_args).to include("--shell=zsh") |
173 | | - expect(captured_args.fetch(4)).to end_with(" 2>/dev/null") |
| 186 | + expect(captured_args.fetch(5)).to end_with(" 2>/dev/null") |
174 | 187 | expect(zsh_dir/"_bar").to be_a_file |
175 | 188 | expect(bash_dir/"bar").not_to exist |
176 | 189 | expect(fish_dir/"bar.fish").not_to exist |
|
0 commit comments