MCPcopy Create free account
hub / github.com/astercloud/aster / TestLocalSandbox_AuditLog

Function TestLocalSandbox_AuditLog

pkg/sandbox/local_test.go:444–481  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

442}
443
444func 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
483func TestLocalSandbox_CommandStats(t *testing.T) {
484 tmpDir, err := os.MkdirTemp("", "sandbox-test-*")

Callers

nothing calls this directly

Calls 4

ExecMethod · 0.95
GetAuditLogMethod · 0.95
NewLocalSandboxFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected