@@ -2,10 +2,13 @@ package mcpproxy
22
33import (
44 "crypto/rsa"
5+ "encoding/json"
56 "errors"
67 "net/http"
8+ "net/http/httptest"
79 "testing"
810
11+ "github.com/gin-gonic/gin"
912 "github.com/sigbit/mcp-auth-proxy/pkg/proxy"
1013 "github.com/stretchr/testify/require"
1114)
@@ -117,3 +120,29 @@ func TestRun_PassesHTTPStreamingOnlyToProxyRouter(t *testing.T) {
117120 require .Contains (t , err .Error (), "failed to create proxy router" )
118121 require .True (t , streamingOnlyReceived , "httpStreamingOnly should be forwarded to proxy router" )
119122}
123+
124+ func TestHealthzEndpoint (t * testing.T ) {
125+ gin .SetMode (gin .TestMode )
126+ router := gin .New ()
127+
128+ // Register healthz before auth middleware, same as in Run()
129+ router .GET ("/healthz" , func (c * gin.Context ) {
130+ c .JSON (http .StatusOK , gin.H {"status" : "ok" })
131+ })
132+
133+ // Add a catch-all that returns 401 to simulate auth middleware
134+ router .Use (func (c * gin.Context ) {
135+ c .AbortWithStatus (http .StatusUnauthorized )
136+ })
137+
138+ w := httptest .NewRecorder ()
139+ req , _ := http .NewRequest ("GET" , "/healthz" , nil )
140+ router .ServeHTTP (w , req )
141+
142+ require .Equal (t , http .StatusOK , w .Code )
143+
144+ var body map [string ]string
145+ err := json .Unmarshal (w .Body .Bytes (), & body )
146+ require .NoError (t , err )
147+ require .Equal (t , "ok" , body ["status" ])
148+ }
0 commit comments