@@ -294,10 +294,11 @@ func TestHandleTailLogs(t *testing.T) {
294294 t .Error ("Expected error for missing file_path" )
295295 }
296296
297- // Test with valid file path (use a temp file in /tmp)
297+ // SECURITY TEST: Verify that /tmp is not allowed (security hardening)
298+ // Create a temp file in /tmp to test that access is properly denied
298299 tmpFile , err := os .CreateTemp ("/tmp" , "test-log-*.txt" )
299300 if err != nil {
300- t .Fatalf ( "Failed to create temp file: %v" , err )
301+ t .Skip ( "Cannot create temp file for security test" )
301302 }
302303 defer os .Remove (tmpFile .Name ())
303304 defer tmpFile .Close ()
@@ -319,23 +320,26 @@ func TestHandleTailLogs(t *testing.T) {
319320 t .Fatalf ("handleTailLogs failed: %v" , err )
320321 }
321322
322- if result .IsError {
323- if len (result .Content ) > 0 {
324- if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
325- t .Errorf ("Expected success, got error: %s" , textContent .Text )
326- } else {
327- t .Error ("Expected success, got error" )
323+ // SECURITY: Expect error because /tmp is not in allowed paths
324+ if ! result .IsError {
325+ t .Error ("Expected error for /tmp access (security hardening), but got success" )
326+ }
327+
328+ // Verify the error message mentions path validation
329+ if len (result .Content ) > 0 {
330+ if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
331+ if ! strings .Contains (textContent .Text , "file path validation failed" ) &&
332+ ! strings .Contains (textContent .Text , "not in allowed directories" ) {
333+ t .Errorf ("Expected path validation error, got: %s" , textContent .Text )
328334 }
329- } else {
330- t .Error ("Expected success, got error" )
331335 }
332336 }
333337}
334338
335339func TestHandleGetDiskUsage (t * testing.T ) {
336340 ctx := context .Background ()
337341
338- // Test with /tmp directory ( allowed path )
342+ // SECURITY TEST: Verify that /tmp is not allowed (security hardening )
339343 req := mcp.CallToolRequest {
340344 Params : mcp.CallToolParams {
341345 Arguments : map [string ]interface {}{
@@ -350,30 +354,19 @@ func TestHandleGetDiskUsage(t *testing.T) {
350354 t .Fatalf ("handleGetDiskUsage failed: %v" , err )
351355 }
352356
353- if result .IsError {
354- if len (result .Content ) > 0 {
355- if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
356- t .Errorf ("Expected success, got error: %s" , textContent .Text )
357- } else {
358- t .Error ("Expected success, got error" )
359- }
360- } else {
361- t .Error ("Expected success, got error" )
362- }
357+ // SECURITY: Expect error because /tmp is not in allowed paths
358+ if ! result .IsError {
359+ t .Error ("Expected error for /tmp access (security hardening), but got success" )
363360 }
364361
365- // Test that result contains valid JSON
362+ // Verify the error message mentions path validation
366363 if len (result .Content ) > 0 {
367364 if textContent , ok := mcp .AsTextContent (result .Content [0 ]); ok {
368- var diskUsage map [ string ] interface {}
369- if err := json . Unmarshal ([] byte ( textContent .Text ), & diskUsage ); err != nil {
370- t .Errorf ("Result should be valid JSON : %v " , err )
365+ if ! strings . Contains ( textContent . Text , "failed to get disk usage" ) &&
366+ ! strings . Contains ( textContent .Text , "not in allowed directories" ) {
367+ t .Errorf ("Expected path validation error, got : %s " , textContent . Text )
371368 }
372- } else {
373- t .Error ("Expected text content in result" )
374369 }
375- } else {
376- t .Error ("Expected content in result" )
377370 }
378371}
379372
0 commit comments