72
72
// Introduced in Go 1.21
73
73
"Certificate required" : regexp .MustCompile (`certificate required` ),
74
74
"Unknown CA" : regexp .MustCompile (`unknown certificate authority` ),
75
+ "Too Many Requests" : regexp .MustCompile (`Too Many Requests` ),
75
76
}
76
77
)
77
78
@@ -98,6 +99,7 @@ type TestInputs struct {
98
99
Username string
99
100
Password string
100
101
ClientCertificate string
102
+ Requests int
101
103
}
102
104
103
105
func TestYAMLFiles (t * testing.T ) {
@@ -364,6 +366,19 @@ func TestServerBehaviour(t *testing.T) {
364
366
ClientCertificate : "client2_selfsigned" ,
365
367
ExpectedError : ErrorMap ["Invalid client cert" ],
366
368
},
369
+ {
370
+ Name : "valid rate limiter that doesn't block" ,
371
+ YAMLConfigPath : "testdata/web_config_rate_limiter_nonblocking.yaml" ,
372
+ UseTLSClient : false ,
373
+ ExpectedError : nil ,
374
+ },
375
+ {
376
+ Name : "valid rate limiter with a capacity of one" ,
377
+ YAMLConfigPath : "testdata/web_config_rate_limiter_capacity_one.yaml" ,
378
+ UseTLSClient : false ,
379
+ Requests : 10 ,
380
+ ExpectedError : ErrorMap ["Too Many Requests" ],
381
+ },
367
382
}
368
383
for _ , testInputs := range testTables {
369
384
t .Run (testInputs .Name , testInputs .Test )
@@ -511,35 +526,41 @@ func (test *TestInputs) Test(t *testing.T) {
511
526
if test .Username != "" {
512
527
req .SetBasicAuth (test .Username , test .Password )
513
528
}
529
+
514
530
return client .Do (req )
515
531
}
516
532
go func () {
517
533
time .Sleep (250 * time .Millisecond )
518
- r , err := ClientConnection ()
519
- if err != nil {
520
- recordConnectionError (err )
521
- return
522
- }
523
534
524
- if test .ActualCipher != 0 {
525
- if r .TLS .CipherSuite != test .ActualCipher {
526
- recordConnectionError (
527
- fmt .Errorf ("bad cipher suite selected. Expected: %s, got: %s" ,
528
- tls .CipherSuiteName (test .ActualCipher ),
529
- tls .CipherSuiteName (r .TLS .CipherSuite ),
530
- ),
531
- )
535
+ for req := 0 ; req <= test .Requests ; req ++ {
536
+
537
+ r , err := ClientConnection ()
538
+
539
+ if err != nil {
540
+ recordConnectionError (err )
541
+ return
532
542
}
533
- }
534
543
535
- body , err := io .ReadAll (r .Body )
536
- if err != nil {
537
- recordConnectionError (err )
538
- return
539
- }
540
- if string (body ) != "Hello World!" {
541
- recordConnectionError (errors .New (string (body )))
542
- return
544
+ if test .ActualCipher != 0 {
545
+ if r .TLS .CipherSuite != test .ActualCipher {
546
+ recordConnectionError (
547
+ fmt .Errorf ("bad cipher suite selected. Expected: %s, got: %s" ,
548
+ tls .CipherSuiteName (test .ActualCipher ),
549
+ tls .CipherSuiteName (r .TLS .CipherSuite ),
550
+ ),
551
+ )
552
+ }
553
+ }
554
+
555
+ body , err := io .ReadAll (r .Body )
556
+ if err != nil {
557
+ recordConnectionError (err )
558
+ return
559
+ }
560
+ if string (body ) != "Hello World!" {
561
+ recordConnectionError (errors .New (string (body )))
562
+ return
563
+ }
543
564
}
544
565
recordConnectionError (nil )
545
566
}()
0 commit comments