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

Method realServer

coderd/coderdtest/oidctest/idp.go:543–573  ·  view source on GitHub ↗

realServer turns the FakeIDP into a real http server.

(t testing.TB)

Source from the content-addressed store, hash-verified

541
542// realServer turns the FakeIDP into a real http server.
543func (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.

Callers 1

NewFakeIDPFunction · 0.95

Calls 8

StartMethod · 0.95
updateIssuerURLMethod · 0.95
IssuerMethod · 0.80
HelperMethod · 0.65
ParseMethod · 0.65
ListenMethod · 0.65
CleanupMethod · 0.65
HandlerMethod · 0.45

Tested by

no test coverage detected