Skip to content

Commit b99f117

Browse files
authored
Enable gosec G112 rule (#10333)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent a51e622 commit b99f117

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ linters-settings:
6666
includes:
6767
- G108
6868
- G109
69+
- G112
6970
- G114
7071

7172
run:

pkg/frontend/frontend_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func TestFrontend_RequestHostHeaderWhenDownstreamURLIsConfigured(t *testing.T) {
5959
_, err := w.Write([]byte(responseBody))
6060
require.NoError(t, err)
6161
}),
62+
ReadTimeout: 10 * time.Second,
63+
WriteTimeout: 10 * time.Second,
6264
}
6365

6466
defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
@@ -111,6 +113,8 @@ func TestFrontend_LogsSlowQueriesFormValues(t *testing.T) {
111113
_, err := w.Write([]byte(responseBody))
112114
require.NoError(t, err)
113115
}),
116+
ReadTimeout: 10 * time.Second,
117+
WriteTimeout: 10 * time.Second,
114118
}
115119

116120
defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
@@ -173,6 +177,8 @@ func TestFrontend_ReturnsRequestBodyTooLargeError(t *testing.T) {
173177
_, err := w.Write([]byte(responseBody))
174178
require.NoError(t, err)
175179
}),
180+
ReadTimeout: 10 * time.Second,
181+
WriteTimeout: 10 * time.Second,
176182
}
177183

178184
defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
@@ -260,7 +266,9 @@ func testFrontend(t *testing.T, config CombinedFrontendConfig, handler http.Hand
260266
).Wrap(transport.NewHandler(config.Handler, rt, logger, nil, nil)))
261267

262268
httpServer := http.Server{
263-
Handler: r,
269+
Handler: r,
270+
ReadTimeout: 10 * time.Second,
271+
WriteTimeout: 10 * time.Second,
264272
}
265273
defer httpServer.Shutdown(context.Background()) //nolint:errcheck
266274

pkg/frontend/v1/frontend_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ func testFrontend(t *testing.T, config Config, handler http.Handler, test func(a
345345
).Wrap(transport.NewHandler(handlerCfg, rt, logger, nil, nil)))
346346

347347
httpServer := http.Server{
348-
Handler: r,
348+
Handler: r,
349+
ReadTimeout: 10 * time.Second,
350+
WriteTimeout: 10 * time.Second,
349351
}
350352
defer httpServer.Shutdown(context.Background()) //nolint:errcheck
351353

pkg/util/gziphandler/gzip_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"strconv"
1818
"testing"
19+
"time"
1920

2021
"github.com/stretchr/testify/assert"
2122
)
@@ -279,7 +280,9 @@ func TestGzipHandlerContentLength(t *testing.T) {
279280
}
280281
defer ln.Close()
281282
srv := &http.Server{
282-
Handler: nil,
283+
Handler: nil,
284+
ReadTimeout: 10 * time.Second,
285+
WriteTimeout: 10 * time.Second,
283286
}
284287
go func() { _ = srv.Serve(ln) }()
285288

pkg/util/instrumentation/metrics.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net"
1111
"net/http"
12+
"time"
1213

1314
"github.com/go-kit/log"
1415
"github.com/go-kit/log/level"
@@ -45,7 +46,9 @@ func (s *MetricsServer) Start() error {
4546
router.Handle("/metrics", promhttp.HandlerFor(s.registry, promhttp.HandlerOpts{}))
4647

4748
s.srv = &http.Server{
48-
Handler: router,
49+
Handler: router,
50+
ReadTimeout: 10 * time.Second,
51+
WriteTimeout: 10 * time.Second,
4952
}
5053

5154
go func() {

0 commit comments

Comments
 (0)