File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -352,7 +352,7 @@ export default class Socket {
352352 // Sec-WebSocket-Protocol based token
353353 // (longpoll uses Authorization header instead)
354354 if ( this . authToken ) {
355- protocols . push ( `base64url.bearer.authorization.phx.${ btoa ( this . authToken ) . replace ( "=" , "" ) } ` )
355+ protocols . push ( `base64url.bearer.authorization.phx.${ btoa ( this . authToken ) . replace ( / = / g , "" ) } ` )
356356 }
357357 this . conn = new this . transport ( this . endPointURL ( ) , protocols )
358358 this . conn . binaryType = this . binaryType
Original file line number Diff line number Diff line change @@ -7,7 +7,10 @@ const defaultRef = 1
77const defaultTimeout = 10000
88
99class WSMock {
10- constructor ( ) { }
10+ constructor ( url , protocols ) {
11+ this . url = url
12+ this . protocols = protocols
13+ }
1114 close ( ) { }
1215 send ( ) { }
1316}
@@ -58,6 +61,14 @@ describe("with transport", function (){
5861 expect ( joinPush . event ) . toBe ( "phx_join" )
5962 expect ( joinPush . timeout ) . toBe ( 1234 )
6063 } )
64+
65+ it ( "sets subprotocols when authToken is provided" , function ( ) {
66+ const authToken = "1234"
67+ const socket = new Socket ( "/socket" , { authToken} )
68+
69+ socket . connect ( )
70+ expect ( socket . conn . protocols ) . toEqual ( [ "phoenix" , "base64url.bearer.authorization.phx.MTIzNA" ] )
71+ } )
6172 } )
6273
6374 describe ( "updating join params" , function ( ) {
You can’t perform that action at this time.
0 commit comments