oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package claude
2
3import (
4 "context"
5 "encoding/json"
6 "os"
7 "path/filepath"
8 "slices"
9 "testing"
10 "time"
11
12 "amadan.net/oficina/equipo/internal/runner/provider"
13)
14
15func TestProtectedPermissionNeverAsks(t *testing.T) {
16 f := fixtureFor(t, "Engineering")
17 s, events := openFixture(t, f)
18 f.l.mu.Lock()
19 st, _ := f.l.state(s)
20 st.active = true
21 st.turn = provider.Turn{ID: "turn"}
22 f.l.mu.Unlock()
23 if err := os.Symlink("/home/runner", filepath.Join(f.launch.Workspace, "alias")); err != nil {
24 t.Fatal(err)
25 }
26 for _, path := range []string{"~/.credentials.json", "~other/sentinel", "/home/runner/auth", "/home/other/sentinel", "/egress/sentinel", "/tool/equipo.sock", "/proc/1/root/home/runner/auth", "/dev/fd/0", "/workspace/alias/auth", "../home/runner/auth"} {
27 t.Run(path, func(t *testing.T) {
28 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
29 defer cancel()
30 raw, _ := json.Marshal(permissionRequest{Tool: "Read", Input: marshalProbe(map[string]string{"file_path": path})})
31 reply, err := f.l.Permission(ctx, s, raw)
32 var answer struct{ Behavior string }
33 if err != nil || json.Unmarshal(reply, &answer) != nil || answer.Behavior != "deny" {
34 t.Errorf("protected path did not deny immediately: %s %v", reply, err)
35 }
36 select {
37 case ev := <-events:
38 t.Errorf("protected path reached human: %s", ev.Kind)
39 default:
40 }
41 if _, err := permissionResult(permissionRequest{Tool: "Read", Input: marshalProbe(map[string]string{"file_path": path})}, provider.Answer{Behavior: "allow"}, f.launch.Policy); err == nil {
42 t.Error("protected path can be approved")
43 }
44 })
45 }
46}
47func marshalProbe(v any) json.RawMessage { raw, _ := json.Marshal(v); return raw }
48func TestHostHomeNativeDeny(t *testing.T) {
49 f := fixtureFor(t, "Engineering")
50 var m manifest
51 json.Unmarshal(f.launch.Policy.Manifest, &m)
52 var settings struct {
53 Permissions struct{ Deny []string }
54 Sandbox struct{ Filesystem struct{ DenyRead []string } }
55 }
56 json.Unmarshal(m.Settings, &settings)
57 if !slices.Contains(settings.Permissions.Deny, "Read(//home/**)") || !slices.Contains(settings.Sandbox.Filesystem.DenyRead, "/home") {
58 t.Fatal("host homes not denied")
59 }
60}
61