MCPcopy
hub / github.com/coder/websocket / Test_verifyServerHandshake

Function Test_verifyServerHandshake

dial_test.go:185–297  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

183}
184
185func Test_verifyServerHandshake(t *testing.T) {
186 t.Parallel()
187
188 testCases := []struct {
189 name string
190 response func(w http.ResponseWriter)
191 success bool
192 }{
193 {
194 name: "badStatus",
195 response: func(w http.ResponseWriter) {
196 w.WriteHeader(http.StatusOK)
197 },
198 success: false,
199 },
200 {
201 name: "badConnection",
202 response: func(w http.ResponseWriter) {
203 w.Header().Set("Connection", "???")
204 w.WriteHeader(http.StatusSwitchingProtocols)
205 },
206 success: false,
207 },
208 {
209 name: "badUpgrade",
210 response: func(w http.ResponseWriter) {
211 w.Header().Set("Connection", "Upgrade")
212 w.Header().Set("Upgrade", "???")
213 w.WriteHeader(http.StatusSwitchingProtocols)
214 },
215 success: false,
216 },
217 {
218 name: "badSecWebSocketAccept",
219 response: func(w http.ResponseWriter) {
220 w.Header().Set("Connection", "Upgrade")
221 w.Header().Set("Upgrade", "websocket")
222 w.Header().Set("Sec-WebSocket-Accept", "xd")
223 w.WriteHeader(http.StatusSwitchingProtocols)
224 },
225 success: false,
226 },
227 {
228 name: "badSecWebSocketProtocol",
229 response: func(w http.ResponseWriter) {
230 w.Header().Set("Connection", "Upgrade")
231 w.Header().Set("Upgrade", "websocket")
232 w.Header().Set("Sec-WebSocket-Protocol", "xd")
233 w.WriteHeader(http.StatusSwitchingProtocols)
234 },
235 success: false,
236 },
237 {
238 name: "unsupportedExtension",
239 response: func(w http.ResponseWriter) {
240 w.Header().Set("Connection", "Upgrade")
241 w.Header().Set("Upgrade", "websocket")
242 w.Header().Set("Sec-WebSocket-Extensions", "meow")

Callers

nothing calls this directly

Calls 2

SuccessFunction · 0.92
ErrorFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…