(t *testing.T)
| 248 | } |
| 249 | |
| 250 | func 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 | } |
nothing calls this directly
no test coverage detected