@@ -184,6 +184,10 @@ impl Read for ProxyStream {
184184 println ! ( "READ {}: read {} bytes" , buf. len( ) , size) ;
185185 Ok ( size)
186186 }
187+ ProxyMsg :: ProxyError ( e) => Err ( std:: io:: Error :: new (
188+ ErrorKind :: InvalidData ,
189+ format ! ( "Proxy error: {e:?}" ) ,
190+ ) ) ,
187191 _ => Err ( std:: io:: Error :: new (
188192 ErrorKind :: InvalidData ,
189193 "unexpected response" ,
@@ -310,8 +314,8 @@ mod test {
310314
311315 #[ test]
312316 fn can_fetch_tls_content_with_local_stream ( ) {
313- let host = "api.turnkey .com" ;
314- let path = "/health " ;
317+ let host = "www.googleapis .com" ;
318+ let path = "/oauth2/v3/certs " ;
315319
316320 let mut stream = LocalStream :: new_by_name (
317321 host. to_string ( ) ,
@@ -322,7 +326,10 @@ mod test {
322326 . unwrap ( ) ;
323327 assert_eq ! ( stream. num_connections( ) , 1 ) ;
324328
325- assert_eq ! ( stream. remote_hostname, Some ( "api.turnkey.com" . to_string( ) ) ) ;
329+ assert_eq ! (
330+ stream. remote_hostname,
331+ Some ( "www.googleapis.com" . to_string( ) )
332+ ) ;
326333
327334 let root_store =
328335 RootCertStore { roots : webpki_roots:: TLS_SERVER_ROOTS . into ( ) } ;
@@ -348,19 +355,27 @@ mod test {
348355 let mut response_bytes = Vec :: new ( ) ;
349356 let read_to_end_result = tls. read_to_end ( & mut response_bytes) ;
350357
351- // Ignore eof errors: https://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof
352- assert ! (
353- read_to_end_result. is_ok( )
354- || ( read_to_end_result
355- . is_err_and( |e| e. kind( ) == ErrorKind :: UnexpectedEof ) )
356- ) ;
357- let response_text = std:: str:: from_utf8 ( & response_bytes) . unwrap ( ) ;
358- assert ! ( response_text. contains( "HTTP/1.1 200 OK" ) ) ;
359- assert ! ( response_text. contains( "currentTime" ) ) ;
358+ match read_to_end_result {
359+ Ok ( read_size) => {
360+ assert ! ( read_size > 0 ) ;
361+ // Close the connection
362+ let closed = stream. close ( ) ;
363+ assert ! ( closed. is_ok( ) ) ;
364+ }
365+ Err ( e) => {
366+ // Only EOF errors are expected. This means the connection was
367+ // closed by the remote server https://docs.rs/rustls/latest/rustls/manual/_03_howto/index.html#unexpected-eof
368+ assert_eq ! ( e. kind( ) , ErrorKind :: UnexpectedEof )
369+ }
370+ }
360371
361- let closed = stream . close ( ) ;
362- assert ! ( closed. is_ok ( ) ) ;
372+ // We should be at 0 connections in our proxy: either the remote
373+ // auto- closed (UnexpectedEof), or we did.
363374 assert_eq ! ( stream. num_connections( ) , 0 ) ;
375+
376+ let response_text = std:: str:: from_utf8 ( & response_bytes) . unwrap ( ) ;
377+ assert ! ( response_text. contains( "HTTP/1.1 200 OK" ) ) ;
378+ assert ! ( response_text. contains( "keys" ) ) ;
364379 }
365380
366381 /// Struct representing a stream, with direct access to the proxy.
@@ -447,6 +462,10 @@ mod test {
447462 println ! ( "READ {}: read {} bytes" , buf. len( ) , size) ;
448463 Ok ( size)
449464 }
465+ ProxyMsg :: ProxyError ( e) => Err ( std:: io:: Error :: new (
466+ ErrorKind :: InvalidData ,
467+ format ! ( "Proxy error: {e:?}" ) ,
468+ ) ) ,
450469 _ => Err ( std:: io:: Error :: new (
451470 ErrorKind :: InvalidData ,
452471 "unexpected response" ,
0 commit comments