跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows_attachments_test.go

74 行 · 2.2 KB历史下载
1package workbench
2
3import (
4 "bytes"
5 "encoding/binary"
6 "errors"
7 "io"
8 "testing"
9)
10
11type interruptedAttachmentReader struct{}
12
13func (interruptedAttachmentReader) Read(p []byte) (int, error) {
14 copy(p, "partial")
15 return 7, errors.New("source interrupted")
16}
17
18func TestWindowsAttachmentFramesRequireCompleteSource(t *testing.T) {
19 for _, input := range []io.Reader{bytes.NewReader([]byte("hello")), bytes.NewReader(nil), interruptedAttachmentReader{}} {
20 var wire bytes.Buffer
21 err := writeWindowsAttachmentFrames(&wire, input)
22 data := wire.Bytes()
23 var content bytes.Buffer
24 complete := false
25 for len(data) >= 4 {
26 n := int(binary.LittleEndian.Uint32(data[:4]))
27 data = data[4:]
28 if n == 0 {
29 complete = true
30 break
31 }
32 if n > 64<<10 || n > len(data) {
33 t.Fatal("invalid frame")
34 }
35 content.Write(data[:n])
36 data = data[n:]
37 }
38 if complete != (err == nil) {
39 t.Fatal("an interrupted transfer must not contain a completion marker")
40 }
41 }
42}
43
44func TestWindowsAttachmentPathConfinedToGeneratedDirectory(t *testing.T) {
45 valid := `C:\Users\CageLabSetup\Cage\Attachments\0123456789abcdef0123456789abcdef\中文 O'Brien.txt`
46 if !validWindowsAttachmentPath(valid, "中文 O'Brien.txt") {
47 t.Fatal("valid guest path rejected")
48 }
49 for _, path := range []string{`C:\Users\Cage\secret.txt`, `C:\Users\Cage\Cage\Attachments\..\secret.txt`, `\\server\Cage\Attachments\0123456789abcdef0123456789abcdef\中文 O'Brien.txt`, valid + ":stream", valid + "\n"} {
50 if validWindowsAttachmentPath(path, "中文 O'Brien.txt") {
51 t.Fatalf("unsafe response accepted: %q", path)
52 }
53 }
54}
55
56func TestWindowsChooserAttachmentPathRetainsNameInPrivateChild(t *testing.T) {
57 const batch = "0123456789abcdef0123456789abcdef"
58 const file = "fedcba9876543210fedcba9876543210"
59 base := `C:\Users\guest\Cage\Attachments\` + batch + `\`
60 if !validWindowsAttachmentPath(base+file+`\same.txt`, "same.txt") {
61 t.Fatal("fixed chooser file directory rejected")
62 }
63 for _, path := range []string{
64 base + `ordinary\same.txt`,
65 base + file + `\` + file + `\same.txt`,
66 base + file + `\different.txt`,
67 base + `..\same.txt`,
68 base + file + `\same.txt:extra`,
69 } {
70 if validWindowsAttachmentPath(path, "same.txt") {
71 t.Fatalf("unconfined chooser attachment accepted: %q", path)
72 }
73 }
74}