Skip to content

Commit 35dac5e

Browse files
committed
simple test
1 parent b4aa682 commit 35dac5e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

assets/js/phoenix/socket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

assets/test/channel_test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const defaultRef = 1
77
const defaultTimeout = 10000
88

99
class 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 (){

0 commit comments

Comments
 (0)