@@ -24,22 +24,22 @@ type testQUICConn struct {
24
24
complete bool
25
25
}
26
26
27
- func newTestQUICClient (t * testing.T , config * Config ) * testQUICConn {
28
- q := & testQUICConn {t : t }
29
- q . conn = QUICClient ( & QUICConfig {
30
- TLSConfig : config ,
31
- })
27
+ func newTestQUICClient (t * testing.T , config * QUICConfig ) * testQUICConn {
28
+ q := & testQUICConn {
29
+ t : t ,
30
+ conn : QUICClient ( config ) ,
31
+ }
32
32
t .Cleanup (func () {
33
33
q .conn .Close ()
34
34
})
35
35
return q
36
36
}
37
37
38
- func newTestQUICServer (t * testing.T , config * Config ) * testQUICConn {
39
- q := & testQUICConn {t : t }
40
- q . conn = QUICServer ( & QUICConfig {
41
- TLSConfig : config ,
42
- })
38
+ func newTestQUICServer (t * testing.T , config * QUICConfig ) * testQUICConn {
39
+ q := & testQUICConn {
40
+ t : t ,
41
+ conn : QUICServer ( config ) ,
42
+ }
43
43
t .Cleanup (func () {
44
44
q .conn .Close ()
45
45
})
@@ -140,6 +140,11 @@ func runTestQUICConnection(ctx context.Context, cli, srv *testQUICConn, onEvent
140
140
return err
141
141
}
142
142
}
143
+ case QUICStoreSession :
144
+ if a != cli {
145
+ return errors .New ("unexpected QUICStoreSession event received by server" )
146
+ }
147
+ a .conn .StoreSession (e .SessionState )
143
148
case QUICResumeSession :
144
149
if a .onResumeSession != nil {
145
150
a .onResumeSession (e .SessionState )
@@ -154,8 +159,8 @@ func runTestQUICConnection(ctx context.Context, cli, srv *testQUICConn, onEvent
154
159
}
155
160
156
161
func TestQUICConnection (t * testing.T ) {
157
- config := testConfig .Clone ()
158
- config .MinVersion = VersionTLS13
162
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
163
+ config .TLSConfig . MinVersion = VersionTLS13
159
164
160
165
cli := newTestQUICClient (t , config )
161
166
cli .conn .SetTransportParameters (nil )
@@ -196,13 +201,13 @@ func TestQUICConnection(t *testing.T) {
196
201
}
197
202
198
203
func TestQUICSessionResumption (t * testing.T ) {
199
- clientConfig := testConfig .Clone ()
200
- clientConfig .MinVersion = VersionTLS13
201
- clientConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
202
- clientConfig .ServerName = "example.go.dev"
204
+ clientConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
205
+ clientConfig .TLSConfig . MinVersion = VersionTLS13
206
+ clientConfig .TLSConfig . ClientSessionCache = NewLRUClientSessionCache (1 )
207
+ clientConfig .TLSConfig . ServerName = "example.go.dev"
203
208
204
- serverConfig := testConfig .Clone ()
205
- serverConfig .MinVersion = VersionTLS13
209
+ serverConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
210
+ serverConfig .TLSConfig . MinVersion = VersionTLS13
206
211
207
212
cli := newTestQUICClient (t , clientConfig )
208
213
cli .conn .SetTransportParameters (nil )
@@ -228,13 +233,13 @@ func TestQUICSessionResumption(t *testing.T) {
228
233
}
229
234
230
235
func TestQUICFragmentaryData (t * testing.T ) {
231
- clientConfig := testConfig .Clone ()
232
- clientConfig .MinVersion = VersionTLS13
233
- clientConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
234
- clientConfig .ServerName = "example.go.dev"
236
+ clientConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
237
+ clientConfig .TLSConfig . MinVersion = VersionTLS13
238
+ clientConfig .TLSConfig . ClientSessionCache = NewLRUClientSessionCache (1 )
239
+ clientConfig .TLSConfig . ServerName = "example.go.dev"
235
240
236
- serverConfig := testConfig .Clone ()
237
- serverConfig .MinVersion = VersionTLS13
241
+ serverConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
242
+ serverConfig .TLSConfig . MinVersion = VersionTLS13
238
243
239
244
cli := newTestQUICClient (t , clientConfig )
240
245
cli .conn .SetTransportParameters (nil )
@@ -260,8 +265,8 @@ func TestQUICFragmentaryData(t *testing.T) {
260
265
261
266
func TestQUICPostHandshakeClientAuthentication (t * testing.T ) {
262
267
// RFC 9001, Section 4.4.
263
- config := testConfig .Clone ()
264
- config .MinVersion = VersionTLS13
268
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
269
+ config .TLSConfig . MinVersion = VersionTLS13
265
270
cli := newTestQUICClient (t , config )
266
271
cli .conn .SetTransportParameters (nil )
267
272
srv := newTestQUICServer (t , config )
@@ -288,8 +293,8 @@ func TestQUICPostHandshakeClientAuthentication(t *testing.T) {
288
293
289
294
func TestQUICPostHandshakeKeyUpdate (t * testing.T ) {
290
295
// RFC 9001, Section 6.
291
- config := testConfig .Clone ()
292
- config .MinVersion = VersionTLS13
296
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
297
+ config .TLSConfig . MinVersion = VersionTLS13
293
298
cli := newTestQUICClient (t , config )
294
299
cli .conn .SetTransportParameters (nil )
295
300
srv := newTestQUICServer (t , config )
@@ -312,8 +317,8 @@ func TestQUICPostHandshakeKeyUpdate(t *testing.T) {
312
317
}
313
318
314
319
func TestQUICPostHandshakeMessageTooLarge (t * testing.T ) {
315
- config := testConfig .Clone ()
316
- config .MinVersion = VersionTLS13
320
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
321
+ config .TLSConfig . MinVersion = VersionTLS13
317
322
cli := newTestQUICClient (t , config )
318
323
cli .conn .SetTransportParameters (nil )
319
324
srv := newTestQUICServer (t , config )
@@ -334,13 +339,13 @@ func TestQUICPostHandshakeMessageTooLarge(t *testing.T) {
334
339
}
335
340
336
341
func TestQUICHandshakeError (t * testing.T ) {
337
- clientConfig := testConfig .Clone ()
338
- clientConfig .MinVersion = VersionTLS13
339
- clientConfig .InsecureSkipVerify = false
340
- clientConfig .ServerName = "name"
342
+ clientConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
343
+ clientConfig .TLSConfig . MinVersion = VersionTLS13
344
+ clientConfig .TLSConfig . InsecureSkipVerify = false
345
+ clientConfig .TLSConfig . ServerName = "name"
341
346
342
- serverConfig := testConfig .Clone ()
343
- serverConfig .MinVersion = VersionTLS13
347
+ serverConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
348
+ serverConfig .TLSConfig . MinVersion = VersionTLS13
344
349
345
350
cli := newTestQUICClient (t , clientConfig )
346
351
cli .conn .SetTransportParameters (nil )
@@ -360,9 +365,9 @@ func TestQUICHandshakeError(t *testing.T) {
360
365
// and that it reports the application protocol as soon as it has been
361
366
// negotiated.
362
367
func TestQUICConnectionState (t * testing.T ) {
363
- config := testConfig .Clone ()
364
- config .MinVersion = VersionTLS13
365
- config .NextProtos = []string {"h3" }
368
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
369
+ config .TLSConfig . MinVersion = VersionTLS13
370
+ config .TLSConfig . NextProtos = []string {"h3" }
366
371
cli := newTestQUICClient (t , config )
367
372
cli .conn .SetTransportParameters (nil )
368
373
srv := newTestQUICServer (t , config )
@@ -391,10 +396,10 @@ func TestQUICStartContextPropagation(t *testing.T) {
391
396
const key = "key"
392
397
const value = "value"
393
398
ctx := context .WithValue (context .Background (), key , value )
394
- config := testConfig .Clone ()
395
- config .MinVersion = VersionTLS13
399
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
400
+ config .TLSConfig . MinVersion = VersionTLS13
396
401
calls := 0
397
- config .GetConfigForClient = func (info * ClientHelloInfo ) (* Config , error ) {
402
+ config .TLSConfig . GetConfigForClient = func (info * ClientHelloInfo ) (* Config , error ) {
398
403
calls ++
399
404
got , _ := info .Context ().Value (key ).(string )
400
405
if got != value {
@@ -415,13 +420,13 @@ func TestQUICStartContextPropagation(t *testing.T) {
415
420
}
416
421
417
422
func TestQUICDelayedTransportParameters (t * testing.T ) {
418
- clientConfig := testConfig .Clone ()
419
- clientConfig .MinVersion = VersionTLS13
420
- clientConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
421
- clientConfig .ServerName = "example.go.dev"
423
+ clientConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
424
+ clientConfig .TLSConfig . MinVersion = VersionTLS13
425
+ clientConfig .TLSConfig . ClientSessionCache = NewLRUClientSessionCache (1 )
426
+ clientConfig .TLSConfig . ServerName = "example.go.dev"
422
427
423
- serverConfig := testConfig .Clone ()
424
- serverConfig .MinVersion = VersionTLS13
428
+ serverConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
429
+ serverConfig .TLSConfig . MinVersion = VersionTLS13
425
430
426
431
cliParams := "client params"
427
432
srvParams := "server params"
@@ -449,8 +454,8 @@ func TestQUICDelayedTransportParameters(t *testing.T) {
449
454
}
450
455
451
456
func TestQUICEmptyTransportParameters (t * testing.T ) {
452
- config := testConfig .Clone ()
453
- config .MinVersion = VersionTLS13
457
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
458
+ config .TLSConfig . MinVersion = VersionTLS13
454
459
455
460
cli := newTestQUICClient (t , config )
456
461
cli .conn .SetTransportParameters (nil )
@@ -475,8 +480,8 @@ func TestQUICEmptyTransportParameters(t *testing.T) {
475
480
}
476
481
477
482
func TestQUICCanceledWaitingForData (t * testing.T ) {
478
- config := testConfig .Clone ()
479
- config .MinVersion = VersionTLS13
483
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
484
+ config .TLSConfig . MinVersion = VersionTLS13
480
485
cli := newTestQUICClient (t , config )
481
486
cli .conn .SetTransportParameters (nil )
482
487
cli .conn .Start (context .Background ())
@@ -489,8 +494,8 @@ func TestQUICCanceledWaitingForData(t *testing.T) {
489
494
}
490
495
491
496
func TestQUICCanceledWaitingForTransportParams (t * testing.T ) {
492
- config := testConfig .Clone ()
493
- config .MinVersion = VersionTLS13
497
+ config := & QUICConfig { TLSConfig : testConfig .Clone ()}
498
+ config .TLSConfig . MinVersion = VersionTLS13
494
499
cli := newTestQUICClient (t , config )
495
500
cli .conn .Start (context .Background ())
496
501
for cli .conn .NextEvent ().Kind != QUICTransportParametersRequired {
@@ -502,15 +507,15 @@ func TestQUICCanceledWaitingForTransportParams(t *testing.T) {
502
507
}
503
508
504
509
func TestQUICEarlyData (t * testing.T ) {
505
- clientConfig := testConfig .Clone ()
506
- clientConfig .MinVersion = VersionTLS13
507
- clientConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
508
- clientConfig .ServerName = "example.go.dev"
509
- clientConfig .NextProtos = []string {"h3" }
510
+ clientConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
511
+ clientConfig .TLSConfig . MinVersion = VersionTLS13
512
+ clientConfig .TLSConfig . ClientSessionCache = NewLRUClientSessionCache (1 )
513
+ clientConfig .TLSConfig . ServerName = "example.go.dev"
514
+ clientConfig .TLSConfig . NextProtos = []string {"h3" }
510
515
511
- serverConfig := testConfig .Clone ()
512
- serverConfig .MinVersion = VersionTLS13
513
- serverConfig .NextProtos = []string {"h3" }
516
+ serverConfig := & QUICConfig { TLSConfig : testConfig .Clone ()}
517
+ serverConfig .TLSConfig . MinVersion = VersionTLS13
518
+ serverConfig .TLSConfig . NextProtos = []string {"h3" }
514
519
515
520
cli := newTestQUICClient (t , clientConfig )
516
521
cli .conn .SetTransportParameters (nil )
@@ -528,7 +533,14 @@ func TestQUICEarlyData(t *testing.T) {
528
533
cli2 .conn .SetTransportParameters (nil )
529
534
srv2 := newTestQUICServer (t , serverConfig )
530
535
srv2 .conn .SetTransportParameters (nil )
531
- if err := runTestQUICConnection (context .Background (), cli2 , srv2 , nil ); err != nil {
536
+ onEvent := func (e QUICEvent , src , dst * testQUICConn ) bool {
537
+ switch e .Kind {
538
+ case QUICStoreSession , QUICResumeSession :
539
+ t .Errorf ("with EnableSessionEvents=false, got unexpected event %v" , e .Kind )
540
+ }
541
+ return false
542
+ }
543
+ if err := runTestQUICConnection (context .Background (), cli2 , srv2 , onEvent ); err != nil {
532
544
t .Fatalf ("error during second connection handshake: %v" , err )
533
545
}
534
546
if ! cli2 .conn .ConnectionState ().DidResume {
@@ -557,15 +569,17 @@ func TestQUICEarlyDataDeclined(t *testing.T) {
557
569
}
558
570
559
571
func testQUICEarlyDataDeclined (t * testing.T , server bool ) {
560
- clientConfig := testConfig .Clone ()
561
- clientConfig .MinVersion = VersionTLS13
562
- clientConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
563
- clientConfig .ServerName = "example.go.dev"
564
- clientConfig .NextProtos = []string {"h3" }
565
-
566
- serverConfig := testConfig .Clone ()
567
- serverConfig .MinVersion = VersionTLS13
568
- serverConfig .NextProtos = []string {"h3" }
572
+ clientConfig := & QUICConfig {TLSConfig : testConfig .Clone ()}
573
+ clientConfig .EnableSessionEvents = true
574
+ clientConfig .TLSConfig .MinVersion = VersionTLS13
575
+ clientConfig .TLSConfig .ClientSessionCache = NewLRUClientSessionCache (1 )
576
+ clientConfig .TLSConfig .ServerName = "example.go.dev"
577
+ clientConfig .TLSConfig .NextProtos = []string {"h3" }
578
+
579
+ serverConfig := & QUICConfig {TLSConfig : testConfig .Clone ()}
580
+ serverConfig .EnableSessionEvents = true
581
+ serverConfig .TLSConfig .MinVersion = VersionTLS13
582
+ serverConfig .TLSConfig .NextProtos = []string {"h3" }
569
583
570
584
cli := newTestQUICClient (t , clientConfig )
571
585
cli .conn .SetTransportParameters (nil )
0 commit comments