跳到主要内容

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

浏览文件

basic_tests.go

221 行 · 7.7 KB历史下载
1package e2e
2
3import (
4 "context"
5 "net"
6 "net/http"
7
8 gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client"
9
10 "github.com/containers/gvisor-tap-vsock/pkg/types"
11 "github.com/onsi/ginkgo"
12 "github.com/onsi/gomega"
13)
14
15type BasicTestProps struct {
16 SSHExec func(cmd ...string) ([]byte, error)
17 Sock string
18}
19
20func BasicConnectivityTests(props BasicTestProps) {
21 ginkgo.It("should configure the interface", func() {
22 out, err := props.SSHExec("ifconfig $(route | grep '^default' | grep -o '[^ ]*$')")
23 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
24 gomega.Expect(string(out)).To(gomega.ContainSubstring("mtu 1500"))
25 gomega.Expect(string(out)).To(gomega.ContainSubstring("inet 192.168.127.2"))
26 gomega.Expect(string(out)).To(gomega.ContainSubstring("netmask 255.255.255.0"))
27 gomega.Expect(string(out)).To(gomega.ContainSubstring("broadcast 192.168.127.255"))
28 })
29
30 ginkgo.It("should configure the default route", func() {
31 out, err := props.SSHExec("ip route show")
32 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
33 gomega.Expect(string(out)).To(gomega.MatchRegexp(`default via 192\.168\.127\.1 dev (.*?) proto dhcp (src 192\.168\.127\.2 )?metric 100`))
34 })
35
36 ginkgo.It("should configure dns settings", func() {
37 out, err := props.SSHExec("cat /etc/resolv.conf")
38 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
39 gomega.Expect(string(out)).To(gomega.ContainSubstring("nameserver 192.168.127.1"))
40 })
41
42 ginkgo.It("should ping the tap device", func() {
43 out, err := props.SSHExec("ping -c2 192.168.127.2")
44 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
45 gomega.Expect(string(out)).To(gomega.ContainSubstring("2 packets transmitted, 2 received, 0% packet loss"))
46 })
47
48 ginkgo.It("should ping the gateway", func() {
49 out, err := props.SSHExec("ping -c2 192.168.127.1")
50 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
51 gomega.Expect(string(out)).To(gomega.ContainSubstring("2 packets transmitted, 2 received, 0% packet loss"))
52 })
53}
54
55func BasicDHCPTests(props BasicTestProps) {
56 ginkgo.It("should return DHCP leases", func() {
57 client := gvproxyclient.New(&http.Client{
58 Transport: &http.Transport{
59 DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
60 return net.Dial("unix", props.Sock)
61 },
62 },
63 }, "http://base")
64 leases, err := client.ListDHCPLeases()
65 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
66 gomega.Expect(leases).Should(gomega.HaveKeyWithValue("192.168.127.1", "5a:94:ef:e4:0c:dd"))
67 gomega.Expect(leases).Should(gomega.HaveKeyWithValue("192.168.127.2", "5a:94:ef:e4:0c:ee"))
68 })
69
70}
71
72func BasicDNSTests(props BasicTestProps) {
73 ginkgo.It("should resolve redhat.com", func() {
74 out, err := props.SSHExec("nslookup redhat.com")
75 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
76 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 52.200.142.250"))
77 })
78
79 ginkgo.It("should resolve CNAME record for docs.crc.dev", func() {
80 out, err := props.SSHExec("nslookup -query=cname docs.crc.dev")
81 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
82 gomega.Expect(string(out)).To(gomega.ContainSubstring("docs.crc.dev canonical name = webredir.gandi.net."))
83 })
84 ginkgo.It("should resolve MX record for crc.dev", func() {
85 out, err := props.SSHExec("nslookup -query=mx crc.dev")
86 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
87 gomega.Expect(string(out)).To(gomega.ContainSubstring("crc.dev mail exchanger = 10 spool.mail.gandi.net."))
88 })
89
90 ginkgo.It("should resolve NS record for wikipedia.org", func() {
91 out, err := props.SSHExec("nslookup -query=ns wikipedia.org")
92 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
93 gomega.Expect(string(out)).To(gomega.ContainSubstring("wikipedia.org nameserver = ns0.wikimedia.org."))
94 })
95 ginkgo.It("should resolve IMAPS SRV record for crc.dev", func() {
96 out, err := props.SSHExec("nslookup -query=srv _imaps._tcp.crc.dev")
97 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
98 gomega.Expect(string(out)).To(gomega.ContainSubstring(`_imaps._tcp.crc.dev service = 0 1 993 mail.gandi.net.`))
99 })
100 ginkgo.It("should resolve TXT for crc.dev", func() {
101 out, err := props.SSHExec("nslookup -query=txt crc.dev")
102 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
103 gomega.Expect(string(out)).To(gomega.ContainSubstring(`text = "v=spf1`))
104 })
105
106 ginkgo.It("should resolve gateway.containers.internal", func() {
107 out, err := props.SSHExec("nslookup gateway.containers.internal")
108 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
109 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.1"))
110 })
111
112 ginkgo.It("should resolve host.containers.internal", func() {
113 out, err := props.SSHExec("nslookup host.containers.internal")
114 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
115 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.254"))
116 })
117
118 ginkgo.It("should resolve dynamically added dns entry test.dynamic.internal", func() {
119 client := gvproxyclient.New(&http.Client{
120 Transport: &http.Transport{
121 DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
122 return net.Dial("unix", props.Sock)
123 },
124 },
125 }, "http://base")
126 err := client.AddDNS(&types.Zone{
127 Name: "dynamic.internal.",
128 Records: []types.Record{
129 {
130 Name: "test",
131 IP: net.ParseIP("192.168.127.254"),
132 },
133 },
134 })
135 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
136
137 out, err := props.SSHExec("nslookup test.dynamic.internal")
138
139 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
140 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.254"))
141 })
142
143 ginkgo.It("should resolve recently added dns entry test.dynamic.internal", func() {
144 client := gvproxyclient.New(&http.Client{
145 Transport: &http.Transport{
146 DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
147 return net.Dial("unix", props.Sock)
148 },
149 },
150 }, "http://base")
151 err := client.AddDNS(&types.Zone{
152 Name: "dynamic.internal.",
153 Records: []types.Record{
154 {
155 Name: "test",
156 IP: net.ParseIP("192.168.127.254"),
157 },
158 },
159 })
160 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
161
162 err = client.AddDNS(&types.Zone{
163 Name: "dynamic.internal.",
164 Records: []types.Record{
165 {
166 Name: "test",
167 IP: net.ParseIP("192.168.127.253"),
168 },
169 },
170 })
171 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
172
173 out, err := props.SSHExec("nslookup test.dynamic.internal")
174
175 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
176 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.253"))
177 })
178
179 ginkgo.It("should retain order of existing zone", func() {
180 client := gvproxyclient.New(&http.Client{
181 Transport: &http.Transport{
182 DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
183 return net.Dial("unix", props.Sock)
184 },
185 },
186 }, "http://base")
187 _ = client.AddDNS(&types.Zone{
188 Name: "dynamic.testing.",
189 DefaultIP: net.ParseIP("192.168.127.2"),
190 })
191 _ = client.AddDNS(&types.Zone{
192 Name: "testing.",
193 Records: []types.Record{
194 {
195 Name: "host",
196 IP: net.ParseIP("192.168.127.3"),
197 },
198 },
199 })
200 out, err := props.SSHExec("nslookup test.dynamic.internal")
201 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
202 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.2"))
203
204 _ = client.AddDNS(&types.Zone{
205 Name: "testing.",
206 Records: []types.Record{
207 {
208 Name: "gateway",
209 IP: net.ParseIP("192.168.127.1"),
210 },
211 },
212 })
213 out, err = props.SSHExec("nslookup *.dynamic.testing")
214 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
215 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.2"))
216
217 out, err = props.SSHExec("nslookup gateway.testing")
218 gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
219 gomega.Expect(string(out)).To(gomega.ContainSubstring("Address: 192.168.127.1"))
220 })
221}