瀏覽代碼

fix some new lint warnings

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
Nicola Murino 1 年之前
父節點
當前提交
ad75543172

+ 4 - 4
internal/cmd/gencompletion.go

@@ -53,7 +53,7 @@ MacOS:
 You will need to start a new shell for this setup to take effect.
 `,
 	DisableFlagsInUseLine: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
+	RunE: func(cmd *cobra.Command, _ []string) error {
 		return cmd.Root().GenBashCompletionV2(os.Stdout, true)
 	},
 }
@@ -79,7 +79,7 @@ macOS:
 You will need to start a new shell for this setup to take effect.
 `,
 	DisableFlagsInUseLine: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
+	RunE: func(cmd *cobra.Command, _ []string) error {
 		return cmd.Root().GenZshCompletion(os.Stdout)
 	},
 }
@@ -100,7 +100,7 @@ $ sftpgo gen completion fish > ~/.config/fish/completions/sftpgo.fish
 You will need to start a new shell for this setup to take effect.
 `,
 	DisableFlagsInUseLine: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
+	RunE: func(cmd *cobra.Command, _ []string) error {
 		return cmd.Root().GenFishCompletion(os.Stdout, true)
 	},
 }
@@ -118,7 +118,7 @@ To load completions for every new session, add the output of the above command
 to your powershell profile.
 `,
 	DisableFlagsInUseLine: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
+	RunE: func(cmd *cobra.Command, _ []string) error {
 		return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
 	},
 }

+ 17 - 23
internal/common/protocol_test.go

@@ -227,10 +227,10 @@ func TestMain(m *testing.M) {
 
 	go func() {
 		// start a test HTTP server to receive action notifications
-		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+		http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
 			fmt.Fprintf(w, "OK\n")
 		})
