跳到主要内容

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

浏览文件

forward_test.go

43 行 · 1.4 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package portfwd
5
6import (
7 "testing"
8
9 "gotest.tools/v3/assert"
10
11 "github.com/lima-vm/lima/v2/pkg/guestagent/api"
12 "github.com/lima-vm/lima/v2/pkg/limatype"
13 "github.com/lima-vm/lima/v2/pkg/limayaml"
14)
15
16// testForwarder returns a forwarder configured to disable TCP forwarding, followed
17// by the catch-all rule that the host agent always appends last.
18func testForwarder() *Forwarder {
19 rules := []limatype.PortForward{
20 {GuestPortRange: [2]int{1, 65535}, Proto: limatype.ProtoTCP, Ignore: true},
21 {},
22 }
23 for i := range rules {
24 limayaml.FillPortForwardDefaults(&rules[i], "", limatype.User{}, nil)
25 }
26 return &Forwarder{rules: rules}
27}
28
29func TestForwardingAddressesRejectsUnknownProto(t *testing.T) {
30 fw := testForwarder()
31 for _, proto := range []string{"tcp6", "TCP", "any", ""} {
32 hostAddr, _ := fw.forwardingAddresses(&api.IPPort{Ip: "127.0.0.1", Port: 8080, Protocol: proto})
33 assert.Equal(t, hostAddr, "", "proto %#q", proto)
34 }
35}
36
37func TestForwardingAddressesHonorsIgnoredProto(t *testing.T) {
38 fw := testForwarder()
39 tcpAddr, _ := fw.forwardingAddresses(&api.IPPort{Ip: "127.0.0.1", Port: 8080, Protocol: limatype.ProtoTCP})
40 assert.Equal(t, tcpAddr, "")
41 udpAddr, _ := fw.forwardingAddresses(&api.IPPort{Ip: "127.0.0.1", Port: 8080, Protocol: limatype.ProtoUDP})
42 assert.Equal(t, udpAddr, "127.0.0.1:8080")
43}