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

Function TestResolveIssuer

coderd/authlink/authlink_test.go:250–305  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

248}
249
250func TestResolveIssuer(t *testing.T) {
251 t.Parallel()
252
253 t.Run("Success", func(t *testing.T) {
254 t.Parallel()
255 ctx := testutil.Context(t, testutil.WaitShort)
256
257 const expectedIssuer = "https://accounts.google.com"
258 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
259 if r.URL.Path != "/.well-known/openid-configuration" {
260 http.NotFound(w, r)
261 return
262 }
263 w.Header().Set("Content-Type", "application/json")
264 _ = json.NewEncoder(w).Encode(map[string]string{
265 "issuer": expectedIssuer,
266 })
267 }))
268 defer srv.Close()
269
270 issuer, err := authlink.ResolveIssuer(ctx, srv.Client(), srv.URL)
271 require.NoError(t, err)
272 require.Equal(t, expectedIssuer, issuer)
273 })
274
275 t.Run("EmptyIssuer", func(t *testing.T) {
276 t.Parallel()
277 ctx := testutil.Context(t, testutil.WaitShort)
278
279 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
280 w.Header().Set("Content-Type", "application/json")
281 _ = json.NewEncoder(w).Encode(map[string]string{
282 "issuer": "",
283 })
284 }))
285 defer srv.Close()
286
287 _, err := authlink.ResolveIssuer(ctx, srv.Client(), srv.URL)
288 require.Error(t, err)
289 require.Contains(t, err.Error(), "empty issuer")
290 })
291
292 t.Run("HTTPError", func(t *testing.T) {
293 t.Parallel()
294 ctx := testutil.Context(t, testutil.WaitShort)
295
296 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
297 w.WriteHeader(http.StatusInternalServerError)
298 }))
299 defer srv.Close()
300
301 _, err := authlink.ResolveIssuer(ctx, srv.Client(), srv.URL)
302 require.Error(t, err)
303 require.Contains(t, err.Error(), "HTTP 500")
304 })
305}

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
ClientMethod · 0.95
ContextFunction · 0.92
ResolveIssuerFunction · 0.92
EncodeMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65
HeaderMethod · 0.45
EqualMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected