chore(lint): upgrade golangci-lint to v1.47.2

- Fix Slowloris attacks on HTTP servers
- Force set default of 5 minutes for pprof read timeout
- Change `ShutdownTimeout` to time.Duration since it cannot be set to 0
This commit is contained in:
Quentin McGaw
2022-07-28 21:55:10 +00:00
parent 877617cc53
commit a6f00f2fb2
24 changed files with 348 additions and 158 deletions

View File

@@ -2,13 +2,11 @@ package pprof
import (
"regexp"
"time"
gomock "github.com/golang/mock/gomock"
)
func boolPtr(b bool) *bool { return &b }
func durationPtr(d time.Duration) *time.Duration { return &d }
func boolPtr(b bool) *bool { return &b }
var _ gomock.Matcher = (*regexMatcher)(nil)

View File

@@ -29,7 +29,7 @@ func Test_Server(t *testing.T) {
HTTPServer: httpserver.Settings{
Address: address,
Logger: logger,
ShutdownTimeout: durationPtr(httpServerShutdownTimeout),
ShutdownTimeout: httpServerShutdownTimeout,
},
}

View File

@@ -2,6 +2,7 @@ package pprof
import (
"errors"
"time"
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
"github.com/qdm12/gluetun/internal/httpserver"
@@ -27,6 +28,8 @@ type Settings struct {
func (s *Settings) SetDefaults() {
s.Enabled = helpers.DefaultBool(s.Enabled, false)
s.HTTPServer.Address = helpers.DefaultString(s.HTTPServer.Address, "localhost:6060")
const defaultReadTimeout = 5 * time.Minute // for CPU profiling
s.HTTPServer.ReadTimeout = helpers.DefaultDuration(s.HTTPServer.ReadTimeout, defaultReadTimeout)
s.HTTPServer.SetDefaults()
}

View File

@@ -21,8 +21,10 @@ func Test_Settings_SetDefaults(t *testing.T) {
expected: Settings{
Enabled: boolPtr(false),
HTTPServer: httpserver.Settings{
Address: "localhost:6060",
ShutdownTimeout: durationPtr(3 * time.Second),
Address: "localhost:6060",
ReadHeaderTimeout: 3 * time.Second,
ReadTimeout: 5 * time.Minute,
ShutdownTimeout: 3 * time.Second,
},
},
},
@@ -32,8 +34,10 @@ func Test_Settings_SetDefaults(t *testing.T) {
BlockProfileRate: 1,
MutexProfileRate: 1,
HTTPServer: httpserver.Settings{
Address: ":6061",
ShutdownTimeout: durationPtr(time.Second),
Address: ":6061",
ReadHeaderTimeout: time.Second,
ReadTimeout: time.Second,
ShutdownTimeout: time.Second,
},
},
expected: Settings{
@@ -41,8 +45,10 @@ func Test_Settings_SetDefaults(t *testing.T) {
BlockProfileRate: 1,
MutexProfileRate: 1,
HTTPServer: httpserver.Settings{
Address: ":6061",
ShutdownTimeout: durationPtr(time.Second),
Address: ":6061",
ReadHeaderTimeout: time.Second,
ReadTimeout: time.Second,
ShutdownTimeout: time.Second,
},
},
},
@@ -75,7 +81,7 @@ func Test_Settings_Copy(t *testing.T) {
MutexProfileRate: 1,
HTTPServer: httpserver.Settings{
Address: ":6061",
ShutdownTimeout: durationPtr(time.Second),
ShutdownTimeout: time.Second,
},
},
expected: Settings{
@@ -84,7 +90,7 @@ func Test_Settings_Copy(t *testing.T) {
MutexProfileRate: 1,
HTTPServer: httpserver.Settings{
Address: ":6061",
ShutdownTimeout: durationPtr(time.Second),
ShutdownTimeout: time.Second,
},
},
},
@@ -278,10 +284,12 @@ func Test_Settings_Validate(t *testing.T) {
"valid settings": {
settings: Settings{
HTTPServer: httpserver.Settings{
Address: ":8000",
Handler: http.NewServeMux(),
Logger: &MockLogger{},
ShutdownTimeout: durationPtr(time.Second),
Address: ":8000",
Handler: http.NewServeMux(),
Logger: &MockLogger{},
ReadHeaderTimeout: time.Second,
ReadTimeout: time.Second,
ShutdownTimeout: time.Second,
},
},
},
@@ -321,7 +329,7 @@ func Test_Settings_String(t *testing.T) {
MutexProfileRate: 1,
HTTPServer: httpserver.Settings{
Address: ":8000",
ShutdownTimeout: durationPtr(time.Second),
ShutdownTimeout: time.Second,
},
},
s: `Pprof settings:
@@ -329,6 +337,8 @@ func Test_Settings_String(t *testing.T) {
├── Mutex profile rate: 1
└── HTTP server settings:
├── Listening address: :8000
├── Read header timeout: 0s
├── Read timeout: 0s
└── Shutdown timeout: 1s`,
},
}