Christian Weichel da4cafd5e5
Gitpod OIDC Identity Provider (#16482)
* Prototype IDP provider

* [gp cli] Add IDP commands

* [public-api] Remove zitadel based IDP implementation

* [gitpod-cli] Add IDP support for Vault

* [idp] Remove per-org IDP

* [idp] Add key cache and random key IDs

* [idp] Defer GetIDToken authorisation to server

* [idp] Add Redis public key cache

* [gitpod-cli] Hide IDP commands

* [idp] Add key ID to JWT

* [idp] Add unit tests

* [idp] Adress review comments

* [public-api-server] Use logging middleware globally

* [public-api-server] Simplify service registration

* [idp] Add Redis outage resilience
2023-03-03 17:11:01 +01:00

39 lines
1.1 KiB
Go

// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package middleware
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
"github.com/sirupsen/logrus"
_ "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
)
func TestLoggingMiddleware(t *testing.T) {
logInMemory := &bytes.Buffer{}
logger := logrus.New()
logger.SetOutput(logInMemory)
logger.SetFormatter(&logrus.JSONFormatter{})
expectedBody := `hello world`
someHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(expectedBody))
})
req := httptest.NewRequest("GET", "/", nil)
rec := httptest.NewRecorder() // this records the response
m := NewLoggingMiddleware()
wrappedHandler := m(someHandler)
wrappedHandler.ServeHTTP(rec, req)
require.HTTPStatusCode(t, someHandler, http.MethodGet, "/", nil, http.StatusOK)
require.HTTPBodyContains(t, someHandler, http.MethodGet, "/", nil, "hello")
}