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

Function Test_verifyHostOverride

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

Source from the content-addressed store, hash-verified

124}
125
126func Test_verifyHostOverride(t *testing.T) {
127 testCases := []struct {
128 name string
129 host string
130 exp string
131 }{
132 {
133 name: "noOverride",
134 host: "",
135 exp: "example.com",
136 },
137 {
138 name: "hostOverride",
139 host: "example.net",
140 exp: "example.net",
141 },
142 }
143
144 for _, tc := range testCases {
145 tc := tc
146 t.Run(tc.name, func(t *testing.T) {
147 t.Parallel()
148
149 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
150 defer cancel()
151
152 rt := func(r *http.Request) (*http.Response, error) {
153 assert.Equal(t, "Host", tc.exp, r.Host)
154
155 h := http.Header{}
156 h.Set("Connection", "Upgrade")
157 h.Set("Upgrade", "websocket")
158 h.Set("Sec-WebSocket-Accept", websocket.SecWebSocketAccept(r.Header.Get("Sec-WebSocket-Key")))
159
160 return &http.Response{
161 StatusCode: http.StatusSwitchingProtocols,
162 Header: h,
163 Body: mockBody{bytes.NewBufferString("hi")},
164 }, nil
165 }
166
167 c, _, err := websocket.Dial(ctx, "ws://example.com", &websocket.DialOptions{
168 HTTPClient: mockHTTPClient(rt),
169 Host: tc.host,
170 })
171 assert.Success(t, err)
172 c.CloseNow()
173 })
174 }
175}
176
177type mockBody struct {
178 *bytes.Buffer

Callers

nothing calls this directly

Calls 5

EqualFunction · 0.92
DialFunction · 0.92
SuccessFunction · 0.92
mockHTTPClientFunction · 0.85
CloseNowMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…