跳到主要内容

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

浏览文件

cloudinit_test.go

36 行 · 1.1 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package hostagent
5
6import (
7 "bytes"
8 "encoding/json"
9 "strings"
10 "testing"
11 "unicode"
12
13 "gotest.tools/v3/assert"
14
15 "github.com/lima-vm/lima/v2/pkg/hostagent/events"
16)
17
18func TestEmitCloudInitProgressEventStripsControlChars(t *testing.T) {
19 var buf bytes.Buffer
20 a := &HostAgent{eventEnc: json.NewEncoder(&buf)}
21
22 // A compromised guest can put arbitrary bytes in its cloud-init log, including
23 // an ANSI escape sequence that would rewrite the operator's terminal.
24 const payload = "starting\x1b[2Kspoofed\x07 line"
25 a.emitCloudInitProgressEvent(t.Context(), &events.CloudInitProgress{LogLine: payload})
26
27 var ev events.Event
28 assert.NilError(t, json.Unmarshal(buf.Bytes(), &ev))
29 assert.Assert(t, ev.Status.CloudInitProgress != nil)
30 got := ev.Status.CloudInitProgress.LogLine
31 for _, r := range got {
32 assert.Assert(t, unicode.IsPrint(r), "control char %#q survived in %#q", r, got)
33 }
34 assert.Equal(t, got, "starting[2Kspoofed line")
35 assert.Assert(t, !strings.ContainsRune(got, '\x1b'))
36}