MCPcopy Index your code
hub / github.com/coder/coder / TestDERPForceWebSockets

Function TestDERPForceWebSockets

coderd/coderd_test.go:147–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestDERPForceWebSockets(t *testing.T) {
148 t.Parallel()
149
150 dv := coderdtest.DeploymentValues(t)
151 dv.DERP.Config.ForceWebSockets = true
152 dv.DERP.Config.BlockDirect = true // to ensure the test always uses DERP
153
154 // Manually create a server so we can influence the HTTP handler.
155 options := &coderdtest.Options{
156 DeploymentValues: dv,
157 }
158 setHandler, cancelFunc, serverURL, newOptions := coderdtest.NewOptions(t, options)
159 coderAPI := coderd.New(newOptions)
160 t.Cleanup(func() {
161 cancelFunc()
162 _ = coderAPI.Close()
163 })
164
165 // Set the HTTP handler to a custom one that ensures all /derp calls are
166 // WebSockets and not `Upgrade: derp`.
167 var upgradeCount atomic.Int64
168 setHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
169 if strings.HasPrefix(r.URL.Path, "/derp") {
170 up := r.Header.Get("Upgrade")
171 if up != "" && up != "websocket" {
172 t.Errorf("expected Upgrade: websocket, got %q", up)
173 } else {
174 upgradeCount.Add(1)
175 }
176 }
177
178 coderAPI.RootHandler.ServeHTTP(rw, r)
179 }))
180
181 // Start a provisioner daemon.
182 provisionerCloser := coderdtest.NewProvisionerDaemon(t, coderAPI)
183 t.Cleanup(func() {
184 _ = provisionerCloser.Close()
185 })
186
187 client := codersdk.New(serverURL, codersdk.WithHTTPClient(coderdtest.NewIsolatedHTTPClient(serverURL)))
188 t.Cleanup(func() {
189 client.HTTPClient.CloseIdleConnections()
190 })
191 wsclient := workspacesdk.New(client)
192 user := coderdtest.CreateFirstUser(t, client)
193
194 gen, err := wsclient.AgentConnectionInfoGeneric(context.Background())
195 require.NoError(t, err)
196 t.Log(spew.Sdump(gen))
197
198 authToken := uuid.NewString()
199 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
200 Parse: echo.ParseComplete,
201 ProvisionPlan: echo.PlanComplete,
202 ProvisionGraph: echo.ProvisionGraphWithAgent(authToken),
203 })
204 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

Callers

nothing calls this directly

Calls 15

DeploymentValuesFunction · 0.92
NewOptionsFunction · 0.92
NewFunction · 0.92
NewProvisionerDaemonFunction · 0.92
NewFunction · 0.92
WithHTTPClientFunction · 0.92
NewIsolatedHTTPClientFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
ProvisionGraphWithAgentFunction · 0.92
CreateTemplateFunction · 0.92

Tested by

no test coverage detected