diff options
Diffstat (limited to 'pkg/web/middleware/user_test.go')
| -rw-r--r-- | pkg/web/middleware/user_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/web/middleware/user_test.go b/pkg/web/middleware/user_test.go new file mode 100644 index 0000000..7119b41 --- /dev/null +++ b/pkg/web/middleware/user_test.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key" + "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" +) + +func TestUser(t *testing.T) { + middleware := User() + + t.Run("when an ID Token is found in the context", func(t *testing.T) { + t.Run("When the user is found in the db", func(t *testing.T) { + + }) + + t.Run("when the user is not found in the db", func(t *testing.T) { + + }) + }) + + t.Run("when an ID Token is not found in the context", func(t *testing.T) { + server := middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + user := key.CurrentUser.From(r.Context()) + require.Nil(t, user) + + w.WriteHeader(http.StatusTeapot) + })) + + r, w := test.RequestResponse("GET", "/example") + server.ServeHTTP(w, r) + + assert.Equal(t, http.StatusTeapot, w.Code) + }) +} |
