Skip to content

Commit

Permalink
test(sec): enhance security and performance in test server configs
Browse files Browse the repository at this point in the history
- Set the minimum TLS version to TLS 1.2 in the test server configuration
- Add `ReadHeaderTimeout` of 10 seconds to the HTTP server configurations in the tests

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Nov 14, 2024
1 parent b87353a commit 6b2fd81
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions graceful_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,19 @@ func TestWithServer(t *testing.T) {
assert.NoError(t, err)
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12,
}
testRouterConstructor(t, func() (*Graceful, error) {
return Default(
WithServer(&http.Server{Addr: ":8811"}),
WithServer(&http.Server{Addr: ":9443", TLSConfig: tlsConfig}),
WithServer(&http.Server{
Addr: ":8811",
ReadHeaderTimeout: 10 * time.Second,
}),
WithServer(&http.Server{
Addr: ":9443",
TLSConfig: tlsConfig,
ReadHeaderTimeout: 10 * time.Second,
}),
)
}, "http://localhost:8811/example", "https://localhost:9443/example")
}
Expand All @@ -212,7 +220,10 @@ func TestWithAll(t *testing.T) {
return Default(WithAddr(":8080"),
WithTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"),
WithListener(listener),
WithServer(&http.Server{Addr: ":8811"}),
WithServer(&http.Server{
Addr: ":8811",
ReadHeaderTimeout: 10 * time.Second,
}),
)
},
"http://localhost:8080/example",
Expand Down

0 comments on commit 6b2fd81

Please sign in to comment.