@@ -79,29 +79,29 @@ async fn profile_rest_endpoint_keeps_body_placeholder(cx: &mut Context) -> testk
7979 allow ( & mut policy, server. port )
8080 . rest ( Access :: Full )
8181 . request_body_credential_rewrite ( false ) ;
82- let sandbox = create_sandbox ( cx, "rest" , policy, & provider) . await ?;
82+ let sandbox = create_sandbox ( cx, "rest" , policy, & [ & provider] ) . await ?;
8383 run_python ( & sandbox, BODY_CLIENT , server. port ) . await ?;
8484 expect_placeholder_body ( & server) . await
8585}
8686
8787/// A provider's WebSocket endpoint completes the handshake but doesn't
8888/// forward a binary frame, which the supervisor can't inspect for the
89- /// credential.
89+ /// credential. The same client in a sandbox without the provider gets its
90+ /// binary frame through, which shows the denial comes from the credential.
9091#[ testkit:: test]
9192async fn profile_websocket_endpoint_denies_binary_frames ( cx : & mut Context ) -> testkit:: Result {
9293 let server = HttpRecorder :: start ( "ok" ) . await ?;
9394 let websocket = WebSocketRecorder :: start ( ) . await ?;
9495 let provider = install_gating_provider ( cx, Some ( ( server. port , websocket. port ) ) ) . await ?;
9596
96- let mut policy = policy:: base ( ) ;
97- allow ( & mut policy, websocket. port ) . websocket ( Access :: ReadWrite ) ;
98- let sandbox = create_sandbox ( cx, "ws" , policy, & provider) . await ?;
99- run_python ( & sandbox, WEBSOCKET_CLIENT , websocket. port ) . await ?;
100- websocket
101- . wait_for_handshake ( )
102- . await
103- . context ( "upstream should receive the WebSocket handshake" ) ?;
104- let binary_seen = websocket. wait_until_finished ( ) . await ?;
97+ let control = WebSocketRecorder :: start ( ) . await ?;
98+ let binary_seen = send_binary_frame ( cx, "wsctl" , & control, & [ ] ) . await ?;
99+ testkit:: ensure!(
100+ binary_seen,
101+ "the binary frame didn't reach upstream from a sandbox without the provider"
102+ ) ;
103+
104+ let binary_seen = send_binary_frame ( cx, "ws" , & websocket, & [ & provider] ) . await ?;
105105 testkit:: ensure!(
106106 !binary_seen,
107107 "credentialed WebSocket binary frame reached upstream"
@@ -137,7 +137,7 @@ async fn policy_binding_requires_inspection_or_opt_in(cx: &mut Context) -> testk
137137 allow ( & mut opt_in, server. port )
138138 . allow_uninspected_credentials ( )
139139 . credential_binding ( & provider) ;
140- let sandbox = create_sandbox ( cx, "optin" , opt_in, & provider) . await ?;
140+ let sandbox = create_sandbox ( cx, "optin" , opt_in, & [ & provider] ) . await ?;
141141 sandbox. exec ( [ "true" ] ) . await ?. success ( ) ?;
142142 Ok ( ( ) )
143143}
@@ -156,7 +156,7 @@ async fn policy_binding_rest_body_keeps_placeholder_without_rewrite(
156156 . rest ( Access :: Full )
157157 . request_body_credential_rewrite ( false )
158158 . credential_binding ( & provider) ;
159- let sandbox = create_sandbox ( cx, "body" , policy, & provider) . await ?;
159+ let sandbox = create_sandbox ( cx, "body" , policy, & [ & provider] ) . await ?;
160160 run_python ( & sandbox, BODY_CLIENT , server. port ) . await ?;
161161 expect_placeholder_body ( & server) . await
162162}
@@ -175,7 +175,7 @@ async fn policy_binding_rest_body_rewrite_sends_secret_upstream(
175175 . rest ( Access :: Full )
176176 . request_body_credential_rewrite ( true )
177177 . credential_binding ( & provider) ;
178- let sandbox = create_sandbox ( cx, "rw" , policy, & provider) . await ?;
178+ let sandbox = create_sandbox ( cx, "rw" , policy, & [ & provider] ) . await ?;
179179 run_python ( & sandbox, BODY_CLIENT , server. port ) . await ?;
180180 let request = one_request ( & server) . await ?;
181181 testkit:: ensure!(
@@ -205,7 +205,7 @@ async fn policy_binding_updates_provider_environment_live(cx: &mut Context) -> t
205205 } ;
206206 let ( unbound, bound) = ( policy_binding ( false ) , policy_binding ( true ) ) ;
207207
208- let sandbox = create_sandbox ( cx, "live" , unbound. clone ( ) , & provider) . await ?;
208+ let sandbox = create_sandbox ( cx, "live" , unbound. clone ( ) , & [ & provider] ) . await ?;
209209 wait_for_token ( & sandbox, "TOKEN_ABSENT" ) . await ?;
210210
211211 set_policy ( cx, & sandbox, & bound)
@@ -219,6 +219,25 @@ async fn policy_binding_updates_provider_environment_live(cx: &mut Context) -> t
219219 wait_for_token ( & sandbox, "TOKEN_ABSENT" ) . await
220220}
221221
222+ /// Run [`WEBSOCKET_CLIENT`] against `server` in a sandbox with `providers`,
223+ /// and return whether its binary frame reached `server`.
224+ async fn send_binary_frame (
225+ cx : & Context ,
226+ suffix : & str ,
227+ server : & WebSocketRecorder ,
228+ providers : & [ & str ] ,
229+ ) -> Result < bool > {
230+ let mut policy = policy:: base ( ) ;
231+ allow ( & mut policy, server. port ) . websocket ( Access :: ReadWrite ) ;
232+ let sandbox = create_sandbox ( cx, suffix, policy, providers) . await ?;
233+ run_python ( & sandbox, WEBSOCKET_CLIENT , server. port ) . await ?;
234+ server
235+ . wait_for_handshake ( )
236+ . await
237+ . context ( "upstream should receive the WebSocket handshake" ) ?;
238+ server. wait_until_finished ( ) . await
239+ }
240+
222241/// Let the image's Python reach `TEST_HOST` on `port`.
223242fn allow ( policy : & mut proto:: SandboxPolicy , port : u16 ) -> & mut proto:: NetworkEndpoint {
224243 policy:: allow (
@@ -274,26 +293,26 @@ fn sandbox_with(
274293 cx : & Context ,
275294 suffix : & str ,
276295 policy : proto:: SandboxPolicy ,
277- provider : & str ,
296+ providers : & [ & str ] ,
278297) -> testkit:: SandboxBuilder {
279298 cx. sandbox ( suffix)
280299 . policy ( policy)
281300 . spec ( |spec| {
282301 spec. image = Some ( testkit:: python_image ( ) ) ;
283- spec. providers = vec ! [ provider . to_string( ) ] ;
302+ spec. providers = providers . iter ( ) . map ( ToString :: to_string) . collect ( ) ;
284303 } )
285304 . command ( [ "sleep" , "infinity" ] )
286305}
287306
288307/// Create a long-running sandbox from the Python image with `policy` and
289- /// `provider `, and wait until it is Ready.
308+ /// `providers `, and wait until it is Ready.
290309async fn create_sandbox (
291310 cx : & Context ,
292311 suffix : & str ,
293312 policy : proto:: SandboxPolicy ,
294- provider : & str ,
313+ providers : & [ & str ] ,
295314) -> Result < Sandbox > {
296- let sandbox = sandbox_with ( cx, suffix, policy, provider ) . create ( ) . await ?;
315+ let sandbox = sandbox_with ( cx, suffix, policy, providers ) . create ( ) . await ?;
297316 sandbox. wait_ready ( ) . await ?;
298317 Ok ( sandbox)
299318}
@@ -306,7 +325,7 @@ async fn expect_rejected(
306325 policy : proto:: SandboxPolicy ,
307326 provider : & str ,
308327) -> Result < String > {
309- match sandbox_with ( cx, suffix, policy, provider) . create ( ) . await {
328+ match sandbox_with ( cx, suffix, policy, & [ provider] ) . create ( ) . await {
310329 Ok ( sandbox) => Err ( Error :: msg ( format ! (
311330 "the gateway accepted sandbox {}" ,
312331 sandbox. name( )
0 commit comments