@@ -2,10 +2,8 @@ package vpn
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"maps"
7
6
"net"
8
- "net/http"
9
7
"net/netip"
10
8
"net/url"
11
9
"slices"
@@ -24,51 +22,32 @@ import (
24
22
"github.com/coder/quartz"
25
23
26
24
maputil "github.com/coder/coder/v2/coderd/util/maps"
27
- "github.com/coder/coder/v2/codersdk"
28
25
"github.com/coder/coder/v2/tailnet"
29
26
"github.com/coder/coder/v2/tailnet/proto"
30
27
"github.com/coder/coder/v2/testutil"
31
28
)
32
29
33
30
func newFakeClient (ctx context.Context , t * testing.T ) * fakeClient {
34
31
return & fakeClient {
35
- t : t ,
36
- ctx : ctx ,
37
- connCh : make (chan * fakeConn , 1 ),
38
- }
39
- }
40
-
41
- func newFakeClientWithOptsCh (ctx context.Context , t * testing.T ) * fakeClient {
42
- return & fakeClient {
43
- t : t ,
44
- ctx : ctx ,
45
- connCh : make (chan * fakeConn , 1 ),
46
- optsCh : make (chan * Options , 1 ),
32
+ t : t ,
33
+ ctx : ctx ,
34
+ ch : make (chan * fakeConn , 1 ),
47
35
}
48
36
}
49
37
50
38
type fakeClient struct {
51
- t * testing.T
52
- ctx context.Context
53
- connCh chan * fakeConn
54
- optsCh chan * Options // options will be written to this channel if it's not nil
39
+ t * testing.T
40
+ ctx context.Context
41
+ ch chan * fakeConn
55
42
}
56
43
57
44
var _ Client = (* fakeClient )(nil )
58
45
59
- func (f * fakeClient ) NewConn (_ context.Context , _ * url.URL , _ string , opts * Options ) (Conn , error ) {
60
- if f .optsCh != nil {
61
- select {
62
- case <- f .ctx .Done ():
63
- return nil , f .ctx .Err ()
64
- case f .optsCh <- opts :
65
- }
66
- }
67
-
46
+ func (f * fakeClient ) NewConn (context.Context , * url.URL , string , * Options ) (Conn , error ) {
68
47
select {
69
48
case <- f .ctx .Done ():
70
49
return nil , f .ctx .Err ()
71
- case conn := <- f .connCh :
50
+ case conn := <- f .ch :
72
51
return conn , nil
73
52
}
74
53
}
@@ -155,53 +134,37 @@ func TestTunnel_StartStop(t *testing.T) {
155
134
t .Parallel ()
156
135
157
136
ctx := testutil .Context (t , testutil .WaitShort )
158
- client := newFakeClientWithOptsCh (ctx , t )
137
+ client := newFakeClient (ctx , t )
159
138
conn := newFakeConn (tailnet.WorkspaceUpdate {}, time.Time {})
160
139
161
140
_ , mgr := setupTunnel (t , ctx , client , quartz .NewMock (t ))
162
141
163
142
errCh := make (chan error , 1 )
164
143
var resp * TunnelMessage
165
144
// When: we start the tunnel
166
- telemetry := codersdk.CoderDesktopTelemetry {
167
- DeviceID : "device001" ,
168
- DeviceOS : "macOS" ,
169
- CoderDesktopVersion : "0.24.8" ,
170
- }
171
- telemetryJSON , err := json .Marshal (telemetry )
172
- require .NoError (t , err )
173
145
go func () {
174
146
r , err := mgr .unaryRPC (ctx , & ManagerMessage {
175
147
Msg : & ManagerMessage_Start {
176
148
Start : & StartRequest {
177
149
TunnelFileDescriptor : 2 ,
178
- // Use default value for TunnelUseSoftNetIsolation
179
- CoderUrl : "https://coder.example.com" ,
180
- ApiToken : "fakeToken" ,
150
+ CoderUrl : "https://coder.example.com" ,
151
+ ApiToken : "fakeToken" ,
181
152
Headers : []* StartRequest_Header {
182
153
{Name : "X-Test-Header" , Value : "test" },
183
154
},
184
- DeviceOs : telemetry . DeviceOS ,
185
- DeviceId : telemetry . DeviceID ,
186
- CoderDesktopVersion : telemetry . CoderDesktopVersion ,
155
+ DeviceOs : "macOS" ,
156
+ DeviceId : "device001" ,
157
+ CoderDesktopVersion : "0.24.8" ,
187
158
},
188
159
},
189
160
})
190
161
resp = r
191
162
errCh <- err
192
163
}()
193
-
194
- // Then: `NewConn` is called
195
- opts := testutil .RequireReceive (ctx , t , client .optsCh )
196
- require .Equal (t , http.Header {
197
- "X-Test-Header" : {"test" },
198
- codersdk .CoderDesktopTelemetryHeader : {string (telemetryJSON )},
199
- }, opts .Headers )
200
- require .False (t , opts .UseSoftNetIsolation ) // the default is false
201
- testutil .RequireSend (ctx , t , client .connCh , conn )
202
-
164
+ // Then: `NewConn` is called,
165
+ testutil .RequireSend (ctx , t , client .ch , conn )
203
166
// And: a response is received
204
- err = testutil .TryReceive (ctx , t , errCh )
167
+ err : = testutil .TryReceive (ctx , t , errCh )
205
168
require .NoError (t , err )
206
169
_ , ok := resp .Msg .(* TunnelMessage_Start )
207
170
require .True (t , ok )
@@ -234,7 +197,7 @@ func TestTunnel_PeerUpdate(t *testing.T) {
234
197
wsID1 := uuid.UUID {1 }
235
198
wsID2 := uuid.UUID {2 }
236
199
237
- client := newFakeClientWithOptsCh (ctx , t )
200
+ client := newFakeClient (ctx , t )
238
201
conn := newFakeConn (tailnet.WorkspaceUpdate {
239
202
UpsertedWorkspaces : []* tailnet.Workspace {
240
203
{
@@ -248,28 +211,22 @@ func TestTunnel_PeerUpdate(t *testing.T) {
248
211
249
212
tun , mgr := setupTunnel (t , ctx , client , quartz .NewMock (t ))
250
213
251
- // When: we start the tunnel
252
214
errCh := make (chan error , 1 )
253
215
var resp * TunnelMessage
254
216
go func () {
255
217
r , err := mgr .unaryRPC (ctx , & ManagerMessage {
256
218
Msg : & ManagerMessage_Start {
257
219
Start : & StartRequest {
258
- TunnelFileDescriptor : 2 ,
259
- TunnelUseSoftNetIsolation : true ,
260
- CoderUrl : "https://coder.example.com" ,
261
- ApiToken : "fakeToken" ,
220
+ TunnelFileDescriptor : 2 ,
221
+ CoderUrl : "https://coder.example.com" ,
222
+ ApiToken : "fakeToken" ,
262
223
},
263
224
},
264
225
})
265
226
resp = r
266
227
errCh <- err
267
228
}()
268
-
269
- // Then: `NewConn` is called
270
- opts := testutil .RequireReceive (ctx , t , client .optsCh )
271
- require .True (t , opts .UseSoftNetIsolation )
272
- testutil .RequireSend (ctx , t , client .connCh , conn )
229
+ testutil .RequireSend (ctx , t , client .ch , conn )
273
230
err := testutil .TryReceive (ctx , t , errCh )
274
231
require .NoError (t , err )
275
232
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -334,7 +291,7 @@ func TestTunnel_NetworkSettings(t *testing.T) {
334
291
resp = r
335
292
errCh <- err
336
293
}()
337
- testutil .RequireSend (ctx , t , client .connCh , conn )
294
+ testutil .RequireSend (ctx , t , client .ch , conn )
338
295
err := testutil .TryReceive (ctx , t , errCh )
339
296
require .NoError (t , err )
340
297
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -475,7 +432,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
475
432
resp = r
476
433
errCh <- err
477
434
}()
478
- testutil .RequireSend (ctx , t , client .connCh , conn )
435
+ testutil .RequireSend (ctx , t , client .ch , conn )
479
436
err := testutil .TryReceive (ctx , t , errCh )
480
437
require .NoError (t , err )
481
438
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -646,7 +603,7 @@ func TestTunnel_sendAgentUpdateReconnect(t *testing.T) {
646
603
resp = r
647
604
errCh <- err
648
605
}()
649
- testutil .RequireSend (ctx , t , client .connCh , conn )
606
+ testutil .RequireSend (ctx , t , client .ch , conn )
650
607
err := testutil .TryReceive (ctx , t , errCh )
651
608
require .NoError (t , err )
652
609
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -746,7 +703,7 @@ func TestTunnel_sendAgentUpdateWorkspaceReconnect(t *testing.T) {
746
703
resp = r
747
704
errCh <- err
748
705
}()
749
- testutil .RequireSend (ctx , t , client .connCh , conn )
706
+ testutil .RequireSend (ctx , t , client .ch , conn )
750
707
err := testutil .TryReceive (ctx , t , errCh )
751
708
require .NoError (t , err )
752
709
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -849,7 +806,7 @@ func TestTunnel_slowPing(t *testing.T) {
849
806
resp = r
850
807
errCh <- err
851
808
}()
852
- testutil .RequireSend (ctx , t , client .connCh , conn )
809
+ testutil .RequireSend (ctx , t , client .ch , conn )
853
810
err := testutil .TryReceive (ctx , t , errCh )
854
811
require .NoError (t , err )
855
812
_ , ok := resp .Msg .(* TunnelMessage_Start )
@@ -938,7 +895,7 @@ func TestTunnel_stopMidPing(t *testing.T) {
938
895
resp = r
939
896
errCh <- err
940
897
}()
941
- testutil .RequireSend (ctx , t , client .connCh , conn )
898
+ testutil .RequireSend (ctx , t , client .ch , conn )
942
899
err := testutil .TryReceive (ctx , t , errCh )
943
900
require .NoError (t , err )
944
901
_ , ok := resp .Msg .(* TunnelMessage_Start )
0 commit comments