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,20 @@ 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 (no rate limiter set up) that doesn't block" ,
371
+ YAMLConfigPath : "testdata/web_config_rate_limiter_nonblocking.yaml" ,
372
+ UseTLSClient : false ,
373
+ Requests : 10 ,
374
+ ExpectedError : nil ,
375
+ },
376
+ {
377
+ Name : "valid rate limiter with an interval of one second" ,
378
+ YAMLConfigPath : "testdata/web_config_rate_limiter_one_second.yaml" ,
379
+ UseTLSClient : false ,
380
+ Requests : 10 ,
381
+ ExpectedError : ErrorMap ["Too Many Requests" ],
382
+ },
367
383
}
368
384
for _ , testInputs := range testTables {
369
385
t .Run (testInputs .Name , testInputs .Test )
@@ -511,35 +527,41 @@ func (test *TestInputs) Test(t *testing.T) {
511
527
if test .Username != "" {
512
528
req .SetBasicAuth (test .Username , test .Password )
513
529
}
530
+
514
531
return client .Do (req )
515
532
}
516
533
go func () {
517
534
time .Sleep (250 * time .Millisecond )
518
- r , err := ClientConnection ()
519
- if err != nil {
520
- recordConnectionError (err )
521
- return
522
- }
523
535
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
- )
536
+ for req := 0 ; req <= test .Requests ; req ++ {
537
+
538
+ r , err := ClientConnection ()
539
+
540
+ if err != nil {
541
+ recordConnectionError (err )
542
+ return
532
543
}
533
- }
534
544
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
545
+ if test .ActualCipher != 0 {
546
+ if r .TLS .CipherSuite != test .ActualCipher {
547
+ recordConnectionError (
548
+ fmt .Errorf ("bad cipher suite selected. Expected: %s, got: %s" ,
549
+ tls .CipherSuiteName (test .ActualCipher ),
550
+ tls .CipherSuiteName (r .TLS .CipherSuite ),
551
+ ),
552
+ )
553
+ }
554
+ }
555
+
556
+ body , err := io .ReadAll (r .Body )
557
+ if err != nil {
558
+ recordConnectionError (err )
559
+ return
560
+ }
561
+ if string (body ) != "Hello World!" {
562
+ recordConnectionError (errors .New (string (body )))
563
+ return
564
+ }
543
565
}
544
566
recordConnectionError (nil )
545
567
}()
0 commit comments