Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(65)

Side by Side Diff: src/pkg/websocket/websocket_test.go

Issue 5318072: code review 5318072: websocket: return an error HTTP response for bad websoc... (Closed)
Patch Set: diff -r 19bc41642ed8 https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/websocket/server.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package websocket 5 package websocket
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "http" 10 "http"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 t.Errorf("WebSocket handshake: %v", err) 193 t.Errorf("WebSocket handshake: %v", err)
194 return 194 return
195 } 195 }
196 ws.Close() 196 ws.Close()
197 } 197 }
198 198
199 func TestHTTP(t *testing.T) { 199 func TestHTTP(t *testing.T) {
200 once.Do(startServer) 200 once.Do(startServer)
201 201
202 // If the client did not send a handshake that matches the protocol 202 // If the client did not send a handshake that matches the protocol
203 » // specification, the server should abort the WebSocket connection. 203 » // specification, the server MUST return an HTTP respose with an
204 » _, err := http.Get(fmt.Sprintf("http://%s/echo", serverAddr)) 204 » // appropriate error code (such as 400 Bad Request)
205 » if err == nil { 205 » resp, err := http.Get(fmt.Sprintf("http://%s/echo", serverAddr))
206 » » t.Error("Get: unexpected success") 206 » if err != nil {
207 » » return
208 » }
209 » urlerr, ok := err.(*url.Error)
210 » if !ok {
211 » » t.Errorf("Get: not url.Error %#v", err)
212 » » return
213 » }
214 » if urlerr.Err != io.ErrUnexpectedEOF {
215 t.Errorf("Get: error %#v", err) 207 t.Errorf("Get: error %#v", err)
216 return 208 return
217 } 209 }
210 if resp == nil {
211 t.Error("Get: resp is null")
212 return
213 }
214 if resp.StatusCode != http.StatusBadRequest {
215 t.Errorf("Get: expected %q got %q", http.StatusBadRequest, resp. StatusCode)
216 }
218 } 217 }
219 218
220 func TestTrailingSpaces(t *testing.T) { 219 func TestTrailingSpaces(t *testing.T) {
221 // http://code.google.com/p/go/issues/detail?id=955 220 // http://code.google.com/p/go/issues/detail?id=955
222 // The last runs of this create keys with trailing spaces that should no t be 221 // The last runs of this create keys with trailing spaces that should no t be
223 // generated by the client. 222 // generated by the client.
224 once.Do(startServer) 223 once.Do(startServer)
225 config := newConfig(t, "/echo") 224 config := newConfig(t, "/echo")
226 for i := 0; i < 30; i++ { 225 for i := 0; i < 30; i++ {
227 // body 226 // body
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 n, err = conn.Read(second_msg) 265 n, err = conn.Read(second_msg)
267 if err != nil { 266 if err != nil {
268 t.Errorf("Read: %v", err) 267 t.Errorf("Read: %v", err)
269 } 268 }
270 second_msg = second_msg[0:n] 269 second_msg = second_msg[0:n]
271 if !bytes.Equal(msg[len(small_msg):], second_msg) { 270 if !bytes.Equal(msg[len(small_msg):], second_msg) {
272 t.Errorf("Echo: expected %q got %q", msg[len(small_msg):], secon d_msg) 271 t.Errorf("Echo: expected %q got %q", msg[len(small_msg):], secon d_msg)
273 } 272 }
274 conn.Close() 273 conn.Close()
275 } 274 }
OLDNEW
« no previous file with comments | « src/pkg/websocket/server.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b