summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/sts/server_test.go19
-rw-r--r--pkg/sts/sts.go7
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)),
)
}