(t *testing.T)
| 442 | } |
| 443 | |
| 444 | func TestLocalSandbox_AuditLog(t *testing.T) { |
| 445 | tmpDir, err := os.MkdirTemp("", "sandbox-test-*") |
| 446 | if err != nil { |
| 447 | t.Fatalf("failed to create temp dir: %v", err) |
| 448 | } |
| 449 | defer func() { _ = os.RemoveAll(tmpDir) }() |
| 450 | |
| 451 | sb, err := NewLocalSandbox(&LocalSandboxConfig{ |
| 452 | WorkDir: tmpDir, |
| 453 | MaxAuditEntries: 100, |
| 454 | }) |
| 455 | if err != nil { |
| 456 | t.Fatalf("failed to create sandbox: %v", err) |
| 457 | } |
| 458 | |
| 459 | // Execute some commands |
| 460 | _, _ = sb.Exec(context.Background(), "echo hello", nil) |
| 461 | _, _ = sb.Exec(context.Background(), "rm -rf /", nil) // blocked |
| 462 | _, _ = sb.Exec(context.Background(), "pwd", nil) |
| 463 | |
| 464 | // Check audit log |
| 465 | auditLog := sb.GetAuditLog() |
| 466 | if len(auditLog) < 3 { |
| 467 | t.Errorf("expected at least 3 audit entries, got %d", len(auditLog)) |
| 468 | } |
| 469 | |
| 470 | // Find the blocked command |
| 471 | var blockedEntry *AuditEntry |
| 472 | for i := range auditLog { |
| 473 | if auditLog[i].Blocked { |
| 474 | blockedEntry = &auditLog[i] |
| 475 | break |
| 476 | } |
| 477 | } |
| 478 | if blockedEntry == nil { |
| 479 | t.Error("expected to find a blocked entry") |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | func TestLocalSandbox_CommandStats(t *testing.T) { |
| 484 | tmpDir, err := os.MkdirTemp("", "sandbox-test-*") |
nothing calls this directly
no test coverage detected