@@ -27,6 +27,7 @@ const (
2727
2828var (
2929 correlationId = ""
30+ xForwardedFor = ""
3031)
3132
3233func TestListenAndServe (t * testing.T ) {
@@ -63,6 +64,10 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
6364 },
6465 DestinationAddr : target ,
6566 }
67+ xForwardedFor = "127.0.0.1"
68+ defer func () {
69+ xForwardedFor = "" // Cleanup for other test cases
70+ }()
6671
6772 testCases := []struct {
6873 desc string
@@ -132,16 +137,20 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
132137 require .NoError (t , err )
133138 }
134139
135- sshConn , _ , _ , err := ssh .NewClientConn (conn , serverUrl , clientConfig (t ))
140+ sshConn , sshChans , sshRequs , err := ssh .NewClientConn (conn , serverUrl , clientConfig (t ))
136141 if sshConn != nil {
137- sshConn .Close ()
142+ defer sshConn .Close ()
138143 }
139144
140145 if tc .isRejected {
141146 require .Error (t , err , "Expected plain SSH request to be failed" )
142147 require .Regexp (t , "ssh: handshake failed" , err .Error ())
143148 } else {
144149 require .NoError (t , err )
150+ client := ssh .NewClient (sshConn , sshChans , sshRequs )
151+ defer client .Close ()
152+
153+ holdSession (t , client )
145154 }
146155 })
147156 }
@@ -306,13 +315,15 @@ func setupServerWithContext(t *testing.T, cfg *config.Config, ctx context.Contex
306315 correlationId = r .Header .Get ("X-Request-Id" )
307316
308317 require .NotEmpty (t , correlationId )
318+ require .Equal (t , xForwardedFor , r .Header .Get ("X-Forwarded-For" ))
309319
310320 fmt .Fprint (w , `{"id": 1000, "key": "key"}` )
311321 },
312322 }, {
313323 Path : "/api/v4/internal/discover" ,
314324 Handler : func (w http.ResponseWriter , r * http.Request ) {
315325 require .Equal (t , correlationId , r .Header .Get ("X-Request-Id" ))
326+ require .Equal (t , xForwardedFor , r .Header .Get ("X-Forwarded-For" ))
316327
317328 fmt .Fprint (w , `{"id": 1000, "name": "Test User", "username": "test-user"}` )
318329 },
0 commit comments