Skip to content

Commit e36e54b

Browse files
committed
fix lint issues in url agent source
- combine consecutive string params in ssrfDialControl (gocritic paramTypeCombine) - rename local 'url' that shadowed the imported net/url package (gocritic importShadow) - align table-driven test comments per gofmt/gci Assisted-By: docker-agent
1 parent 9ceae88 commit e36e54b

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

pkg/config/sources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func ssrfCheckRedirect(req *http.Request, via []*http.Request) error {
429429
// ssrfDialControl is invoked by net.Dialer after DNS resolution but before the
430430
// TCP handshake. It rejects addresses that are not safe to fetch from over
431431
// the public internet.
432-
func ssrfDialControl(_ string, address string, _ syscall.RawConn) error {
432+
func ssrfDialControl(_, address string, _ syscall.RawConn) error {
433433
host, _, err := net.SplitHostPort(address)
434434
if err != nil {
435435
return fmt.Errorf("parsing dial address %q: %w", address, err)

pkg/config/sources_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ func TestURLSource_Read_RejectsLocalAddresses(t *testing.T) {
329329
// though the TLS handshake will never complete, because the dial is
330330
// aborted before any bytes are sent.
331331
tests := []string{
332-
"https://127.0.0.1/agent.yaml", // loopback
333-
"https://[::1]/agent.yaml", // IPv6 loopback
334-
"https://10.0.0.1/agent.yaml", // RFC1918
335-
"https://192.168.1.1/agent.yaml", // RFC1918
336-
"https://169.254.169.254/agent.yaml", // AWS/GCP/Azure metadata
337-
"https://0.0.0.0/agent.yaml", // unspecified
332+
"https://127.0.0.1/agent.yaml", // loopback
333+
"https://[::1]/agent.yaml", // IPv6 loopback
334+
"https://10.0.0.1/agent.yaml", // RFC1918
335+
"https://192.168.1.1/agent.yaml", // RFC1918
336+
"https://169.254.169.254/agent.yaml", // AWS/GCP/Azure metadata
337+
"https://0.0.0.0/agent.yaml", // unspecified
338338
}
339339
for _, rawURL := range tests {
340340
t.Run(rawURL, func(t *testing.T) {
@@ -396,7 +396,7 @@ func TestSSRFCheckRedirect(t *testing.T) {
396396
tests := []struct {
397397
name string
398398
target string
399-
via int // length of the via slice
399+
via int // length of the via slice
400400
wantErr string // empty means no error
401401
}{
402402
{"https redirect allowed", "https://example.com/agent.yaml", 1, ""},
@@ -441,13 +441,13 @@ func TestURLSource_Read_RejectsHTTPRedirect(t *testing.T) {
441441
// and assert that the production fetch path errors out for an https
442442
// origin pointing at a non-trusted CA. Either way, the request must
443443
// not silently follow to http://.
444-
url := httpsSrv.URL + "/agent.yaml"
444+
agentURL := httpsSrv.URL + "/agent.yaml"
445445
urlCacheDir := getURLCacheDir()
446-
urlHash := hashURL(url)
446+
urlHash := hashURL(agentURL)
447447
_ = os.Remove(filepath.Join(urlCacheDir, urlHash))
448448
_ = os.Remove(filepath.Join(urlCacheDir, urlHash+".etag"))
449449

450-
_, err := NewURLSource(url, nil).Read(t.Context())
450+
_, err := NewURLSource(agentURL, nil).Read(t.Context())
451451
require.Error(t, err)
452452
}
453453

0 commit comments

Comments
 (0)