Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions pkg/oidc/check/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package check_test
import (
"context"
"fmt"
"net"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
Expand All @@ -21,7 +21,7 @@ import (
)

type TestProvider struct {
srv *http.Server
srv *httptest.Server
URL string
RequestedScopes []string
GenClaims func() jwt.Claims
Expand All @@ -38,17 +38,7 @@ func (tp TestProvider) genToken() string {
}

func (tp *TestProvider) Start() error {
listener, err := net.Listen("tcp", "127.0.0.1:8765")
if err != nil {
return fmt.Errorf("failed starting listener: %w", err)
}

tp.URL = fmt.Sprintf("http://%s", listener.Addr().String())
mux := http.ServeMux{}
tp.srv = &http.Server{
Handler: &mux,
ReadHeaderTimeout: 5 * time.Second,
}
mux := &http.ServeMux{}

mux.HandleFunc("/.well-known/openid-configuration", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("content-type", "application/json")
Expand All @@ -72,13 +62,14 @@ func (tp *TestProvider) Start() error {
}`, tp.genToken())
})

go tp.srv.Serve(listener)
tp.srv = httptest.NewServer(mux)
tp.URL = tp.srv.URL

return nil
}

func (tp TestProvider) Shutdown() {
tp.srv.Shutdown(context.Background())
tp.srv.Close()
}

func (tp TestProvider) IssuerURL() string {
Expand Down