drop the dead nolint directives

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2026-09-09 12:37:54 +02:00
parent be8a4f3618
commit 55e443d29e
16 changed files with 95 additions and 95 deletions
+4 -4
View File
@@ -200,7 +200,7 @@ func TestRenameEntryChecks(t *testing.T) {
},
})
fs := vfs.NewOsFs("", filepath.Clean(os.TempDir()), "", nil)
defer fs.Close() //nolint:errcheck
defer fs.Close()
sourcePath := filepath.Join(os.TempDir(), "source")
targetPath := filepath.Join(os.TempDir(), "target")
// the rename permissions are partial, the entries must be checked one by one
@@ -221,7 +221,7 @@ func TestRenameEntryChecks(t *testing.T) {
assert.ErrorIs(t, err, os.ErrPermission)
// a filesystem that recurses walks the tree first
mockFs := newMockOsFs(false, "mockID", filepath.Clean(os.TempDir()), "S3Fs")
defer mockFs.Close() //nolint:errcheck
defer mockFs.Close()
err = conn.checkFolderRename(mockFs, mockFs, sourcePath, targetPath, "/source", "/target")
if assert.Error(t, err) {
assert.EqualError(t, err, conn.GetOpUnsupportedError().Error())
@@ -328,7 +328,7 @@ func TestRenameSourceTypeChanged(t *testing.T) {
require.NoError(t, os.RemoveAll(root))
require.NoError(t, os.MkdirAll(filepath.Join(root, "adir"), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(root, "afile"), []byte("f"), 0o600))
defer os.RemoveAll(root) //nolint:errcheck
defer os.RemoveAll(root)
conn := NewBaseConnection("", ProtocolWebDAV, "", "", dataprovider.User{
BaseUser: sdk.BaseUser{
@@ -336,7 +336,7 @@ func TestRenameSourceTypeChanged(t *testing.T) {
},
})
fs := vfs.NewOsFs("", root, "", nil)
defer fs.Close() //nolint:errcheck
defer fs.Close()
dirInfo := vfs.NewFileInfo("x", true, 0, time.Now(), false)
fileInfo := vfs.NewFileInfo("x", false, 0, time.Now(), false)
+12 -12
View File
@@ -335,7 +335,7 @@ func TestBaseConnection(t *testing.T) {
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)
linkName := testFileName + ".link" //nolint:goconst
linkName := testFileName + ".link"
err = client.Rename(testFileName, testFileName)
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "the rename source and target cannot be the same")
@@ -440,7 +440,7 @@ func TestRelativeSymlinks(t *testing.T) {
defer conn.Close()
defer client.Close()
linkName := testFileName + "_link" //nolint:goconst
linkName := testFileName + "_link"
err = client.Symlink("non-existent-file", linkName)
assert.NoError(t, err)
err = client.Remove(linkName)
@@ -1105,7 +1105,7 @@ func TestHiddenRoot(t *testing.T) {
assert.ErrorIs(t, err, os.ErrPermission)
err = writeSFTPFile("ftp123", 4096, client)
assert.ErrorIs(t, err, os.ErrPermission)
err = client.Rename(testFileName, testFileName+"_rename") //nolint:goconst
err = client.Rename(testFileName, testFileName+"_rename")
assert.ErrorIs(t, err, os.ErrNotExist)
err = writeSFTPFile(path.Join("/ftp", testFileName), 4096, client)
assert.NoError(t, err)
@@ -1529,16 +1529,16 @@ func TestTruncateQuotaLimits(t *testing.T) {
func TestVirtualFoldersQuotaRenameOverwrite(t *testing.T) {
testFileSize := int64(131072)
testFileSize1 := int64(65537)
testFileName1 := "test_file1.dat" //nolint:goconst
testFileName1 := "test_file1.dat"
u := getTestUser()
u.QuotaFiles = 0
u.QuotaSize = 0
mappedPath1 := filepath.Join(os.TempDir(), "vdir1")
folderName1 := filepath.Base(mappedPath1)
vdirPath1 := "/vdir1" //nolint:goconst
vdirPath1 := "/vdir1"
mappedPath2 := filepath.Join(os.TempDir(), "vdir2")
folderName2 := filepath.Base(mappedPath2)
vdirPath2 := "/vdir2" //nolint:goconst
vdirPath2 := "/vdir2"
mappedPath3 := filepath.Join(os.TempDir(), "vdir3")
folderName3 := filepath.Base(mappedPath3)
vdirPath3 := "/vdir3"
@@ -1613,7 +1613,7 @@ func TestVirtualFoldersQuotaRenameOverwrite(t *testing.T) {
assert.NoError(t, err)
err = writeSFTPFile(path.Join(vdirPath3, testFileName+"1"), testFileSize, client)
assert.NoError(t, err)
err = client.Rename(testFileName, path.Join(vdirPath1, testFileName+".rename")) //nolint:goconst
err = client.Rename(testFileName, path.Join(vdirPath1, testFileName+".rename"))
assert.Error(t, err)
// we overwrite an existing file and we have unlimited size
err = client.Rename(testFileName, path.Join(vdirPath1, testFileName))
@@ -1882,8 +1882,8 @@ func TestQuotaRenameInsideSameVirtualFolder(t *testing.T) {
testFileName1 := "test_file1.dat"
testFileSize := int64(131072)
testFileSize1 := int64(65535)
dir1 := "dir1" //nolint:goconst
dir2 := "dir2" //nolint:goconst
dir1 := "dir1"
dir2 := "dir2"
assert.NoError(t, err)
err = client.Mkdir(path.Join(vdirPath1, dir1))
assert.NoError(t, err)
@@ -2808,7 +2808,7 @@ func TestVirtualFoldersLink(t *testing.T) {
assert.NoError(t, err)
err = client.Symlink(path.Join(vdirPath2, testFileName), path.Join(vdirPath2, testDir, testFileName+".link"))
assert.NoError(t, err)
err = client.Symlink(path.Join("/", testFileName), path.Join(vdirPath1, testFileName+".link1")) //nolint:goconst
err = client.Symlink(path.Join("/", testFileName), path.Join(vdirPath1, testFileName+".link1"))
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "SSH_FX_OP_UNSUPPORTED")
}
@@ -4919,7 +4919,7 @@ func TestEventRuleFsActions(t *testing.T) {
assert.NoError(t, err)
_, err = client.Stat(path.Join("basedir", testFileName))
assert.Error(t, err)
info, err := client.Stat(testFileName + "_renamed") //nolint:goconst
info, err := client.Stat(testFileName + "_renamed")
if assert.NoError(t, err) {
assert.Equal(t, size, info.Size())
}
@@ -6190,7 +6190,7 @@ func TestEventActionCompress(t *testing.T) {
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)
info, err := client.Stat(testFileName + ".zip") //nolint:goconst
info, err := client.Stat(testFileName + ".zip")
if assert.NoError(t, err) {
assert.Greater(t, info.Size(), int64(0))
// check quota
+1 -1
View File
@@ -63,7 +63,7 @@ func TestLoadConfigTest(t *testing.T) {
assert.NotEqual(t, sftpd.Configuration{}, config.GetSFTPDConfig())
assert.NotEqual(t, httpclient.Config{}, config.GetHTTPConfig())
assert.NotEqual(t, smtp.Config{}, config.GetSMTPConfig())
confName := tempConfigName + ".json" //nolint:goconst
confName := tempConfigName + ".json"
configFilePath := filepath.Join(configDir, confName)
err = config.LoadConfig(configDir, confName)
assert.Error(t, err)
+2 -2
View File
@@ -283,11 +283,11 @@ func TestResumeCryptFs(t *testing.T) {
assert.Equal(t, initialHash, downloadHash)
err = os.Truncate(localDownloadPath, 32767)
assert.NoError(t, err)
err = ftpDownloadFile(testFileName, localDownloadPath+"_partial", testFileSize-32767, client, 32767) //nolint:goconst
err = ftpDownloadFile(testFileName, localDownloadPath+"_partial", testFileSize-32767, client, 32767)
assert.NoError(t, err)
file, err := os.OpenFile(localDownloadPath, os.O_APPEND|os.O_WRONLY, os.ModePerm)
assert.NoError(t, err)
file1, err := os.Open(localDownloadPath + "_partial") //nolint:goconst
file1, err := os.Open(localDownloadPath + "_partial")
assert.NoError(t, err)
_, err = io.Copy(file, file1)
assert.NoError(t, err)
+1 -1
View File
@@ -2390,7 +2390,7 @@ func TestQuotaLimits(t *testing.T) {
// test quota files
client, err := getFTPClient(user, false, nil)
if assert.NoError(t, err) {
err = ftpUploadFile(testFilePath, testFileName+".quota", testFileSize, client, 0) //nolint:goconst
err = ftpUploadFile(testFilePath, testFileName+".quota", testFileSize, client, 0)
assert.NoError(t, err)
err = ftpUploadFile(testFilePath, testFileName+".quota1", testFileSize, client, 0)
assert.Error(t, err)
+1 -1
View File
@@ -168,7 +168,7 @@ func isTLS(r *http.Request) bool {
return true
}
if proto, ok := r.Context().Value(forwardedProtoKey).(string); ok {
return proto == "https" //nolint:goconst
return proto == "https"
}
return false
}
+34 -34
View File
@@ -1913,7 +1913,7 @@ func TestGroupSettingsOverride(t *testing.T) {
assert.Equal(t, group1.UserSettings.Filters.MaxUploadFileSize, user.Filters.MaxUploadFileSize)
assert.Equal(t, "/startdir/"+defaultUsername, user.Filters.StartDirectory)
if assert.Len(t, user.Filters.FilePatterns, 1) {
assert.Equal(t, "/sub2/"+role.Name+"/"+defaultUsername+"test", user.Filters.FilePatterns[0].Path) //nolint:goconst
assert.Equal(t, "/sub2/"+role.Name+"/"+defaultUsername+"test", user.Filters.FilePatterns[0].Path)
}
if assert.Len(t, user.Filters.WebClient, 2) {
assert.Contains(t, user.Filters.WebClient, sdk.WebClientInfoChangeDisabled)
@@ -3784,14 +3784,14 @@ func TestLoginRedirectNext(t *testing.T) {
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err)
uri := webClientFilesPath + "?path=%2F" //nolint:goconst
uri := webClientFilesPath + "?path=%2F"
req, err := http.NewRequest(http.MethodGet, uri, nil)
assert.NoError(t, err)
req.RequestURI = uri
rr := executeRequest(req)
checkResponseCode(t, http.StatusFound, rr)
redirectURI := rr.Header().Get("Location")
assert.Equal(t, webClientLoginPath+"?next="+url.QueryEscape(uri), redirectURI) //nolint:goconst
assert.Equal(t, webClientLoginPath+"?next="+url.QueryEscape(uri), redirectURI)
// render the login page
req, err = http.NewRequest(http.MethodGet, redirectURI, nil)
assert.NoError(t, err)
@@ -5140,7 +5140,7 @@ func TestAddUserNoHomeDir(t *testing.T) {
func TestAddUserInvalidHomeDir(t *testing.T) {
u := getTestUser()
u.HomeDir = "relative_path" //nolint:goconst
u.HomeDir = "relative_path"
_, _, err := httpdtest.AddUser(u, http.StatusBadRequest)
assert.NoError(t, err)
}
@@ -5303,12 +5303,12 @@ func TestAddUserInvalidFsConfig(t *testing.T) {
_, _, err := httpdtest.AddUser(u, http.StatusBadRequest)
assert.NoError(t, err)
u.FsConfig.S3Config.Bucket = "testbucket"
u.FsConfig.S3Config.Region = "eu-west-1" //nolint:goconst
u.FsConfig.S3Config.AccessKey = "access-key" //nolint:goconst
u.FsConfig.S3Config.Region = "eu-west-1"
u.FsConfig.S3Config.AccessKey = "access-key"
u.FsConfig.S3Config.AccessSecret = kms.NewSecret(sdkkms.SecretStatusRedacted, "access-secret", "", "")
u.FsConfig.S3Config.Endpoint = "http://127.0.0.1:9000/path?a=b"
u.FsConfig.S3Config.StorageClass = "Standard" //nolint:goconst
u.FsConfig.S3Config.KeyPrefix = ".." // resolves to the storage root: rejected
u.FsConfig.S3Config.StorageClass = "Standard"
u.FsConfig.S3Config.KeyPrefix = ".." // resolves to the storage root: rejected
_, _, err = httpdtest.AddUser(u, http.StatusBadRequest)
assert.NoError(t, err)
u.FsConfig.S3Config.AccessSecret.SetStatus(sdkkms.SecretStatusPlain)
@@ -5361,14 +5361,14 @@ func TestAddUserInvalidFsConfig(t *testing.T) {
assert.NoError(t, err)
u.FsConfig.GCSConfig.Bucket = "abucket"
u.FsConfig.GCSConfig.StorageClass = "Standard"
u.FsConfig.GCSConfig.KeyPrefix = ".." // resolves to the storage root: rejected
u.FsConfig.GCSConfig.Credentials = kms.NewSecret(sdkkms.SecretStatusRedacted, "test", "", "") //nolint:goconst
u.FsConfig.GCSConfig.KeyPrefix = ".." // resolves to the storage root: rejected
u.FsConfig.GCSConfig.Credentials = kms.NewSecret(sdkkms.SecretStatusRedacted, "test", "", "")
_, _, err = httpdtest.AddUser(u, http.StatusBadRequest)
assert.NoError(t, err)
u.FsConfig.GCSConfig.Credentials.SetStatus(sdkkms.SecretStatusPlain)
_, _, err = httpdtest.AddUser(u, http.StatusBadRequest)
assert.NoError(t, err)
u.FsConfig.GCSConfig.KeyPrefix = "somedir/subdir/" //nolint:goconst
u.FsConfig.GCSConfig.KeyPrefix = "somedir/subdir/"
u.FsConfig.GCSConfig.Credentials = kms.NewEmptySecret()
u.FsConfig.GCSConfig.AutomaticCredentials = 0
_, _, err = httpdtest.AddUser(u, http.StatusBadRequest)
@@ -6275,7 +6275,7 @@ func TestUserS3Config(t *testing.T) {
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err)
user.FsConfig.Provider = sdk.S3FilesystemProvider
user.FsConfig.S3Config.Bucket = "test" //nolint:goconst
user.FsConfig.S3Config.Bucket = "test"
user.FsConfig.S3Config.AccessKey = "Server-Access-Key"
user.FsConfig.S3Config.AccessSecret = kms.NewPlainSecret("Server-Access-Secret")
user.FsConfig.S3Config.SSECustomerKey = kms.NewPlainSecret("SSE-encryption-key")
@@ -6355,10 +6355,10 @@ func TestUserS3Config(t *testing.T) {
assert.Empty(t, user.FsConfig.S3Config.AccessSecret.GetKey())
user.FsConfig.Provider = sdk.S3FilesystemProvider
user.FsConfig.S3Config.Bucket = "test-bucket"
user.FsConfig.S3Config.Region = "us-east-1" //nolint:goconst
user.FsConfig.S3Config.Region = "us-east-1"
user.FsConfig.S3Config.AccessKey = "Server-Access-Key1"
user.FsConfig.S3Config.Endpoint = "http://localhost:9000"
user.FsConfig.S3Config.KeyPrefix = "somedir/subdir" //nolint:goconst
user.FsConfig.S3Config.KeyPrefix = "somedir/subdir"
user.FsConfig.S3Config.UploadConcurrency = 5
user.FsConfig.S3Config.DownloadConcurrency = 4
user, bb, err := httpdtest.UpdateUser(user, http.StatusOK, "")
@@ -7591,7 +7591,7 @@ func TestNamingRules(t *testing.T) {
assert.NoError(t, err)
userAPIToken, err := getJWTAPIUserTokenFromTestServer(user.Username, defaultPassword)
assert.NoError(t, err)
req, err = http.NewRequest(http.MethodPut, userPath+"/"+user.Username+"/2fa/disable", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodPut, userPath+"/"+user.Username+"/2fa/disable", nil)
assert.NoError(t, err)
setBearerForReq(req, adminAPIToken)
rr = executeRequest(req)
@@ -12143,7 +12143,7 @@ func TestWebAPIChangeUserProfileMock(t *testing.T) {
profileReq = make(map[string]any)
profileReq["allow_api_key_auth"] = false
profileReq["email"] = email
profileReq["description"] = description + "_mod" //nolint:goconst
profileReq["description"] = description + "_mod"
profileReq["public_keys"] = []string{testPubKey}
profileReq["tls_certs"] = []string{}
asJSON, err = json.Marshal(profileReq)
@@ -12854,7 +12854,7 @@ func TestUpdateUserQuotaUsageMock(t *testing.T) {
// now update only quota size
u.UsedQuotaFiles = 0
userAsJSON = getUserAsJSON(t, u)
req, _ = http.NewRequest(http.MethodPut, path.Join(quotasBasePath, "users", u.Username, "usage")+"?mode=add", bytes.NewBuffer(userAsJSON)) //nolint:goconst
req, _ = http.NewRequest(http.MethodPut, path.Join(quotasBasePath, "users", u.Username, "usage")+"?mode=add", bytes.NewBuffer(userAsJSON))
setBearerForReq(req, token)
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
@@ -13651,7 +13651,7 @@ func TestWebAPILoginMock(t *testing.T) {
checkResponseCode(t, http.StatusUnauthorized, rr)
assert.Contains(t, rr.Body.String(), "Your token audience is not valid")
req, err = http.NewRequest(http.MethodGet, userDirsPath+"/?path=%2F", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, userDirsPath+"/?path=%2F", nil)
assert.NoError(t, err)
setBearerForReq(req, apiToken)
rr = executeRequest(req)
@@ -14093,7 +14093,7 @@ func TestMaxSessions(t *testing.T) {
checkResponseCode(t, http.StatusTooManyRequests, rr)
assert.Contains(t, rr.Body.String(), util.I18nError429Message)
req, err = http.NewRequest(http.MethodGet, webClientEditFilePath+"?path=file", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, webClientEditFilePath+"?path=file", nil)
assert.NoError(t, err)
setJWTCookieForReq(req, webToken)
rr = executeRequest(req)
@@ -14991,7 +14991,7 @@ func TestPreDownloadHook(t *testing.T) {
assert.NoError(t, err)
webAPIToken, err := getJWTAPIUserTokenFromTestServer(defaultUsername, defaultPassword)
assert.NoError(t, err)
req, err := http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil) //nolint:goconst
req, err := http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil)
assert.NoError(t, err)
setJWTCookieForReq(req, webToken)
rr := executeRequest(req)
@@ -16229,7 +16229,7 @@ func TestShareMaxSessions(t *testing.T) {
objectID := rr.Header().Get("X-Object-ID")
assert.NotEmpty(t, objectID)
req, err = http.NewRequest(http.MethodGet, sharesPath+"/"+objectID+"/dirs", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, sharesPath+"/"+objectID+"/dirs", nil)
assert.NoError(t, err)
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
@@ -16550,7 +16550,7 @@ func TestShareReadWrite(t *testing.T) {
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
req, err = http.NewRequest(http.MethodGet, path.Join(webClientPubSharesPath, objectID, "browse?path="+testFileName), nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, path.Join(webClientPubSharesPath, objectID, "browse?path="+testFileName), nil)
assert.NoError(t, err)
req.SetBasicAuth(defaultUsername, defaultPassword)
rr = executeRequest(req)
@@ -16664,7 +16664,7 @@ func TestShareUncompressed(t *testing.T) {
checkResponseCode(t, http.StatusOK, rr)
assert.Equal(t, "application/zip", rr.Header().Get("Content-Type"))
req, err = http.NewRequest(http.MethodGet, webClientPubSharesPath+"/"+objectID+"?compress=false", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, webClientPubSharesPath+"/"+objectID+"?compress=false", nil)
assert.NoError(t, err)
req.SetBasicAuth(defaultUsername, defaultPassword)
rr = executeRequest(req)
@@ -16917,7 +16917,7 @@ func TestBrowseShares(t *testing.T) {
checkResponseCode(t, http.StatusBadRequest, rr)
assert.Contains(t, rr.Body.String(), util.I18nErrorPathInvalid)
req, err = http.NewRequest(http.MethodGet, path.Join(sharesPath, objectID, "files?path="+testFileName), nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, path.Join(sharesPath, objectID, "files?path="+testFileName), nil)
assert.NoError(t, err)
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
@@ -18044,7 +18044,7 @@ func TestWebClientViewPDF(t *testing.T) {
err = os.WriteFile(filepath.Join(user.GetHomeDir(), "test.pdf"), []byte("some text data"), 0666)
assert.NoError(t, err)
req, err = http.NewRequest(http.MethodGet, webClientGetPDFPath+"?path=%2Ftest.pdf", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, webClientGetPDFPath+"?path=%2Ftest.pdf", nil)
assert.NoError(t, err)
setJWTCookieForReq(req, webToken)
rr = executeRequest(req)
@@ -18319,7 +18319,7 @@ func TestWebGetFiles(t *testing.T) {
checkResponseCode(t, http.StatusBadRequest, rr)
assert.Contains(t, rr.Body.String(), util.I18nError400Message)
req, _ = http.NewRequest(http.MethodGet, webClientDirsPath+"?path=/", nil) //nolint:goconst
req, _ = http.NewRequest(http.MethodGet, webClientDirsPath+"?path=/", nil)
setJWTCookieForReq(req, webToken)
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
@@ -18579,7 +18579,7 @@ func TestRenameDifferentResource(t *testing.T) {
assert.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, userFileActionsPath+"/move?path="+testFileName+"&target="+url.QueryEscape(path.Join("/", "folderPath", testFileName)), nil) //nolint:goconst
req, err := http.NewRequest(http.MethodPost, userFileActionsPath+"/move?path="+testFileName+"&target="+url.QueryEscape(path.Join("/", "folderPath", testFileName)), nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr := executeRequest(req)
@@ -18691,13 +18691,13 @@ func TestWebDirsAPI(t *testing.T) {
assert.Len(t, contents, 0)
// rename a missing folder
req, err = http.NewRequest(http.MethodPost, userFileActionsPath+"/move?path="+testDir+"&target="+testDir+"new", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodPost, userFileActionsPath+"/move?path="+testDir+"&target="+testDir+"new", nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
checkResponseCode(t, http.StatusNotFound, rr)
// copy a missing folder
req, err = http.NewRequest(http.MethodPost, userFileActionsPath+"/copy?path="+testDir+"%2F&target="+testDir+"new%2F", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodPost, userFileActionsPath+"/copy?path="+testDir+"%2F&target="+testDir+"new%2F", nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
@@ -18753,7 +18753,7 @@ func TestWebDirsAPI(t *testing.T) {
rr = executeRequest(req)
checkResponseCode(t, http.StatusNotFound, rr)
// setting the mkdir_parents param will work
req, err = http.NewRequest(http.MethodPost, userDirsPath+"?mkdir_parents=true&path="+url.QueryEscape(path.Join("/sub/dir", testDir)), nil) //nolint:goconst
req, err = http.NewRequest(http.MethodPost, userDirsPath+"?mkdir_parents=true&path="+url.QueryEscape(path.Join("/sub/dir", testDir)), nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
@@ -18893,7 +18893,7 @@ func TestWebUploadSingleFile(t *testing.T) {
assert.Contains(t, rr.Body.String(), "please set a file path")
modTime := time.Now().Add(-24 * time.Hour)
req, err = http.NewRequest(http.MethodPost, userUploadFilePath+"?path=file.txt", bytes.NewBuffer(content)) //nolint:goconst
req, err = http.NewRequest(http.MethodPost, userUploadFilePath+"?path=file.txt", bytes.NewBuffer(content))
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
req.Header.Set("X-SFTPGO-MTIME", strconv.FormatInt(util.GetTimeAsMsSinceEpoch(modTime), 10))
@@ -18941,7 +18941,7 @@ func TestWebUploadSingleFile(t *testing.T) {
assert.InDelta(t, util.GetTimeAsMsSinceEpoch(modTime), util.GetTimeAsMsSinceEpoch(info.ModTime()), float64(1000))
}
// missing file
req, err = http.NewRequest(http.MethodPatch, userFilesDirsMetadataPath+"?path=file2.txt", bytes.NewBuffer(asJSON)) //nolint:goconst
req, err = http.NewRequest(http.MethodPatch, userFilesDirsMetadataPath+"?path=file2.txt", bytes.NewBuffer(asJSON))
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
@@ -19630,7 +19630,7 @@ func TestWebFilesAPI(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, contents, 2)
// download a file
req, err = http.NewRequest(http.MethodGet, userFilesPath+"?path=file1.txt", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, userFilesPath+"?path=file1.txt", nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
@@ -20467,7 +20467,7 @@ func TestWebUploadErrors(t *testing.T) {
checkResponseCode(t, http.StatusForbidden, rr)
assert.Contains(t, rr.Body.String(), "Error checking parent directories")
// create a dir and try to overwrite it with a file
req, err = http.NewRequest(http.MethodPost, userDirsPath+"?path=file.zip", nil) //nolint:goconst
req, err = http.NewRequest(http.MethodPost, userDirsPath+"?path=file.zip", nil)
assert.NoError(t, err)
setBearerForReq(req, webAPIToken)
rr = executeRequest(req)
+1 -1
View File
@@ -1253,7 +1253,7 @@ func TestOAuth2Redirect(t *testing.T) {
ip := "127.1.1.4"
tokenString := createOAuth2Token(server.csrfTokenAuth, xid.New().String(), ip)
rr = httptest.NewRecorder()
req, err = http.NewRequest(http.MethodGet, webOAuth2RedirectPath+"?state="+tokenString, nil) //nolint:goconst
req, err = http.NewRequest(http.MethodGet, webOAuth2RedirectPath+"?state="+tokenString, nil)
assert.NoError(t, err)
req.RemoteAddr = ip
server.handleOAuth2TokenRedirect(rr, req)
+1 -1
View File
@@ -56,7 +56,7 @@ func validateJWTToken(w http.ResponseWriter, r *http.Request, audience tokenAudi
} else {
redirectPath = webClientLoginPath
if uri := r.RequestURI; strings.HasPrefix(uri, webClientFilesPath) {
redirectPath += "?next=" + url.QueryEscape(uri) //nolint:goconst
redirectPath += "?next=" + url.QueryEscape(uri)
}
}
+1 -1
View File
@@ -1961,7 +1961,7 @@ func TestOIDCEvMgrIntegration(t *testing.T) {
Nonce: authReq.Nonce,
Expiry: time.Now().Add(5 * time.Minute),
}
setIDTokenClaims(idToken, []byte(`{"preferred_username":"`+util.JSONEscape(username)+`","custom1":{"sub":"val1"},"custom2":"desc"}`)) //nolint:goconst
setIDTokenClaims(idToken, []byte(`{"preferred_username":"`+util.JSONEscape(username)+`","custom1":{"sub":"val1"},"custom2":"desc"}`))
server.binding.OIDC.verifier = &mockOIDCVerifier{
err: nil,
token: idToken,
+5 -5
View File
@@ -1415,12 +1415,12 @@ func (s *httpdServer) setupRESTAPIRoutes() {
router.With(s.checkPerms(dataprovider.PermAdminQuotaScans)).Post(quotasBasePath+"/folders/{name}/scan", startFolderQuotaScan)
router.With(s.checkPerms(dataprovider.PermAdminViewUsers)).Get(userPath, getUsers)
router.With(s.checkPerms(dataprovider.PermAdminAddUsers)).Post(userPath, addUser)
router.With(s.checkPerms(dataprovider.PermAdminViewUsers)).Get(userPath+"/{username}", getUserByUsername) //nolint:goconst
router.With(s.checkPerms(dataprovider.PermAdminViewUsers)).Get(userPath+"/{username}", getUserByUsername)
router.With(s.checkPerms(dataprovider.PermAdminChangeUsers)).Put(userPath+"/{username}", updateUser)
router.With(s.checkPerms(dataprovider.PermAdminDeleteUsers)).Delete(userPath+"/{username}", deleteUser)
router.With(s.checkPerms(dataprovider.PermAdminDisableMFA)).Put(userPath+"/{username}/2fa/disable", disableUser2FA) //nolint:goconst
router.With(s.checkPerms(dataprovider.PermAdminDisableMFA)).Put(userPath+"/{username}/2fa/disable", disableUser2FA)
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Get(folderPath, getFolders)
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Get(folderPath+"/{name}", getFolderByName) //nolint:goconst
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Get(folderPath+"/{name}", getFolderByName)
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Post(folderPath, addFolder)
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Put(folderPath+"/{name}", updateFolder)
router.With(s.checkPerms(dataprovider.PermAdminManageFolders)).Delete(folderPath+"/{name}", deleteFolder)
@@ -1470,9 +1470,9 @@ func (s *httpdServer) setupRESTAPIRoutes() {
router.With(s.checkPerms(dataprovider.PermAdminAny)).Get(rolesPath+"/{name}", getRoleByName)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Put(rolesPath+"/{name}", updateRole)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Delete(rolesPath+"/{name}", deleteRole)
router.With(s.checkPerms(dataprovider.PermAdminAny), compressor.Handler).Get(ipListsPath+"/{type}", getIPListEntries) //nolint:goconst
router.With(s.checkPerms(dataprovider.PermAdminAny), compressor.Handler).Get(ipListsPath+"/{type}", getIPListEntries)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Post(ipListsPath+"/{type}", addIPListEntry)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Get(ipListsPath+"/{type}/{ipornet}", getIPListEntry) //nolint:goconst
router.With(s.checkPerms(dataprovider.PermAdminAny)).Get(ipListsPath+"/{type}/{ipornet}", getIPListEntry)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Put(ipListsPath+"/{type}/{ipornet}", updateIPListEntry)
router.With(s.checkPerms(dataprovider.PermAdminAny)).Delete(ipListsPath+"/{type}/{ipornet}", deleteIPListEntry)
})
+1 -1
View File
@@ -478,7 +478,7 @@ func (fs *httpFsImpl) configureRouter() {
fs.router = chi.NewRouter()
fs.router.Use(middleware.Recoverer)
fs.router.Get(statPath+"/{name}", fs.stat) //nolint:goconst
fs.router.Get(statPath+"/{name}", fs.stat)
fs.router.Get(openPath+"/{name}", fs.open)
fs.router.Post(createPath+"/{name}", fs.create)
fs.router.Patch(renamePath+"/{name}", fs.rename)
+2 -2
View File
@@ -241,7 +241,7 @@ func TestQuotaFileReplaceCryptFs(t *testing.T) {
assert.Equal(t, expectedQuotaSize, user.UsedQuotaSize)
// now create a symlink, replace it with a file and check the quota
// replacing a symlink is like uploading a new file
err = client.Symlink(testFileName, testFileName+".link") //nolint:goconst
err = client.Symlink(testFileName, testFileName+".link")
assert.NoError(t, err)
user, _, err = httpdtest.GetUserByUsername(user.Username, http.StatusOK)
assert.NoError(t, err)
@@ -456,7 +456,7 @@ func TestSCPRecursiveCryptFs(t *testing.T) {
assert.NoError(t, err)
testBaseDirName := "atestdir"
testBaseDirPath := filepath.Join(homeBasePath, testBaseDirName)
testBaseDirDownName := "test_dir_down" //nolint:goconst
testBaseDirDownName := "test_dir_down"
testBaseDirDownPath := filepath.Join(homeBasePath, testBaseDirDownName)
testFilePath := filepath.Join(homeBasePath, testBaseDirName, testFileName)
testFilePath1 := filepath.Join(homeBasePath, testBaseDirName, testBaseDirName, testFileName)
+2 -2
View File
@@ -184,7 +184,7 @@ func TestGetOSOpenFlags(t *testing.T) {
}
func TestUploadResumeInvalidOffset(t *testing.T) {
testfile := "testfile" //nolint:goconst
testfile := "testfile"
file, err := os.Create(testfile)
assert.NoError(t, err)
user := dataprovider.User{
@@ -368,7 +368,7 @@ func TestUploadFiles(t *testing.T) {
func TestWithInvalidHome(t *testing.T) {
u := dataprovider.User{}
u.HomeDir = "home_rel_path" //nolint:goconst
u.HomeDir = "home_rel_path"
_, err := loginUser(&u, dataprovider.LoginMethodPassword, "", nil)
assert.Error(t, err, "login a user with an invalid home_dir must fail")
+24 -24
View File
@@ -2099,7 +2099,7 @@ func TestChtimes(t *testing.T) {
defer client.Close()
testFilePath := filepath.Join(homeBasePath, testFileName)
testFileSize := int64(65535)
testDir := "test" //nolint:goconst
testDir := "test"
err = createTestFile(testFilePath, testFileSize)
assert.NoError(t, err)
err = sftpUploadFile(testFilePath, testFileName, testFileSize, client)
@@ -2166,7 +2166,7 @@ func TestEscapeHomeDir(t *testing.T) {
defer conn.Close()
defer client.Close()
assert.NoError(t, checkBasicSFTP(client))
testDir := "testDir" //nolint:goconst
testDir := "testDir"
linkPath := filepath.Join(homeBasePath, defaultUsername, testDir)
err = os.Symlink(homeBasePath, linkPath)
assert.NoError(t, err)
@@ -5375,7 +5375,7 @@ func TestQuotaDisabledError(t *testing.T) {
assert.NoError(t, err)
err = sftpUploadFile(testFilePath, testFileName+"1", testFileSize, client)
assert.NoError(t, err)
err = client.Rename(testFileName+"1", testFileName+".rename") //nolint:goconst
err = client.Rename(testFileName+"1", testFileName+".rename")
assert.NoError(t, err)
err = os.Remove(testFilePath)
assert.NoError(t, err)
@@ -5690,7 +5690,7 @@ func TestQuotaRename(t *testing.T) {
assert.NoError(t, err)
testFileSize := int64(65535)
testFileSize1 := int64(65537)
testFileName1 := "test_file1.dat" //nolint:goconst
testFileName1 := "test_file1.dat"
testFilePath := filepath.Join(homeBasePath, testFileName)
testFilePath1 := filepath.Join(homeBasePath, testFileName1)
for _, user := range []dataprovider.User{localUser, sftpUser} {
@@ -5718,7 +5718,7 @@ func TestQuotaRename(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, user.UsedQuotaFiles)
assert.Equal(t, testFileSize1, user.UsedQuotaSize)
err = client.Symlink(testFileName+".rename", testFileName+".symlink") //nolint:goconst
err = client.Symlink(testFileName+".rename", testFileName+".symlink")
assert.NoError(t, err)
err = sftpUploadFile(testFilePath, testFileName, testFileSize, client)
assert.NoError(t, err)
@@ -5855,7 +5855,7 @@ func TestQuotaLimits(t *testing.T) {
err = createTestFile(testFilePath1, testFileSize1)
assert.NoError(t, err)
testFileSize2 := int64(32768)
testFileName2 := "test_file2.dat" //nolint:goconst
testFileName2 := "test_file2.dat"
testFilePath2 := filepath.Join(homeBasePath, testFileName2)
err = createTestFile(testFilePath2, testFileSize2)
assert.NoError(t, err)
@@ -5865,7 +5865,7 @@ func TestQuotaLimits(t *testing.T) {
if assert.NoError(t, err) {
defer conn.Close()
defer client.Close()
err = sftpUploadFile(testFilePath, testFileName+".quota", testFileSize, client) //nolint:goconst
err = sftpUploadFile(testFilePath, testFileName+".quota", testFileSize, client)
assert.NoError(t, err)
err = sftpUploadFile(testFilePath, testFileName+".quota.1", testFileSize, client)
if assert.Error(t, err, "user is over quota files, upload must fail") {
@@ -6648,10 +6648,10 @@ func TestVirtualFoldersQuotaLimit(t *testing.T) {
u1.QuotaFiles = 1
mappedPath1 := filepath.Join(os.TempDir(), "vdir1")
folderName1 := filepath.Base(mappedPath1)
vdirPath1 := "/vdir1" //nolint:goconst
vdirPath1 := "/vdir1"
mappedPath2 := filepath.Join(os.TempDir(), "vdir2")
folderName2 := filepath.Base(mappedPath2)
vdirPath2 := "/vdir2" //nolint:goconst
vdirPath2 := "/vdir2"
u1.VirtualFolders = append(u1.VirtualFolders, vfs.VirtualFolder{
BaseVirtualFolder: vfs.BaseVirtualFolder{
Name: folderName1,
@@ -7651,10 +7651,10 @@ func TestVirtualFoldersQuotaValues(t *testing.T) {
u := getTestUser(usePubKey)
u.QuotaFiles = 100
mappedPath1 := filepath.Join(os.TempDir(), "vdir1")
vdirPath1 := "/vdir1" //nolint:goconst
vdirPath1 := "/vdir1"
folderName1 := filepath.Base(mappedPath1)
mappedPath2 := filepath.Join(os.TempDir(), "vdir2")
vdirPath2 := "/vdir2" //nolint:goconst
vdirPath2 := "/vdir2"
folderName2 := filepath.Base(mappedPath2)
u.VirtualFolders = append(u.VirtualFolders, vfs.VirtualFolder{
BaseVirtualFolder: vfs.BaseVirtualFolder{
@@ -7811,8 +7811,8 @@ func TestQuotaRenameInsideSameVirtualFolder(t *testing.T) {
testFileSize1 := int64(65535)
testFilePath := filepath.Join(homeBasePath, testFileName)
testFilePath1 := filepath.Join(homeBasePath, testFileName1)
dir1 := "dir1" //nolint:goconst
dir2 := "dir2" //nolint:goconst
dir1 := "dir1"
dir2 := "dir2"
err = createTestFile(testFilePath, testFileSize)
assert.NoError(t, err)
err = createTestFile(testFilePath1, testFileSize1)
@@ -8720,7 +8720,7 @@ func TestVirtualFoldersLink(t *testing.T) {
assert.NoError(t, err)
err = client.Symlink(path.Join(vdirPath2, testFileName), path.Join(vdirPath2, testDir, testFileName+".link"))
assert.NoError(t, err)
err = client.Symlink(path.Join("/", testFileName), path.Join(vdirPath1, testFileName+".link1")) //nolint:goconst
err = client.Symlink(path.Join("/", testFileName), path.Join(vdirPath1, testFileName+".link1"))
assert.Error(t, err)
err = client.Symlink(path.Join("/", testFileName), path.Join(vdirPath1, testDir, testFileName+".link1"))
assert.Error(t, err)
@@ -9043,7 +9043,7 @@ func TestOverwriteDirWithFile(t *testing.T) {
defer conn.Close()
defer client.Close()
testFileSize := int64(65535)
testDirName := "test_dir" //nolint:goconst
testDirName := "test_dir"
testFilePath := filepath.Join(homeBasePath, testFileName)
err = createTestFile(testFilePath, testFileSize)
assert.NoError(t, err)
@@ -9657,7 +9657,7 @@ func TestSubDirsOverwrite(t *testing.T) {
if assert.NoError(t, err) {
defer conn.Close()
defer client.Close()
testFileName := "/subdir/test_file.dat" //nolint:goconst
testFileName := "/subdir/test_file.dat"
testFilePath := filepath.Join(homeBasePath, "test_file.dat")
testFileSFTPPath := filepath.Join(u.GetHomeDir(), "subdir", "test_file.dat")
testFileSize := int64(65535)
@@ -10074,7 +10074,7 @@ func TestResolvePaths(t *testing.T) {
func TestVirtualRelativePaths(t *testing.T) {
user := getTestUser(true)
mappedPath := filepath.Join(os.TempDir(), "mdir")
vdirPath := "/vdir" //nolint:goconst
vdirPath := "/vdir"
user.VirtualFolders = append(user.VirtualFolders, vfs.VirtualFolder{
BaseVirtualFolder: vfs.BaseVirtualFolder{
MappedPath: mappedPath,
@@ -10855,11 +10855,11 @@ func TestSSHCopy(t *testing.T) {
assert.Equal(t, 6, user.UsedQuotaFiles)
assert.Equal(t, 3*testFileSize+3*testFileSize1, user.UsedQuotaSize)
}
out, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", path.Join(vdirPath2, testDir1, testFileName), testFileName+".copy"), //nolint:goconst
out, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", path.Join(vdirPath2, testDir1, testFileName), testFileName+".copy"),
user, usePubKey)
if assert.NoError(t, err) {
assert.Equal(t, "OK\n", string(out))
fi, err := client.Stat(testFileName + ".copy") //nolint:goconst
fi, err := client.Stat(testFileName + ".copy")
if assert.NoError(t, err) {
assert.True(t, fi.Mode().IsRegular())
}
@@ -10868,7 +10868,7 @@ func TestSSHCopy(t *testing.T) {
assert.Equal(t, 7, user.UsedQuotaFiles)
assert.Equal(t, 4*testFileSize+3*testFileSize1, user.UsedQuotaSize)
}
out, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", path.Join(vdirPath1, testDir1), path.Join(vdirPath2, testDir1+"copy")), //nolint:goconst
out, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", path.Join(vdirPath1, testDir1), path.Join(vdirPath2, testDir1+"copy")),
user, usePubKey)
if assert.NoError(t, err) {
assert.Equal(t, "OK\n", string(out))
@@ -11105,7 +11105,7 @@ func TestSSHCopyQuotaLimits(t *testing.T) {
assert.NoError(t, err)
// user quota: 2 files, size: 32768*2, folder2 quota: 2 files, size: 32768*2
// try to duplicate testDir, this will result in 4 file (over quota) and 32768*4 bytes (not over quota)
_, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", testDir, testDir+"_copy"), user, usePubKey) //nolint:goconst
_, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", testDir, testDir+"_copy"), user, usePubKey)
assert.Error(t, err)
_, err = runSSHCommand(fmt.Sprintf("sftpgo-copy %v %v", path.Join(vdirPath2, testDir),
path.Join(vdirPath2, testDir+"_copy")), user, usePubKey)
@@ -11489,7 +11489,7 @@ func TestSSHCommandMaxTransfers(t *testing.T) {
user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err)
repoName := "testrepo" //nolint:goconst
repoName := "testrepo"
clonePath := filepath.Join(homeBasePath, repoName)
err = os.RemoveAll(user.GetHomeDir())
assert.NoError(t, err)
@@ -11705,7 +11705,7 @@ func TestSCPRecursive(t *testing.T) {
assert.NoError(t, err)
testBaseDirName := "test_dir"
testBaseDirPath := filepath.Join(homeBasePath, testBaseDirName)
testBaseDirDownName := "test_dir_down" //nolint:goconst
testBaseDirDownName := "test_dir_down"
testBaseDirDownPath := filepath.Join(homeBasePath, testBaseDirDownName)
testFilePath := filepath.Join(homeBasePath, testBaseDirName, testFileName)
testFilePath1 := filepath.Join(homeBasePath, testBaseDirName, testBaseDirName, testFileName)
@@ -13129,7 +13129,7 @@ func sftpUploadFile(localSourcePath string, remoteDestPath string, expectedSize
return err
}
func sftpUploadResumeFile(localSourcePath string, expectedSize int64, invalidOffset bool, //nolint:unparam
func sftpUploadResumeFile(localSourcePath string, expectedSize int64, invalidOffset bool,
client *sftp.Client) error {
srcFile, err := os.Open(localSourcePath)
if err != nil {
+3 -3
View File
@@ -613,7 +613,7 @@ func TestBasicHandling(t *testing.T) {
files, err := client.ReadDir(testDir)
assert.NoError(t, err)
assert.Len(t, files, 5)
err = client.Copy(testDir, testDir+"_copy", false) //nolint:goconst
err = client.Copy(testDir, testDir+"_copy", false)
assert.NoError(t, err)
err = client.RemoveAll(testDir)
assert.NoError(t, err)
@@ -2132,7 +2132,7 @@ func TestQuotaLimits(t *testing.T) {
assert.NoError(t, err)
client := getWebDavClient(user, false, nil)
// test quota files
err = uploadFileWithRawClient(testFilePath, testFileName+".quota", user.Username, defaultPassword, false, //nolint:goconst
err = uploadFileWithRawClient(testFilePath, testFileName+".quota", user.Username, defaultPassword, false,
testFileSize, client)
if !assert.NoError(t, err, "username: %v", user.Username) {
info, err := os.Stat(testFilePath)
@@ -2934,7 +2934,7 @@ func TestMiscCommands(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 6, user.UsedQuotaFiles)
assert.Equal(t, 6*testFileSize, user.UsedQuotaSize)
err = client.Copy(dir, dir+"_copy1", false) //nolint:goconst
err = client.Copy(dir, dir+"_copy1", false)
assert.NoError(t, err)
err = client.Copy(dir+"_copy", dir+"_copy1", false)
assert.Error(t, err)