Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mocks/mockServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newOIDCMockServer(customIssuer string) (*MockServer, error) {
CustomIssuer: customIssuer,
}

r.Use(verifyUserAgent)
r.Use(VerifyUserAgent)
r.HandleFunc("/.well-known/openid-configuration", mockServer.WellKnownHandler).Methods(http.MethodGet)
r.HandleFunc("/oauth2/certs", mockServer.JWKsHandlerInvalidAppTID).Methods(http.MethodGet).Headers("x-app_tid", InvalidAppTID)
r.HandleFunc("/oauth2/certs", mockServer.JWKsHandler).Methods(http.MethodGet)
Expand All @@ -102,7 +102,7 @@ func newOIDCMockServer(customIssuer string) (*MockServer, error) {
return mockServer, nil
}

func verifyUserAgent(next http.Handler) http.Handler {
func VerifyUserAgent(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("User-Agent") != httpclient.UserAgent {
w.WriteHeader(http.StatusBadRequest)
Expand Down
13 changes: 1 addition & 12 deletions tokenclient/tokenFlows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/gorilla/mux"
"github.com/sap/cloud-security-client-go/env"
"github.com/sap/cloud-security-client-go/httpclient"
"github.com/sap/cloud-security-client-go/mocks"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -174,7 +173,7 @@ func TestClientCredentialsTokenFlow_UsingMockServer_Succeeds(t *testing.T) {

func setupNewTLSServer(t *testing.T, f func(http.ResponseWriter, *http.Request)) *httptest.Server {
r := mux.NewRouter()
r.Use(verifyUserAgent)
r.Use(mocks.VerifyUserAgent)
r.HandleFunc("/oauth2/token", f).Methods(http.MethodPost).Headers("Content-Type", "application/x-www-form-urlencoded")
r.HandleFunc("/oauth/token", f).Methods(http.MethodPost).Headers("Content-Type", "application/x-www-form-urlencoded")

Expand All @@ -184,16 +183,6 @@ func setupNewTLSServer(t *testing.T, f func(http.ResponseWriter, *http.Request))
return httptest.NewTLSServer(r)
}

func verifyUserAgent(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("User-Agent") != httpclient.UserAgent {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("wrong user agent, expected: " + httpclient.UserAgent))
}
next.ServeHTTP(w, r)
})
}

// tokenHandler is the http handler which serves the /oauth2/token endpoint.
func tokenHandler(w http.ResponseWriter, r *http.Request) {
buf := new(bytes.Buffer)
Expand Down