跳到主要内容

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

浏览文件

port_test.go

38 行 · 1.2 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package hostagent
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)
14
15func testPortForwarder(sshLocalPort int) *portForwarder {
16 return &portForwarder{
17 rules: portForwardRules("", limatype.User{}, nil, sshLocalPort, nil),
18 }
19}
20
21func TestPortForwardRulesBlockSSHOnEveryGuestIP(t *testing.T) {
22 const sshLocalPort = 60022
23 pf := testPortForwarder(sshLocalPort)
24 for _, guestIP := range []string{"0.0.0.0", "127.0.0.1", "::", "::1"} {
25 for _, port := range []int32{sshGuestPort, sshLocalPort} {
26 hostAddr, _ := pf.forwardingAddresses(&api.IPPort{Ip: guestIP, Port: port, Protocol: "tcp"})
27 assert.Equal(t, hostAddr, "", "guest %s:%d", guestIP, port)
28 }
29 }
30}
31
32func TestPortForwardRulesStillForwardOtherPorts(t *testing.T) {
33 pf := testPortForwarder(60022)
34 for _, guestIP := range []string{"0.0.0.0", "127.0.0.1", "::1"} {
35 hostAddr, _ := pf.forwardingAddresses(&api.IPPort{Ip: guestIP, Port: 8080, Protocol: "tcp"})
36 assert.Equal(t, hostAddr, "127.0.0.1:8080", "guest %s:8080", guestIP)
37 }
38}