cocoonstack-sandbox 0.1.32__tar.gz → 0.1.34__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/PKG-INFO +1 -1
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/client.py +2 -2
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/conn.py +22 -20
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/sandbox.py +70 -51
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/PKG-INFO +1 -1
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/pyproject.toml +1 -1
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_hardening.py +15 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_keepalive.py +24 -10
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_upgrade.py +22 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/LICENSE +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/README.md +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/__init__.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/checkpoint.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/endpoint.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/errors.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/frames.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/py.typed +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/template.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonsandbox/volumes.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/SOURCES.txt +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/dependency_links.txt +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/top_level.txt +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/setup.cfg +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_checkpoint.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_client.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_endpoint.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_fault_matrix.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_fixtures.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_frames.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_packaging.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_proc.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_proxy.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_stream.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_volume_controller.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_volumes.py +0 -0
- {cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/tests/test_wire_binding.py +0 -0
|
@@ -121,7 +121,7 @@ class Client(_Closeable):
|
|
|
121
121
|
return self._request(self.addr, "DELETE", "/v1/drain", None, "undrain")
|
|
122
122
|
|
|
123
123
|
def cordon(self) -> dict[str, Any]:
|
|
124
|
-
"""Refuses new claims across restarts (root token); live claims
|
|
124
|
+
"""Refuses new claims across restarts (root token); live claims, moves in and adoptions stay admitted."""
|
|
125
125
|
return self._request(self.addr, "POST", "/v1/cordon", None, "cordon")
|
|
126
126
|
|
|
127
127
|
def uncordon(self) -> dict[str, Any]:
|
|
@@ -237,7 +237,7 @@ class Client(_Closeable):
|
|
|
237
237
|
|
|
238
238
|
def _dial(self, addr: str, sandbox_id: str, token: str, deadline: float | None = None) -> Conn:
|
|
239
239
|
origin = addr if "://" in addr else f"{self._scheme}://{addr}"
|
|
240
|
-
context = self._tls() if origin.startswith("https://") else None
|
|
240
|
+
context = self._tls() if origin.lower().startswith("https://") else None
|
|
241
241
|
return dial_agent(
|
|
242
242
|
origin, sandbox_id, token, self.timeout, deadline, ssl_context=context, tag=(sandbox_id, addr)
|
|
243
243
|
)
|
|
@@ -67,10 +67,30 @@ class Conn(_Closeable):
|
|
|
67
67
|
with contextlib.suppress(OSError):
|
|
68
68
|
self._sock.shutdown(socket.SHUT_RDWR)
|
|
69
69
|
|
|
70
|
+
def finish_upgrade(self) -> None:
|
|
71
|
+
"""Reads a plain-HTTP upgrade's pending 101; it retimes the socket, so no other thread may be sending."""
|
|
72
|
+
timeout, self._upgrade_timeout = self._upgrade_timeout, None
|
|
73
|
+
if timeout is None:
|
|
74
|
+
return
|
|
75
|
+
caller = self._sock.gettimeout()
|
|
76
|
+
limit = timeout if caller is None else min(caller, timeout)
|
|
77
|
+
deadline = time.monotonic() + limit
|
|
78
|
+
try:
|
|
79
|
+
_read_upgrade(
|
|
80
|
+
self._reader,
|
|
81
|
+
lambda: self._sock.settimeout(remaining_timeout(limit, deadline, "agent upgrade")),
|
|
82
|
+
self._tag,
|
|
83
|
+
)
|
|
84
|
+
self._sock.settimeout(caller)
|
|
85
|
+
except Exception as exc:
|
|
86
|
+
self.close()
|
|
87
|
+
if isinstance(exc, OSError) and not isinstance(exc, SandboxError):
|
|
88
|
+
raise _handshake_error("agent upgrade", exc) from exc
|
|
89
|
+
raise
|
|
90
|
+
|
|
70
91
|
def recv(self) -> dict[str, Any]:
|
|
71
92
|
"""Reads one frame or raises a typed protocol or guest error."""
|
|
72
|
-
|
|
73
|
-
self._finish_upgrade(self._upgrade_timeout)
|
|
93
|
+
self.finish_upgrade()
|
|
74
94
|
try:
|
|
75
95
|
line = self._reader.readline(MAX_FRAME + 1)
|
|
76
96
|
except (OSError, ValueError) as exc:
|
|
@@ -106,24 +126,6 @@ class Conn(_Closeable):
|
|
|
106
126
|
finally:
|
|
107
127
|
self._sock.close()
|
|
108
128
|
|
|
109
|
-
def _finish_upgrade(self, timeout: float) -> None:
|
|
110
|
-
self._upgrade_timeout = None
|
|
111
|
-
caller = self._sock.gettimeout()
|
|
112
|
-
limit = timeout if caller is None else min(caller, timeout)
|
|
113
|
-
deadline = time.monotonic() + limit
|
|
114
|
-
try:
|
|
115
|
-
_read_upgrade(
|
|
116
|
-
self._reader,
|
|
117
|
-
lambda: self._sock.settimeout(remaining_timeout(limit, deadline, "agent upgrade")),
|
|
118
|
-
self._tag,
|
|
119
|
-
)
|
|
120
|
-
self._sock.settimeout(caller)
|
|
121
|
-
except Exception as exc:
|
|
122
|
-
self.close()
|
|
123
|
-
if isinstance(exc, OSError) and not isinstance(exc, SandboxError):
|
|
124
|
-
raise _handshake_error("agent upgrade", exc) from exc
|
|
125
|
-
raise
|
|
126
|
-
|
|
127
129
|
|
|
128
130
|
class ConnPool:
|
|
129
131
|
"""Parks a handle's idle relay connections between calls; one sweeper timer closes them as they expire."""
|
|
@@ -144,7 +144,6 @@ class Sandbox:
|
|
|
144
144
|
raise ExitError(code, err.decode(errors="replace"), out.decode(errors="replace"))
|
|
145
145
|
return out.decode(errors="replace")
|
|
146
146
|
|
|
147
|
-
@_follows_move
|
|
148
147
|
def run(
|
|
149
148
|
self,
|
|
150
149
|
argv: list[str],
|
|
@@ -157,59 +156,24 @@ class Sandbox:
|
|
|
157
156
|
on_stderr: Callable[[bytes], object] | None = None,
|
|
158
157
|
timeout: float | None = None,
|
|
159
158
|
) -> int:
|
|
160
|
-
"""Streams raw output
|
|
159
|
+
"""Streams raw output and returns the exit code; timeout kills what it cuts, except a session command."""
|
|
161
160
|
if timeout is not None and timeout <= 0:
|
|
162
161
|
raise ValueError("timeout must be positive")
|
|
163
162
|
if stdin and not isinstance(stdin, (bytes, bytearray, memoryview)):
|
|
164
163
|
raise TypeError("stdin must be bytes")
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
179
|
-
except (ProtocolError, TimeoutError):
|
|
180
|
-
if deadline is not None and time.monotonic() >= deadline:
|
|
181
|
-
raise SandboxTimeout(f"command did not finish within {timeout}s") from None
|
|
182
|
-
raise
|
|
183
|
-
with self._lease(conn):
|
|
184
|
-
watchdog = None if deadline is None else _arm_watchdog(conn, deadline, expired)
|
|
185
|
-
pump = threading.Thread(target=_feed_stdin, args=(conn, stdin), daemon=True) if stdin else None
|
|
186
|
-
try:
|
|
187
|
-
if pump is not None:
|
|
188
|
-
pump.start()
|
|
189
|
-
else:
|
|
190
|
-
with contextlib.suppress(ProtocolError):
|
|
191
|
-
conn.send("stdin_close")
|
|
192
|
-
code = _pump_stdio(conn, on_stdout, on_stderr, started.append)
|
|
193
|
-
except (ProtocolError, OSError):
|
|
194
|
-
if expired.is_set():
|
|
195
|
-
if started:
|
|
196
|
-
self._kill_after_cut(started[0])
|
|
197
|
-
raise SandboxTimeout(f"command did not finish within {timeout}s") from None
|
|
198
|
-
raise
|
|
199
|
-
except SilkdError:
|
|
200
|
-
if pump is not None:
|
|
201
|
-
pump.join()
|
|
202
|
-
raise
|
|
203
|
-
finally:
|
|
204
|
-
if watchdog is not None:
|
|
205
|
-
watchdog.cancel()
|
|
206
|
-
if pump is not None:
|
|
207
|
-
if pump.is_alive():
|
|
208
|
-
conn.abort()
|
|
209
|
-
pump.join() # the pump's frames must not land on the next RPC
|
|
210
|
-
if code is None:
|
|
211
|
-
raise ProtocolError("exec stream ended without an exit frame")
|
|
212
|
-
return code
|
|
164
|
+
return self._run(
|
|
165
|
+
None if timeout is None else time.monotonic() + timeout,
|
|
166
|
+
timeout,
|
|
167
|
+
stdin,
|
|
168
|
+
on_stdout,
|
|
169
|
+
on_stderr,
|
|
170
|
+
argv=argv,
|
|
171
|
+
cwd=cwd or None,
|
|
172
|
+
env=env,
|
|
173
|
+
user=user or None,
|
|
174
|
+
detach=False,
|
|
175
|
+
session=session or None,
|
|
176
|
+
)
|
|
213
177
|
|
|
214
178
|
def spawn(self, *argv: str, cwd: str = "", env: dict[str, str] | None = None, user: str = "") -> int:
|
|
215
179
|
"""Starts a detached process with a bounded output ring and returns its pid."""
|
|
@@ -241,7 +205,7 @@ class Sandbox:
|
|
|
241
205
|
on_stdout: Callable[[bytes], object] | None = None,
|
|
242
206
|
on_stderr: Callable[[bytes], object] | None = None,
|
|
243
207
|
) -> int | None:
|
|
244
|
-
"""Replays then follows output;
|
|
208
|
+
"""Replays then follows output until exit; a reader that falls behind misses live chunks."""
|
|
245
209
|
return self._drain_proc("attach", pid, on_stdout, on_stderr)
|
|
246
210
|
|
|
247
211
|
@_follows_move
|
|
@@ -630,6 +594,56 @@ class Sandbox:
|
|
|
630
594
|
_expect(conn, "done")
|
|
631
595
|
return code
|
|
632
596
|
|
|
597
|
+
@_follows_move
|
|
598
|
+
def _run(
|
|
599
|
+
self,
|
|
600
|
+
deadline: float | None,
|
|
601
|
+
timeout: float | None,
|
|
602
|
+
stdin: bytes,
|
|
603
|
+
on_stdout: Callable[[bytes], object] | None,
|
|
604
|
+
on_stderr: Callable[[bytes], object] | None,
|
|
605
|
+
**fields: object,
|
|
606
|
+
) -> int:
|
|
607
|
+
expired = threading.Event()
|
|
608
|
+
started: deque[int] = deque(maxlen=1)
|
|
609
|
+
try:
|
|
610
|
+
conn = self._connect("exec", deadline, **fields)
|
|
611
|
+
except (ProtocolError, TimeoutError):
|
|
612
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
613
|
+
raise SandboxTimeout(f"command did not finish within {timeout}s") from None
|
|
614
|
+
raise
|
|
615
|
+
with self._lease(conn):
|
|
616
|
+
watchdog = None if deadline is None else _arm_watchdog(conn, deadline, expired)
|
|
617
|
+
pump = threading.Thread(target=_feed_stdin, args=(conn, stdin), daemon=True) if stdin else None
|
|
618
|
+
try:
|
|
619
|
+
if pump is not None:
|
|
620
|
+
conn.finish_upgrade()
|
|
621
|
+
pump.start()
|
|
622
|
+
else:
|
|
623
|
+
with contextlib.suppress(ProtocolError):
|
|
624
|
+
conn.send("stdin_close")
|
|
625
|
+
code = _pump_stdio(conn, on_stdout, on_stderr, started.append)
|
|
626
|
+
except (ProtocolError, OSError):
|
|
627
|
+
if expired.is_set():
|
|
628
|
+
if started:
|
|
629
|
+
self._kill_after_cut(started[0])
|
|
630
|
+
raise SandboxTimeout(f"command did not finish within {timeout}s") from None
|
|
631
|
+
raise
|
|
632
|
+
except SilkdError:
|
|
633
|
+
if pump is not None:
|
|
634
|
+
pump.join()
|
|
635
|
+
raise
|
|
636
|
+
finally:
|
|
637
|
+
if watchdog is not None:
|
|
638
|
+
watchdog.cancel()
|
|
639
|
+
if pump is not None:
|
|
640
|
+
if pump.is_alive():
|
|
641
|
+
conn.abort()
|
|
642
|
+
pump.join() # the pump's frames must not land on the next RPC
|
|
643
|
+
if code is None:
|
|
644
|
+
raise ProtocolError("exec stream ended without an exit frame")
|
|
645
|
+
return code
|
|
646
|
+
|
|
633
647
|
def _kill_after_cut(self, pid: int) -> None:
|
|
634
648
|
deadline = time.monotonic() + _KILL_WAIT_SECONDS
|
|
635
649
|
with contextlib.suppress(SandboxError, OSError), self._lease(self._connect("kill", deadline, pid=pid)) as conn:
|
|
@@ -671,7 +685,11 @@ class Watcher(_Closeable):
|
|
|
671
685
|
except ProtocolError as e:
|
|
672
686
|
if not self._closed:
|
|
673
687
|
self.error = e
|
|
688
|
+
self._conn.close()
|
|
674
689
|
return
|
|
690
|
+
except SilkdError:
|
|
691
|
+
self._conn.close()
|
|
692
|
+
raise
|
|
675
693
|
if frame["type"] == "event":
|
|
676
694
|
yield frame
|
|
677
695
|
|
|
@@ -698,6 +716,7 @@ class Pty(_Closeable):
|
|
|
698
716
|
if frame["type"] == "exit":
|
|
699
717
|
self.exit_code = frame.get("code")
|
|
700
718
|
self._eof = True
|
|
719
|
+
self._conn.close()
|
|
701
720
|
return b""
|
|
702
721
|
return frame.get("data") or b""
|
|
703
722
|
|
|
@@ -167,6 +167,21 @@ def test_watcher_error_stays_none_after_close(conn_pair):
|
|
|
167
167
|
assert events == [] and watcher.error is None
|
|
168
168
|
|
|
169
169
|
|
|
170
|
+
def test_a_watcher_closes_its_connection_when_the_stream_ends(conn_pair):
|
|
171
|
+
conn, guest_sock = conn_pair
|
|
172
|
+
guest_sock.sendall(json.dumps({"type": "error", "kind": "internal", "message": "overflow"}).encode() + b"\n")
|
|
173
|
+
with pytest.raises(SilkdError):
|
|
174
|
+
list(Watcher(conn))
|
|
175
|
+
assert conn._sock.fileno() == -1, "the ended watch kept its relay open"
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_a_pty_closes_its_connection_at_the_exit_frame(conn_pair):
|
|
179
|
+
conn, guest_sock = conn_pair
|
|
180
|
+
guest_sock.sendall(json.dumps({"type": "exit", "code": 0}).encode() + b"\n")
|
|
181
|
+
assert Pty(sandbox_at("127.0.0.1:1"), conn, 1).read() == b""
|
|
182
|
+
assert conn._sock.fileno() == -1, "the exited pty kept its relay open"
|
|
183
|
+
|
|
184
|
+
|
|
170
185
|
def test_sandbox_timeout_is_both_hierarchies():
|
|
171
186
|
with pytest.raises(SandboxError):
|
|
172
187
|
remaining_timeout(1.0, time.monotonic() - 1, "probe")
|
|
@@ -15,11 +15,10 @@ INPUT_OPS = ("stdin", "stdin_close", "data", "data_end")
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class FakeAgent:
|
|
18
|
-
"""A relay-side silkd stand-in; hang_up_after half-closes after N RPCs
|
|
18
|
+
"""A relay-side silkd stand-in; hang_up_after half-closes after N RPCs."""
|
|
19
19
|
|
|
20
|
-
def __init__(self, hang_up_after: int = 0
|
|
20
|
+
def __init__(self, hang_up_after: int = 0) -> None:
|
|
21
21
|
self.hang_up_after = hang_up_after
|
|
22
|
-
self.slam = slam
|
|
23
22
|
self.upgrades = 0
|
|
24
23
|
self.hangups = 0
|
|
25
24
|
self.closed = 0
|
|
@@ -51,8 +50,6 @@ class FakeAgent:
|
|
|
51
50
|
for frame in self._answer(op):
|
|
52
51
|
conn.sendall(json.dumps(frame).encode() + b"\n")
|
|
53
52
|
replies += 1
|
|
54
|
-
if self.slam:
|
|
55
|
-
break
|
|
56
53
|
if replies == self.hang_up_after:
|
|
57
54
|
conn.shutdown(socket.SHUT_WR)
|
|
58
55
|
self.hangups += 1
|
|
@@ -65,7 +62,7 @@ class FakeAgent:
|
|
|
65
62
|
if op == "fs_stat":
|
|
66
63
|
return [{"type": "stat", "info": {"kind": "dir", "size": 0, "mode": 0o755, "mtime_epoch_secs": 0}}]
|
|
67
64
|
if op == "fs_find":
|
|
68
|
-
return [{"type": "match", "
|
|
65
|
+
return [{"type": "match", "file": "/work/f", "line": 1, "content": "TODO"}, {"type": "done"}]
|
|
69
66
|
if op == "exec":
|
|
70
67
|
out = base64.b64encode(b"42\n").decode()
|
|
71
68
|
return [{"type": "started", "pid": 1}, {"type": "stdout", "data": out}, {"type": "exit", "code": 0}]
|
|
@@ -184,9 +181,11 @@ def test_close_drains_the_parked_connection(monkeypatch, relay):
|
|
|
184
181
|
|
|
185
182
|
|
|
186
183
|
def test_an_upload_the_daemon_rejects_at_open_raises_its_error_frame(relay):
|
|
187
|
-
|
|
184
|
+
agent, sb = relay()
|
|
188
185
|
with pytest.raises(SilkdError):
|
|
189
186
|
sb.write_file("/missing/f", bytes(64 << 20))
|
|
187
|
+
assert sb.stat("/")["kind"] == "dir"
|
|
188
|
+
assert agent.upgrades == 1, agent.upgrades
|
|
190
189
|
|
|
191
190
|
|
|
192
191
|
@pytest.mark.parametrize("retired", [False, True], ids=["owner_404", "connection_refused"])
|
|
@@ -214,12 +213,27 @@ def test_find_retries_at_the_new_owner(spawn_node, dead_addr, relay, retired, st
|
|
|
214
213
|
old = dead_addr if retired else spawn_node({})
|
|
215
214
|
sb = Client(directory, keep_alive=0).attach(old, "sb_1", "tok")
|
|
216
215
|
matches = list(sb.find_iter("/work", "TODO")) if streamed else sb.find("/work", "TODO")
|
|
217
|
-
assert matches == [{"type": "match", "
|
|
216
|
+
assert matches == [{"type": "match", "file": "/work/f", "line": 1, "content": "TODO"}]
|
|
218
217
|
assert sb.owner == agent.addr
|
|
219
218
|
assert len(lookups) == 1
|
|
220
219
|
assert agent.upgrades == 1
|
|
221
220
|
|
|
222
221
|
|
|
222
|
+
def test_run_keeps_one_deadline_across_a_move(monkeypatch, spawn_node, dead_addr, relay):
|
|
223
|
+
agent, _ = relay()
|
|
224
|
+
directory = spawn_node({("GET", "/v1/sandboxes/sb_1/owner"): lambda body, path: (200, {"owner_addr": agent.addr})})
|
|
225
|
+
sb = Client(directory, keep_alive=0).attach(dead_addr, "sb_1", "tok")
|
|
226
|
+
dial, deadlines = sb._dial, []
|
|
227
|
+
|
|
228
|
+
def recording_dial(deadline=None):
|
|
229
|
+
deadlines.append(deadline)
|
|
230
|
+
return dial(deadline)
|
|
231
|
+
|
|
232
|
+
monkeypatch.setattr(sb, "_dial", recording_dial)
|
|
233
|
+
assert sb.run(["echo", "42"], timeout=30) == 0
|
|
234
|
+
assert len(deadlines) == 2 and deadlines[0] == deadlines[1], deadlines
|
|
235
|
+
|
|
236
|
+
|
|
223
237
|
def test_a_callback_error_tagged_for_this_sandbox_is_not_replayed(spawn_node):
|
|
224
238
|
owner, other = FakeAgent(), FakeAgent()
|
|
225
239
|
try:
|
|
@@ -263,8 +277,8 @@ def test_another_sandboxs_error_in_a_callback_is_not_replayed(spawn_node, dead_a
|
|
|
263
277
|
def relay():
|
|
264
278
|
started = []
|
|
265
279
|
|
|
266
|
-
def start(hang_up_after=0,
|
|
267
|
-
agent = FakeAgent(hang_up_after
|
|
280
|
+
def start(hang_up_after=0, **client_kwargs):
|
|
281
|
+
agent = FakeAgent(hang_up_after)
|
|
268
282
|
sb = sandbox_at(agent.addr, **client_kwargs)
|
|
269
283
|
started.append((agent, sb))
|
|
270
284
|
return agent, sb
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import contextlib
|
|
4
4
|
import json
|
|
5
|
+
import select
|
|
5
6
|
import socket
|
|
6
7
|
import threading
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ import pytest
|
|
|
9
10
|
from cocoonsandbox import APIError, SandboxTimeout
|
|
10
11
|
from conftest import bounded, sandbox_at
|
|
11
12
|
|
|
13
|
+
PAUSE = 0.2
|
|
12
14
|
REPLIES = {"fs_mkdir": {"type": "done"}}
|
|
13
15
|
REJECT = b"HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 15\r\n\r\nunknown sandbox"
|
|
14
16
|
REJECT_JSON = (
|
|
@@ -75,3 +77,23 @@ def test_run_timeout_cuts_an_unanswered_upgrade(black_hole):
|
|
|
75
77
|
sb = sandbox_at(black_hole, timeout=60, keep_alive=0)
|
|
76
78
|
with pytest.raises(SandboxTimeout):
|
|
77
79
|
bounded(lambda: sb.run(["true"], timeout=0.2))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_run_feeds_stdin_only_after_the_101(script_server):
|
|
83
|
+
early: list[bool] = []
|
|
84
|
+
sb = sandbox_at(script_server(serve_a_late_101, early), timeout=5, keep_alive=0)
|
|
85
|
+
assert sb.run(["cat"], stdin=b"x") == 0
|
|
86
|
+
assert early == [False], "stdin left while the first recv could still retime the socket"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def serve_a_late_101(server: socket.socket, early: list[bool]) -> None:
|
|
90
|
+
conn, _ = server.accept()
|
|
91
|
+
with conn, contextlib.suppress(OSError):
|
|
92
|
+
seen = b""
|
|
93
|
+
while b"\n" not in seen.partition(b"\r\n\r\n")[2]:
|
|
94
|
+
seen += conn.recv(4096)
|
|
95
|
+
behind = seen.partition(b"\r\n\r\n")[2].partition(b"\n")[2]
|
|
96
|
+
early.append(bool(behind or select.select([conn], [], [], PAUSE)[0]))
|
|
97
|
+
conn.sendall(b'HTTP/1.1 101 Switching Protocols\r\n\r\n{"type":"started","pid":1}\n{"type":"exit","code":0}\n')
|
|
98
|
+
while conn.recv(4096):
|
|
99
|
+
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{cocoonstack_sandbox-0.1.32 → cocoonstack_sandbox-0.1.34}/cocoonstack_sandbox.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|