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

Function TestExternalAuthParam

coderd/httpmw/externalauthparam_test.go:17–49  ·  view source on GitHub ↗

nolint:bodyclose

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16//nolint:bodyclose
17func TestExternalAuthParam(t *testing.T) {
18 t.Parallel()
19 t.Run("Found", func(t *testing.T) {
20 t.Parallel()
21 routeCtx := chi.NewRouteContext()
22 routeCtx.URLParams.Add("externalauth", "my-id")
23 r := httptest.NewRequest(http.MethodGet, "/", nil)
24 r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx))
25 res := httptest.NewRecorder()
26
27 httpmw.ExtractExternalAuthParam([]*externalauth.Config{{
28 ID: "my-id",
29 }})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30 require.Equal(t, "my-id", httpmw.ExternalAuthParam(r).ID)
31 w.WriteHeader(http.StatusOK)
32 })).ServeHTTP(res, r)
33
34 require.Equal(t, http.StatusOK, res.Result().StatusCode)
35 })
36
37 t.Run("NotFound", func(t *testing.T) {
38 t.Parallel()
39 routeCtx := chi.NewRouteContext()
40 routeCtx.URLParams.Add("externalauth", "my-id")
41 r := httptest.NewRequest(http.MethodGet, "/", nil)
42 r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx))
43 res := httptest.NewRecorder()
44
45 httpmw.ExtractExternalAuthParam([]*externalauth.Config{})(nil).ServeHTTP(res, r)
46
47 require.Equal(t, http.StatusNotFound, res.Result().StatusCode)
48 })
49}

Callers

nothing calls this directly

Calls 10

ExtractExternalAuthParamFunction · 0.92
ExternalAuthParamFunction · 0.92
WithContextMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
ContextMethod · 0.65
ServeHTTPMethod · 0.45
EqualMethod · 0.45
WriteHeaderMethod · 0.45
ResultMethod · 0.45

Tested by

no test coverage detected