1
1
package devtunnel_test
2
2
3
3
import (
4
+ "cdr.dev/slog"
4
5
"context"
5
6
"encoding/hex"
6
7
"encoding/json"
@@ -25,6 +26,18 @@ import (
25
26
"github.com/coder/coder/coderd/devtunnel"
26
27
)
27
28
29
+ const (
30
+ ipByte1 = 0xfc
31
+ ipByte2 = 0xca
32
+ wgPort = 48732
33
+ )
34
+
35
+ var (
36
+ serverIP = netip .AddrFrom16 ([16 ]byte {ipByte1 , ipByte2 , 15 : 0x1 })
37
+ dnsIP = netip .AddrFrom4 ([4 ]byte {1 , 1 , 1 , 1 })
38
+ clientIP = netip .AddrFrom16 ([16 ]byte {ipByte1 , ipByte2 , 15 : 0x2 })
39
+ )
40
+
28
41
// The tunnel leaks a few goroutines that aren't impactful to production scenarios.
29
42
// func TestMain(m *testing.M) {
30
43
// goleak.VerifyTestMain(m)
@@ -51,7 +64,7 @@ func TestTunnel(t *testing.T) {
51
64
fTunServer := newFakeTunnelServer (t )
52
65
cfg := fTunServer .config ()
53
66
54
- tun , errCh , err := devtunnel .NewWithConfig (ctx , slogtest .Make (t , nil ), cfg )
67
+ tun , errCh , err := devtunnel .NewWithConfig (ctx , slogtest .Make (t , nil ). Leveled ( slog . LevelDebug ) , cfg )
55
68
require .NoError (t , err )
56
69
t .Log (tun .URL )
57
70
@@ -99,18 +112,6 @@ type fakeTunnelServer struct {
99
112
server * httptest.Server
100
113
}
101
114
102
- const (
103
- ipByte1 = 0xfc
104
- ipByte2 = 0xca
105
- wgPort = 48732
106
- )
107
-
108
- var (
109
- serverIP = netip .AddrFrom16 ([16 ]byte {ipByte1 , ipByte2 , 15 : 0x1 })
110
- dnsIP = netip .AddrFrom4 ([4 ]byte {1 , 1 , 1 , 1 })
111
- clientIP = netip .AddrFrom16 ([16 ]byte {ipByte1 , ipByte2 , 15 : 0x2 })
112
- )
113
-
114
115
func newFakeTunnelServer (t * testing.T ) * fakeTunnelServer {
115
116
priv , err := wgtypes .GeneratePrivateKey ()
116
117
privBytes := [32 ]byte (priv )
@@ -123,14 +124,15 @@ func newFakeTunnelServer(t *testing.T) *fakeTunnelServer {
123
124
1280 ,
124
125
)
125
126
require .NoError (t , err )
126
- dev := device .NewDevice (tun , conn .NewDefaultBind (), device .NewLogger (device .LogLevelVerbose , "" ))
127
+ dev := device .NewDevice (tun , conn .NewDefaultBind (), device .NewLogger (device .LogLevelVerbose , "server " ))
127
128
err = dev .IpcSet (fmt .Sprintf (`private_key=%s
128
129
listen_port=%d` ,
129
130
hex .EncodeToString (privBytes [:]),
130
131
wgPort ,
131
132
))
132
133
require .NoError (t , err )
133
134
t .Cleanup (func () {
135
+ dev .RemoveAllPeers ()
134
136
dev .Close ()
135
137
})
136
138
@@ -193,7 +195,7 @@ allowed_ip=%s/128`,
193
195
PublicKey : device .NoisePublicKey (pub ),
194
196
Tunnel : devtunnel.Node {
195
197
HostnameHTTPS : strings .TrimPrefix (f .server .URL , "https://" ),
196
- HostnameWireguard : "::1 " ,
198
+ HostnameWireguard : "localhost " ,
197
199
WireguardPort : wgPort ,
198
200
},
199
201
HTTPClient : f .server .Client (),
0 commit comments