@@ -185,6 +185,14 @@ func Test_verifyClientHandshake(t *testing.T) {
185185 },
186186 {
187187 name : "missingWebSocketKey" ,
188+ h : map [string ]string {
189+ "Connection" : "Upgrade" ,
190+ "Upgrade" : "websocket" ,
191+ "Sec-WebSocket-Version" : "13" ,
192+ },
193+ },
194+ {
195+ name : "emptyWebSocketKey" ,
188196 h : map [string ]string {
189197 "Connection" : "Upgrade" ,
190198 "Upgrade" : "websocket" ,
@@ -210,6 +218,18 @@ func Test_verifyClientHandshake(t *testing.T) {
210218 "Sec-WebSocket-Key" : "notbase64" ,
211219 },
212220 },
221+ {
222+ name : "extraWebSocketKey" ,
223+ h : map [string ]string {
224+ "Connection" : "Upgrade" ,
225+ "Upgrade" : "websocket" ,
226+ "Sec-WebSocket-Version" : "13" ,
227+ // Kinda cheeky, but http headers are case-insensitive.
228+ // If 2 sec keys are present, this is a failure condition.
229+ "Sec-WebSocket-Key" : xrand .Base64 (16 ),
230+ "sec-webSocket-key" : xrand .Base64 (16 ),
231+ },
232+ },
213233 {
214234 name : "badHTTPVersion" ,
215235 h : map [string ]string {
@@ -256,7 +276,7 @@ func Test_verifyClientHandshake(t *testing.T) {
256276 }
257277
258278 for k , v := range tc .h {
259- r .Header .Set (k , v )
279+ r .Header .Add (k , v )
260280 }
261281
262282 _ , err := verifyClientRequest (httptest .NewRecorder (), r )
0 commit comments