@@ -95,7 +95,7 @@ use itertools::Itertools;
9595use mz_environmentd:: http:: {
9696 BecomeLeaderResponse , BecomeLeaderResult , LeaderStatus , LeaderStatusResponse ,
9797} ;
98- use mz_environmentd:: WebSocketResponse ;
98+ use mz_environmentd:: { WebSocketAuth , WebSocketResponse } ;
9999use mz_ore:: cast:: CastFrom ;
100100use mz_ore:: cast:: CastLossy ;
101101use mz_ore:: cast:: TryCastFrom ;
@@ -2117,25 +2117,38 @@ fn test_internal_ws_auth() {
21172117
21182118 // Create our WebSocket.
21192119 let ws_url = server. internal_ws_addr ( ) ;
2120- let req = Request :: builder ( )
2121- . uri ( ws_url. as_str ( ) )
2122- . method ( "GET" )
2123- . header ( "Host" , ws_url. host_str ( ) . unwrap ( ) )
2124- . header ( "Connection" , "Upgrade" )
2125- . header ( "Upgrade" , "websocket" )
2126- . header ( "Sec-WebSocket-Version" , "13" )
2127- . header ( "Sec-WebSocket-Key" , "foobar" )
2128- // Set our user to the mz_support user
2129- . header ( "x-materialize-user" , "mz_support" )
2130- . body ( ( ) )
2131- . unwrap ( ) ;
2120+ let make_req = || {
2121+ Request :: builder ( )
2122+ . uri ( ws_url. as_str ( ) )
2123+ . method ( "GET" )
2124+ . header ( "Host" , ws_url. host_str ( ) . unwrap ( ) )
2125+ . header ( "Connection" , "Upgrade" )
2126+ . header ( "Upgrade" , "websocket" )
2127+ . header ( "Sec-WebSocket-Version" , "13" )
2128+ . header ( "Sec-WebSocket-Key" , "foobar" )
2129+ // Set our user to the mz_support user
2130+ . header ( "x-materialize-user" , "mz_support" )
2131+ . body ( ( ) )
2132+ . unwrap ( )
2133+ } ;
21322134
2133- let ( mut ws, _resp) = tungstenite:: connect ( req ) . unwrap ( ) ;
2135+ let ( mut ws, _resp) = tungstenite:: connect ( make_req ( ) ) . unwrap ( ) ;
21342136 let options = BTreeMap :: from ( [ (
21352137 "application_name" . to_string ( ) ,
21362138 "billion_dollar_idea" . to_string ( ) ,
21372139 ) ] ) ;
2138- util:: auth_with_ws ( & mut ws, options) . unwrap ( ) ;
2140+ // We should receive error if sending the standard bearer auth, since that is unexpected
2141+ // for the Internal HTTP API
2142+ assert_eq ! ( util:: auth_with_ws( & mut ws, options. clone( ) ) . is_err( ) , true ) ;
2143+
2144+ // Recreate the websocket
2145+ let ( mut ws, _resp) = tungstenite:: connect ( make_req ( ) ) . unwrap ( ) ;
2146+ // Auth with OptionsOnly
2147+ util:: auth_with_ws_impl (
2148+ & mut ws,
2149+ Message :: Text ( serde_json:: to_string ( & WebSocketAuth :: OptionsOnly { options } ) . unwrap ( ) ) ,
2150+ )
2151+ . unwrap ( ) ;
21392152
21402153 // Query to make sure we get back the correct user, which should be
21412154 // set from the headers passed with the websocket request.
0 commit comments