Skip to content
Snippets Groups Projects
Commit 63e9defc authored by Rohith Jayawardene's avatar Rohith Jayawardene Committed by Rohith
Browse files

Debug Handler Unit Tests (#223)

- adding unit tests for the debug handlers
parent fd263515
No related branches found
No related tags found
No related merge requests found
...@@ -416,6 +416,7 @@ func (r *oauthProxy) healthHandler(cx echo.Context) error { ...@@ -416,6 +416,7 @@ func (r *oauthProxy) healthHandler(cx echo.Context) error {
// debugHandler is responsible for providing the pprof // debugHandler is responsible for providing the pprof
func (r *oauthProxy) debugHandler(cx echo.Context) error { func (r *oauthProxy) debugHandler(cx echo.Context) error {
r.revokeProxy(cx)
name := cx.Param("name") name := cx.Param("name")
switch cx.Request().Method { switch cx.Request().Method {
case http.MethodGet: case http.MethodGet:
......
...@@ -21,6 +21,25 @@ import ( ...@@ -21,6 +21,25 @@ import (
"time" "time"
) )
func TestDebugHandler(t *testing.T) {
c := newFakeKeycloakConfig()
c.Resources = make([]*Resource, 0)
c.EnableProfiling = true
requests := []fakeRequest{
{URI: "/debug/pprof/no_there", ExpectedCode: http.StatusNotFound},
{URI: "/debug/pprof/heap", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/goroutine", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/block", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/threadcreate", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/cmdline", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/trace", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/symbol", ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/symbol", Method: http.MethodPost, ExpectedCode: http.StatusOK},
{URI: "/debug/pprof/symbol", Method: http.MethodPost, ExpectedCode: http.StatusOK},
}
newFakeProxy(c).RunTests(t, requests)
}
func TestExpirationHandler(t *testing.T) { func TestExpirationHandler(t *testing.T) {
uri := oauthURL + expiredURL uri := oauthURL + expiredURL
requests := []fakeRequest{ requests := []fakeRequest{
......
...@@ -149,7 +149,7 @@ func (r *oauthProxy) createReverseProxy() error { ...@@ -149,7 +149,7 @@ func (r *oauthProxy) createReverseProxy() error {
if r.config.EnableProfiling { if r.config.EnableProfiling {
log.Warn("enabling the debug profiling on /debug/pprof") log.Warn("enabling the debug profiling on /debug/pprof")
engine.Any("/debug/pprof/:name", r.debugHandler, r.proxyRevokeMiddleware()) engine.Any("/debug/pprof/:name", r.debugHandler)
} }
if r.config.EnableLogging { if r.config.EnableLogging {
engine.Use(r.loggingMiddleware()) engine.Use(r.loggingMiddleware())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment