realServer turns the FakeIDP into a real http server.
(t testing.TB)
| 541 | |
| 542 | // realServer turns the FakeIDP into a real http server. |
| 543 | func (f *FakeIDP) realServer(t testing.TB) *httptest.Server { |
| 544 | t.Helper() |
| 545 | |
| 546 | srvURL := "localhost:0" |
| 547 | issURL, err := url.Parse(f.locked.Issuer()) |
| 548 | if err == nil { |
| 549 | if issURL.Hostname() == "localhost" || issURL.Hostname() == "127.0.0.1" { |
| 550 | srvURL = issURL.Host |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | l, err := net.Listen("tcp", srvURL) |
| 555 | require.NoError(t, err, "failed to create listener") |
| 556 | |
| 557 | ctx, cancel := context.WithCancel(context.Background()) |
| 558 | srv := &httptest.Server{ |
| 559 | Listener: l, |
| 560 | Config: &http.Server{Handler: f.locked.Handler(), ReadHeaderTimeout: time.Second * 5}, |
| 561 | } |
| 562 | |
| 563 | srv.Config.BaseContext = func(_ net.Listener) context.Context { |
| 564 | return ctx |
| 565 | } |
| 566 | srv.Start() |
| 567 | t.Cleanup(srv.CloseClientConnections) |
| 568 | t.Cleanup(srv.Close) |
| 569 | t.Cleanup(cancel) |
| 570 | |
| 571 | f.updateIssuerURL(t, srv.URL) |
| 572 | return srv |
| 573 | } |
| 574 | |
| 575 | // GenerateAuthenticatedToken skips all oauth2 flows, and just generates a |
| 576 | // valid token for some given claims. |
no test coverage detected