|  | 
| 1 | 1 | package mcp | 
| 2 | 2 | 
 | 
| 3 | 3 | import ( | 
|  | 4 | +	"github.com/mark3labs/mcp-go/client/transport" | 
| 4 | 5 | 	"github.com/mark3labs/mcp-go/mcp" | 
| 5 | 6 | 	"k8s.io/utils/ptr" | 
| 6 | 7 | 	"regexp" | 
| @@ -140,16 +141,39 @@ func TestToolCallLogging(t *testing.T) { | 
| 140 | 141 | 			} | 
| 141 | 142 | 		}) | 
| 142 | 143 | 	}) | 
| 143 |  | -	testCaseWithContext(t, &mcpContext{logLevel: 7}, func(c *mcpContext) { | 
|  | 144 | +	before := func(c *mcpContext) { | 
|  | 145 | +		c.clientOptions = append(c.clientOptions, transport.WithHeaders(map[string]string{ | 
|  | 146 | +			"Accept-Encoding":   "gzip", | 
|  | 147 | +			"Authorization":     "Bearer should-not-be-logged", | 
|  | 148 | +			"authorization":     "Bearer should-not-be-logged", | 
|  | 149 | +			"a-loggable-header": "should-be-logged", | 
|  | 150 | +		})) | 
|  | 151 | +	} | 
|  | 152 | +	testCaseWithContext(t, &mcpContext{logLevel: 7, before: before}, func(c *mcpContext) { | 
| 144 | 153 | 		_, _ = c.callTool("configuration_view", map[string]interface{}{ | 
| 145 | 154 | 			"minified": false, | 
| 146 | 155 | 		}) | 
| 147 | 156 | 		t.Run("Logs tool call headers", func(t *testing.T) { | 
| 148 |  | -			expectedLog := "mcp tool call headers: Accept-Encoding: gzip" | 
|  | 157 | +			expectedLog := "mcp tool call headers: A-Loggable-Header: should-be-logged" | 
| 149 | 158 | 			if !strings.Contains(c.logBuffer.String(), expectedLog) { | 
| 150 | 159 | 				t.Errorf("Expected log to contain '%s', got: %s", expectedLog, c.logBuffer.String()) | 
| 151 | 160 | 			} | 
| 152 | 161 | 		}) | 
| 153 |  | - | 
|  | 162 | +		sensitiveHeaders := []string{ | 
|  | 163 | +			"Authorization", | 
|  | 164 | +			// TODO: Add more sensitive headers as needed | 
|  | 165 | +		} | 
|  | 166 | +		t.Run("Does not log sensitive headers", func(t *testing.T) { | 
|  | 167 | +			for _, header := range sensitiveHeaders { | 
|  | 168 | +				if strings.Contains(c.logBuffer.String(), header) { | 
|  | 169 | +					t.Errorf("Log should not contain sensitive header '%s', got: %s", header, c.logBuffer.String()) | 
|  | 170 | +				} | 
|  | 171 | +			} | 
|  | 172 | +		}) | 
|  | 173 | +		t.Run("Does not log sensitive header values", func(t *testing.T) { | 
|  | 174 | +			if strings.Contains(c.logBuffer.String(), "should-not-be-logged") { | 
|  | 175 | +				t.Errorf("Log should not contain sensitive header value 'should-not-be-logged', got: %s", c.logBuffer.String()) | 
|  | 176 | +			} | 
|  | 177 | +		}) | 
| 154 | 178 | 	}) | 
| 155 | 179 | } | 
0 commit comments