package sts import ( "net/http" "strconv" "testing" "time" "github.com/oauth2-proxy/mockoidc" "github.com/stretchr/testify/assert" "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" ) func TestServer(t *testing.T) { srv := web.NewOIDCServer(t) defer srv.Close() t.Run("New", func(t *testing.T) { server := New(t.Context()) t.Run("GET /", func(t *testing.T) { r, w := test.RequestResponse("GET", "/") server.ServeHTTP(w, r) assert.Equal(t, http.StatusNotFound, w.Code) }) t.Run("POST /oauth/token", func(t *testing.T) { code := strconv.FormatInt(time.Now().Unix(), 10) user := mockoidc.DefaultUser() srv.MockOIDC.QueueUser(user) srv.MockOIDC.QueueCode(code) r, w := test.RequestResponse("POST", "/oauth/token") server.ServeHTTP(w, r) assert.Equal(t, http.StatusCreated, w.Code) }) }) }