diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-18 14:42:36 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-18 14:42:36 -0600 |
| commit | 011fe0f9af046235cc25e87aaf25398db125a79f (patch) | |
| tree | 698c1570ccc8cd26cdf580858d584bb11f44d284 | |
| parent | 7db38ae743b025546202ea32651ad40a0c3c7d77 (diff) | |
Create a token creation endpointsts
| -rw-r--r-- | pkg/sts/server_test.go | 19 | ||||
| -rw-r--r-- | pkg/sts/sts.go | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/pkg/sts/server_test.go b/pkg/sts/server_test.go index ad8ff28..9c54475 100644 --- a/pkg/sts/server_test.go +++ b/pkg/sts/server_test.go @@ -2,13 +2,20 @@ 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()) @@ -18,5 +25,17 @@ func TestServer(t *testing.T) { 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) + }) }) } diff --git a/pkg/sts/sts.go b/pkg/sts/sts.go index ae75e8a..1030280 100644 --- a/pkg/sts/sts.go +++ b/pkg/sts/sts.go @@ -9,8 +9,13 @@ import ( ) func New(ctx context.Context) http.Handler { + mux := http.NewServeMux() + mux.HandleFunc("POST /oauth/token", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusCreated) + }) + return x.Middleware[http.Handler]( - http.NewServeMux(), + mux, log.HTTP(log.From(ctx)), ) } |