-		http.HandleFunc("/404", func(w http.ResponseWriter, r *http.Request) {
+		http.HandleFunc("/404", func(w http.ResponseWriter, _ *http.Request) {
 			w.WriteHeader(http.StatusNotFound)
 			fmt.Fprintf(w, "Not found\n")
 		})
@@ -272,7 +272,7 @@ func TestMain(m *testing.M) {
 	}()
 
 	go func() {
-		if err := smtpd.ListenAndServe(smtpServerAddr, func(remoteAddr net.Addr, from string, to []string, data []byte) error {
+		if err := smtpd.ListenAndServe(smtpServerAddr, func(_ net.Addr, from string, to []string, data []byte) error {
 			lastReceivedEmail.set(from, to, data)
 			return nil
 		}, "SFTPGo test", "localhost"); err != nil {
@@ -7793,7 +7793,7 @@ func TestBuiltinKeyboardInteractiveAuthentication(t *testing.T) {
 	user, _, err := httpdtest.AddUser(u, http.StatusCreated)
 	assert.NoError(t, err)
 	authMethods := []ssh.AuthMethod{
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 			return []string{defaultPassword}, nil
 		}),
 	}
@@ -7822,7 +7822,7 @@ func TestBuiltinKeyboardInteractiveAuthentication(t *testing.T) {
 	passwordAsked := false
 	passcodeAsked := false
 	authMethods = []ssh.AuthMethod{
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, questions []string, _ []bool) ([]string, error) {
 			var answers []string
 			if strings.HasPrefix(questions[0], "Password") {
 				answers = append(answers, defaultPassword)
@@ -7866,7 +7866,7 @@ func TestMultiStepBuiltinKeyboardAuth(t *testing.T) {
 	// public key + password
 	authMethods := []ssh.AuthMethod{
 		ssh.PublicKeys(signer),
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 			return []string{defaultPassword}, nil
 		}),
 	}
@@ -7895,7 +7895,7 @@ func TestMultiStepBuiltinKeyboardAuth(t *testing.T) {
 	// public key + passcode
 	authMethods = []ssh.AuthMethod{
 		ssh.PublicKeys(signer),
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 			return []string{passcode}, nil
 		}),
 	}
@@ -8848,12 +8848,10 @@ func checkBasicSFTP(client *sftp.Client) error {
 func getCustomAuthSftpClient(user dataprovider.User, authMethods []ssh.AuthMethod) (*ssh.Client, *sftp.Client, error) {
 	var sftpClient *sftp.Client
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Auth:    authMethods,
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Auth:            authMethods,
+		Timeout:         5 * time.Second,
 	}
 	conn, err := ssh.Dial("tcp", sftpServerAddr, config)
 	if err != nil {
@@ -8869,11 +8867,9 @@ func getCustomAuthSftpClient(user dataprovider.User, authMethods []ssh.AuthMetho
 func getSftpClient(user dataprovider.User) (*ssh.Client, *sftp.Client, error) {
 	var sftpClient *sftp.Client
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Timeout:         5 * time.Second,
 	}
 	if user.Password != "" {
 		config.Auth = []ssh.AuthMethod{ssh.Password(user.Password)}
@@ -8896,11 +8892,9 @@ func runSSHCommand(command string, user dataprovider.User) ([]byte, error) {
 	var sshSession *ssh.Session
 	var output []byte
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Timeout:         5 * time.Second,
 	}
 	if user.Password != "" {
 		config.Auth = []ssh.AuthMethod{ssh.Password(user.Password)}

+ 1 - 1
internal/httpd/httpd.go

@@ -562,7 +562,7 @@ func (b *Binding) checkBranding() {
 func (b *Binding) parseAllowedProxy() error {
 	if filepath.IsAbs(b.Address) && len(b.ProxyAllowed) > 0 {
 		// unix domain socket
-		b.allowHeadersFrom = []func(net.IP) bool{func(ip net.IP) bool { return true }}
+		b.allowHeadersFrom = []func(net.IP) bool{func(_ net.IP) bool { return true }}
 		return nil
 	}
 	allowedFuncs, err := util.ParseAllowedIPAndRanges(b.ProxyAllowed)

+ 1 - 1
internal/httpd/httpd_test.go

@@ -25526,7 +25526,7 @@ func getJWTWebToken(username, password string) (string, error) {
 	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
 	client := &http.Client{
 		Timeout: 10 * time.Second,
-		CheckRedirect: func(req *http.Request, via []*http.Request) error {
+		CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
 			return http.ErrUseLastResponse
 		},
 	}

+ 4 - 4
internal/httpd/internal_test.go

@@ -2168,7 +2168,7 @@ func TestRecoverer(t *testing.T) {
 	}
 	server := newHttpdServer(b, "../static", "", CorsConfig{}, "../openapi")
 	server.initializeRouter()
-	server.router.Get(recoveryPath, func(w http.ResponseWriter, r *http.Request) {
+	server.router.Get(recoveryPath, func(_ http.ResponseWriter, _ *http.Request) {
 		panic("panic")
 	})
 	testServer := httptest.NewServer(server.router)
@@ -2182,7 +2182,7 @@ func TestRecoverer(t *testing.T) {
 
 	server.router = chi.NewRouter()
 	server.router.Use(middleware.Recoverer)
-	server.router.Get(recoveryPath, func(w http.ResponseWriter, r *http.Request) {
+	server.router.Get(recoveryPath, func(_ http.ResponseWriter, _ *http.Request) {
 		panic("panic")
 	})
 	testServer = httptest.NewServer(server.router)
@@ -2208,7 +2208,7 @@ func TestStreamJSONArray(t *testing.T) {
 		data = append(data, i)
 	}
 
-	dataGetter = func(limit, offset int) ([]byte, int, error) {
+	dataGetter = func(_, offset int) ([]byte, int, error) {
 		if offset >= len(data) {
 			return nil, 0, nil
 		}
@@ -3140,7 +3140,7 @@ func TestWebAdminSetupWithInstallCode(t *testing.T) {
 	err = dataprovider.Initialize(providerConf, configDir, true)
 	assert.NoError(t, err)
 
-	SetInstallationCodeResolver(func(defaultInstallationCode string) string {
+	SetInstallationCodeResolver(func(_ string) string {
 		return "5678"
 	})
 

+ 1 - 1
internal/sftpd/server.go

@@ -555,7 +555,7 @@ func (c *Configuration) configureLoginBanner(serverConfig *ssh.ServerConfig, con
 		bannerContent, err := os.ReadFile(bannerFilePath)
 		if err == nil {
 			banner := string(bannerContent)
-			serverConfig.BannerCallback = func(conn ssh.ConnMetadata) string {
+			serverConfig.BannerCallback = func(_ ssh.ConnMetadata) string {
 				return banner
 			}
 		} else {

+ 19 - 29
internal/sftpd/sftpd_test.go

@@ -2331,7 +2331,7 @@ func TestMultiStepLoginKeyAndKeyInt(t *testing.T) {
 	signer, _ := ssh.ParsePrivateKey([]byte(testPrivateKey))
 	authMethods := []ssh.AuthMethod{
 		ssh.PublicKeys(signer),
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 			return []string{"1", "2"}, nil
 		}),
 	}
@@ -2348,7 +2348,7 @@ func TestMultiStepLoginKeyAndKeyInt(t *testing.T) {
 		assert.NoError(t, checkBasicSFTP(client))
 	}
 	authMethods = []ssh.AuthMethod{
-		ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+		ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 			return []string{"1", "2"}, nil
 		}),
 		ssh.PublicKeys(signer),
@@ -8225,12 +8225,10 @@ func TestOpenUnhandledChannel(t *testing.T) {
 	assert.NoError(t, err)
 
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Auth:    []ssh.AuthMethod{ssh.Password(defaultPassword)},
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Auth:            []ssh.AuthMethod{ssh.Password(defaultPassword)},
+		Timeout:         5 * time.Second,
 	}
 	conn, err := ssh.Dial("tcp", sftpServerAddr, config)
 	if assert.NoError(t, err) {
@@ -11186,11 +11184,9 @@ func runSSHCommand(command string, user dataprovider.User, usePubKey bool) ([]by
 	var sshSession *ssh.Session
 	var output []byte
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Timeout:         5 * time.Second,
 	}
 	if usePubKey {
 		key, err := ssh.ParsePrivateKey([]byte(testPrivateKey))
@@ -11235,11 +11231,9 @@ func getSignerForUserCert(certBytes []byte) (ssh.Signer, error) {
 func getSftpClientWithAddr(user dataprovider.User, usePubKey bool, addr string) (*ssh.Client, *sftp.Client, error) {
 	var sftpClient *sftp.Client
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Timeout:         5 * time.Second,
 	}
 	if usePubKey {
 		signer, err := ssh.ParsePrivateKey([]byte(testPrivateKey))
@@ -11276,12 +11270,10 @@ func getSftpClient(user dataprovider.User, usePubKey bool) (*ssh.Client, *sftp.C
 func getKeyboardInteractiveSftpClient(user dataprovider.User, answers []string) (*ssh.Client, *sftp.Client, error) {
 	var sftpClient *sftp.Client
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
 		Auth: []ssh.AuthMethod{
-			ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) ([]string, error) {
+			ssh.KeyboardInteractive(func(_, _ string, _ []string, _ []bool) ([]string, error) {
 				return answers, nil
 			}),
 		},
@@ -11301,12 +11293,10 @@ func getKeyboardInteractiveSftpClient(user dataprovider.User, answers []string)
 func getCustomAuthSftpClient(user dataprovider.User, authMethods []ssh.AuthMethod, addr string) (*ssh.Client, *sftp.Client, error) {
 	var sftpClient *sftp.Client
 	config := &ssh.ClientConfig{
-		User: user.Username,
-		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
-			return nil
-		},
-		Auth:    authMethods,
-		Timeout: 5 * time.Second,
+		User:            user.Username,
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Auth:            authMethods,
+		Timeout:         5 * time.Second,
 	}
 	var err error
 	var conn *ssh.Client

+ 1 - 1
internal/webdavd/webdavd.go

@@ -156,7 +156,7 @@ type Binding struct {
 func (b *Binding) parseAllowedProxy() error {
 	if filepath.IsAbs(b.Address) && len(b.ProxyAllowed) > 0 {
 		// unix domain socket
-		b.allowHeadersFrom = []func(net.IP) bool{func(ip net.IP) bool { return true }}
+		b.allowHeadersFrom = []func(net.IP) bool{func(_ net.IP) bool { return true }}
 		return nil
 	}
 	allowedFuncs, err := util.ParseAllowedIPAndRanges(b.ProxyAllowed)