@@ -25,9 +25,10 @@ use openshell_core::proto::{
2525 ListSandboxesResponse , PlatformEvent , Provider , ProviderResponse , RevokeSshSessionRequest ,
2626 RevokeSshSessionResponse , Sandbox , SandboxCondition , SandboxLogLine , SandboxPhase ,
2727 SandboxResponse , SandboxStatus , SandboxStreamEvent , SandboxTemplateResponse ,
28- SandboxWorkloadTemplate , ServiceStatus , SettingValue , TcpForwardFrame , TcpForwardInit ,
29- TcpRelayTarget , UpdateProviderRequest , WatchSandboxRequest , sandbox_stream_event,
30- tcp_forward_frame, tcp_forward_init,
28+ SandboxWorkloadTemplate , ServiceAuthorizationMode , ServiceBackendHttpVersion , ServiceEndpoint ,
29+ ServiceStatus , SettingValue , TcpForwardFrame , TcpForwardInit , TcpRelayTarget ,
30+ UpdateProviderRequest , WatchSandboxRequest , sandbox_stream_event, tcp_forward_frame,
31+ tcp_forward_init,
3132} ;
3233use openshell_server:: test_support:: grpc:: open_shell_server:: { OpenShell , OpenShellServer } ;
3334use std:: collections:: HashMap ;
@@ -69,6 +70,7 @@ struct SandboxState {
6970 /// The policy `GetSandboxConfig` returns.
7071 sandbox_config_policy : Arc < Mutex < Option < openshell_core:: proto:: SandboxPolicy > > > ,
7172 expose_service_requests : Arc < Mutex < Vec < openshell_core:: proto:: ExposeServiceRequest > > > ,
73+ expose_service_supports_http2 : Arc < AtomicBool > ,
7274 fail_delete_sandbox_message : Arc < Mutex < Option < String > > > ,
7375 stop_response : Arc < Mutex < Option < Sandbox > > > ,
7476 vm_error_after_started : Arc < AtomicBool > ,
@@ -449,17 +451,26 @@ impl OpenShell for TestOpenShell {
449451 & self ,
450452 request : tonic:: Request < openshell_core:: proto:: ExposeServiceRequest > ,
451453 ) -> Result < Response < openshell_core:: proto:: ServiceEndpointResponse > , Status > {
454+ let request = request. into_inner ( ) ;
455+ let mut endpoint = ServiceEndpoint :: default ( ) ;
456+ if self
457+ . state
458+ . expose_service_supports_http2
459+ . load ( Ordering :: SeqCst )
460+ {
461+ endpoint. backend_http_version = request. backend_http_version ;
462+ }
452463 self . state
453464 . expose_service_requests
454465 . lock ( )
455466 . await
456- . push ( request. into_inner ( ) ) ;
467+ . push ( request) ;
457468 Ok ( Response :: new (
458469 openshell_core:: proto:: ServiceEndpointResponse {
459470 application_url : String :: new ( ) ,
460471 gateway_url : String :: new ( ) ,
461472 url : "https://default--sandbox.openshell.localhost:17670/" . to_string ( ) ,
462- .. Default :: default ( )
473+ endpoint : Some ( endpoint ) ,
463474 } ,
464475 ) )
465476 }
@@ -2862,8 +2873,7 @@ async fn sandbox_create_exposes_service_after_ready_and_keeps_sandbox() {
28622873 name : Some ( "sandbox" ) ,
28632874 keep : false ,
28642875 expose : Some ( 4500 ) ,
2865- expose_authorization_mode :
2866- openshell_core:: proto:: ServiceAuthorizationMode :: BearerPassthrough ,
2876+ expose_authorization_mode : ServiceAuthorizationMode :: BearerPassthrough ,
28672877 detach : true ,
28682878 ..test_config ( )
28692879 } ,
@@ -2881,7 +2891,7 @@ async fn sandbox_create_exposes_service_after_ready_and_keeps_sandbox() {
28812891 assert_eq ! ( create_requests[ 0 ] . service_exposures[ 0 ] . target_port, 4500 ) ;
28822892 assert_eq ! (
28832893 create_requests[ 0 ] . service_exposures[ 0 ] . authorization_mode( ) ,
2884- openshell_core :: proto :: ServiceAuthorizationMode :: BearerPassthrough
2894+ ServiceAuthorizationMode :: BearerPassthrough
28852895 ) ;
28862896 assert ! ( expose_service_requests( & server) . await . is_empty( ) ) ;
28872897 } )
@@ -2898,7 +2908,8 @@ async fn service_expose_forwards_bearer_passthrough_mode() {
28982908 "sandbox" ,
28992909 "codex" ,
29002910 4500 ,
2901- openshell_core:: proto:: ServiceAuthorizationMode :: BearerPassthrough ,
2911+ ServiceAuthorizationMode :: BearerPassthrough ,
2912+ ServiceBackendHttpVersion :: Http1 ,
29022913 "default" ,
29032914 & tls,
29042915 )
@@ -2909,7 +2920,46 @@ async fn service_expose_forwards_bearer_passthrough_mode() {
29092920 assert_eq ! ( requests. len( ) , 1 ) ;
29102921 assert_eq ! (
29112922 requests[ 0 ] . authorization_mode( ) ,
2912- openshell_core:: proto:: ServiceAuthorizationMode :: BearerPassthrough
2923+ ServiceAuthorizationMode :: BearerPassthrough
2924+ ) ;
2925+ }
2926+
2927+ #[ tokio:: test]
2928+ async fn service_expose_requires_gateway_confirmation_for_http2 ( ) {
2929+ let server = run_server ( ) . await ;
2930+ let tls = test_tls ( & server) ;
2931+ let expose = || {
2932+ run:: service_expose (
2933+ & server. endpoint ,
2934+ "sandbox" ,
2935+ "agent" ,
2936+ 50051 ,
2937+ ServiceAuthorizationMode :: Strip ,
2938+ ServiceBackendHttpVersion :: Http2 ,
2939+ "default" ,
2940+ & tls,
2941+ )
2942+ } ;
2943+
2944+ let error = expose ( ) . await . unwrap_err ( ) ;
2945+ assert ! (
2946+ error
2947+ . to_string( )
2948+ . contains( "did not confirm the HTTP/2 backend" )
2949+ ) ;
2950+
2951+ server
2952+ . openshell
2953+ . state
2954+ . expose_service_supports_http2
2955+ . store ( true , Ordering :: SeqCst ) ;
2956+ expose ( ) . await . expect ( "gateway confirmed HTTP/2" ) ;
2957+
2958+ let requests = expose_service_requests ( & server) . await ;
2959+ assert_eq ! ( requests. len( ) , 2 ) ;
2960+ assert_eq ! (
2961+ requests[ 0 ] . backend_http_version( ) ,
2962+ ServiceBackendHttpVersion :: Http2
29132963 ) ;
29142964}
29152965
0 commit comments