Use new methods in the io and os packages instead of ioutil ones

ioutil is deprecated in Go 1.16 and SFTPGo is an application, not
a library, we have no reason to keep compatibility with old Go
versions.

Go 1.16 fix some cifs related issues too.
This commit is contained in:
Nicola Murino 2021-02-25 21:53:04 +01:00
parent 4b2edff6dd
commit ca3e15578e
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
37 changed files with 211 additions and 232 deletions

View file

@ -15,9 +15,9 @@ jobs:
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest]
upload-coverage: [true] upload-coverage: [true]
include: include:
- go: 1.15 #- go: 1.15
os: ubuntu-latest # os: ubuntu-latest
upload-coverage: false # upload-coverage: false
- go: 1.16 - go: 1.16
os: windows-latest os: windows-latest
upload-coverage: false upload-coverage: false
@ -268,7 +268,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run golangci-lint - name: Run golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: latest version: latest
skip-go-installation: true

View file

@ -4,7 +4,6 @@ package cmd
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -384,7 +383,7 @@ func getFileContents(name string) (string, error) {
if fi.Size() > 1048576 { if fi.Size() > 1048576 {
return "", fmt.Errorf("%#v is too big %v/1048576 bytes", name, fi.Size()) return "", fmt.Errorf("%#v is too big %v/1048576 bytes", name, fi.Size())
} }
contents, err := ioutil.ReadFile(name) contents, err := os.ReadFile(name)
if err != nil { if err != nil {
return "", err return "", err
} }

View file

@ -3,7 +3,6 @@ package common
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -184,7 +183,7 @@ func TestPreDeleteAction(t *testing.T) {
c := NewBaseConnection("id", ProtocolSFTP, user, fs) c := NewBaseConnection("id", ProtocolSFTP, user, fs)
testfile := filepath.Join(user.HomeDir, "testfile") testfile := filepath.Join(user.HomeDir, "testfile")
err = ioutil.WriteFile(testfile, []byte("test"), os.ModePerm) err = os.WriteFile(testfile, []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
info, err := os.Stat(testfile) info, err := os.Stat(testfile)
assert.NoError(t, err) assert.NoError(t, err)

View file

@ -1,7 +1,6 @@
package common package common
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -165,7 +164,7 @@ func TestRemoveFile(t *testing.T) {
assert.EqualError(t, err, c.GetPermissionDeniedError().Error()) assert.EqualError(t, err, c.GetPermissionDeniedError().Error())
} }
testFile := filepath.Join(mappedPath, "afile") testFile := filepath.Join(mappedPath, "afile")
err = ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err = os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
info, err := os.Stat(testFile) info, err := os.Stat(testFile)
assert.NoError(t, err) assert.NoError(t, err)
@ -225,7 +224,7 @@ func TestRemoveDir(t *testing.T) {
testDir := filepath.Join(user.GetHomeDir(), "testDir") testDir := filepath.Join(user.GetHomeDir(), "testDir")
err = c.RemoveDir(testDir, "testDir") err = c.RemoveDir(testDir, "testDir")
assert.Error(t, err) assert.Error(t, err)
err = ioutil.WriteFile(testDir, []byte("data"), os.ModePerm) err = os.WriteFile(testDir, []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = c.RemoveDir(testDir, "testDir") err = c.RemoveDir(testDir, "testDir")
if assert.Error(t, err) { if assert.Error(t, err) {
@ -308,10 +307,10 @@ func TestRename(t *testing.T) {
err = c.Rename("missing", "", "", "") err = c.Rename("missing", "", "", "")
assert.Error(t, err) assert.Error(t, err)
testFile := filepath.Join(user.GetHomeDir(), "file") testFile := filepath.Join(user.GetHomeDir(), "file")
err = ioutil.WriteFile(testFile, []byte("data"), os.ModePerm) err = os.WriteFile(testFile, []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
testSubFile := filepath.Join(user.GetHomeDir(), "sub", "file") testSubFile := filepath.Join(user.GetHomeDir(), "sub", "file")
err = ioutil.WriteFile(testSubFile, []byte("data"), os.ModePerm) err = os.WriteFile(testSubFile, []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = c.Rename(testSubFile, filepath.Join(user.GetHomeDir(), "file"), "/sub/file", "/file") err = c.Rename(testSubFile, filepath.Join(user.GetHomeDir(), "file"), "/sub/file", "/file")
if assert.Error(t, err) { if assert.Error(t, err) {
@ -343,7 +342,7 @@ func TestRename(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = os.MkdirAll(filepath.Join(user.GetHomeDir(), "adir"), os.ModePerm) err = os.MkdirAll(filepath.Join(user.GetHomeDir(), "adir"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(user.GetHomeDir(), "adir", "file"), []byte("data"), os.ModePerm) err = os.WriteFile(filepath.Join(user.GetHomeDir(), "adir", "file"), []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = c.Rename(filepath.Join(user.GetHomeDir(), "adir", "file"), filepath.Join(user.GetHomeDir(), "file"), "/adir/file", "/file") err = c.Rename(filepath.Join(user.GetHomeDir(), "adir", "file"), filepath.Join(user.GetHomeDir(), "file"), "/adir/file", "/file")
assert.NoError(t, err) assert.NoError(t, err)
@ -446,7 +445,7 @@ func TestDoStat(t *testing.T) {
} }
u.Permissions = make(map[string][]string) u.Permissions = make(map[string][]string)
u.Permissions["/"] = []string{dataprovider.PermAny} u.Permissions["/"] = []string{dataprovider.PermAny}
err := ioutil.WriteFile(testFile, []byte("data"), os.ModePerm) err := os.WriteFile(testFile, []byte("data"), os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
err = os.Symlink(testFile, testFile+".sym") err = os.Symlink(testFile, testFile+".sym")
require.NoError(t, err) require.NoError(t, err)
@ -468,7 +467,7 @@ func TestDoStat(t *testing.T) {
conn = NewBaseConnection(fs.ConnectionID(), ProtocolFTP, u, fs) conn = NewBaseConnection(fs.ConnectionID(), ProtocolFTP, u, fs)
dataSize := int64(32768) dataSize := int64(32768)
data := make([]byte, dataSize) data := make([]byte, dataSize)
err = ioutil.WriteFile(testFile, data, os.ModePerm) err = os.WriteFile(testFile, data, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
infoStat, err = conn.DoStat(testFile, 0) infoStat, err = conn.DoStat(testFile, 0)
assert.NoError(t, err) assert.NoError(t, err)
@ -615,7 +614,7 @@ func TestSetStat(t *testing.T) {
assert.Error(t, err) assert.Error(t, err)
filePath := filepath.Join(user.GetHomeDir(), "afile.txt") filePath := filepath.Join(user.GetHomeDir(), "afile.txt")
err = ioutil.WriteFile(filePath, []byte("hello"), os.ModePerm) err = os.WriteFile(filePath, []byte("hello"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = c.SetStat(filePath, "/afile.txt", &StatAttributes{ err = c.SetStat(filePath, "/afile.txt", &StatAttributes{
Flags: StatAttrSize, Flags: StatAttrSize,
@ -641,7 +640,7 @@ func TestSetStat(t *testing.T) {
}) })
filePath = filepath.Join(vDir, "afile.txt") filePath = filepath.Join(vDir, "afile.txt")
err = ioutil.WriteFile(filePath, []byte("hello"), os.ModePerm) err = os.WriteFile(filePath, []byte("hello"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = c.SetStat(filePath, "/vpath/afile.txt", &StatAttributes{ err = c.SetStat(filePath, "/vpath/afile.txt", &StatAttributes{
Flags: StatAttrSize, Flags: StatAttrSize,
@ -678,7 +677,7 @@ func TestSpaceForCrossRename(t *testing.T) {
testDir := filepath.Join(os.TempDir(), "dir") testDir := filepath.Join(os.TempDir(), "dir")
err = os.MkdirAll(testDir, os.ModePerm) err = os.MkdirAll(testDir, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(testDir, "afile.txt"), []byte("content"), os.ModePerm) err = os.WriteFile(filepath.Join(testDir, "afile.txt"), []byte("content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = os.Chmod(testDir, 0001) err = os.Chmod(testDir, 0001)
assert.NoError(t, err) assert.NoError(t, err)
@ -690,7 +689,7 @@ func TestSpaceForCrossRename(t *testing.T) {
} }
testFile := filepath.Join(os.TempDir(), "afile.txt") testFile := filepath.Join(os.TempDir(), "afile.txt")
err = ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err = os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
quotaResult = vfs.QuotaCheckResult{ quotaResult = vfs.QuotaCheckResult{
HasSpace: false, HasSpace: false,
@ -732,9 +731,9 @@ func TestSpaceForCrossRename(t *testing.T) {
testDir := filepath.Join(os.TempDir(), "testDir") testDir := filepath.Join(os.TempDir(), "testDir")
err = os.MkdirAll(testDir, os.ModePerm) err = os.MkdirAll(testDir, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(testDir, "1"), []byte("1"), os.ModePerm) err = os.WriteFile(filepath.Join(testDir, "1"), []byte("1"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(testDir, "2"), []byte("2"), os.ModePerm) err = os.WriteFile(filepath.Join(testDir, "2"), []byte("2"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
quotaResult = vfs.QuotaCheckResult{ quotaResult = vfs.QuotaCheckResult{
HasSpace: true, HasSpace: true,
@ -848,7 +847,7 @@ func TestRenamePermission(t *testing.T) {
dir6 := filepath.Join(conn.User.HomeDir, "dir6") dir6 := filepath.Join(conn.User.HomeDir, "dir6")
err = os.MkdirAll(filepath.Join(dir3, "subdir"), os.ModePerm) err = os.MkdirAll(filepath.Join(dir3, "subdir"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir3, "subdir", "testfile"), []byte("test"), os.ModePerm) err = os.WriteFile(filepath.Join(dir3, "subdir", "testfile"), []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = conn.checkRecursiveRenameDirPermissions(dir3, dir6) err = conn.checkRecursiveRenameDirPermissions(dir3, dir6)
assert.NoError(t, err) assert.NoError(t, err)
@ -859,7 +858,7 @@ func TestRenamePermission(t *testing.T) {
dir8 := filepath.Join(conn.User.HomeDir, "dir8") dir8 := filepath.Join(conn.User.HomeDir, "dir8")
err = os.MkdirAll(filepath.Join(dir8, "subdir"), os.ModePerm) err = os.MkdirAll(filepath.Join(dir8, "subdir"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(dir8, "subdir", "testfile"), []byte("test"), os.ModePerm) err = os.WriteFile(filepath.Join(dir8, "subdir", "testfile"), []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = conn.checkRecursiveRenameDirPermissions(dir8, dir7) err = conn.checkRecursiveRenameDirPermissions(dir8, dir7)
assert.NoError(t, err) assert.NoError(t, err)
@ -876,7 +875,7 @@ func TestRenamePermission(t *testing.T) {
}, },
} }
testFile := filepath.Join(user.HomeDir, "testfile") testFile := filepath.Join(user.HomeDir, "testfile")
err = ioutil.WriteFile(testFile, []byte("data"), os.ModePerm) err = os.WriteFile(testFile, []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
info, err = os.Stat(testFile) info, err = os.Stat(testFile)
assert.NoError(t, err) assert.NoError(t, err)
@ -983,13 +982,13 @@ func TestUpdateQuotaAfterRename(t *testing.T) {
request.Filepath = path.Join("/vdir", "file") request.Filepath = path.Join("/vdir", "file")
err = c.updateQuotaAfterRename(request.Filepath, request.Target, filepath.Join(mappedPath, "file"), 0) err = c.updateQuotaAfterRename(request.Filepath, request.Target, filepath.Join(mappedPath, "file"), 0)
assert.Error(t, err) assert.Error(t, err)
err = ioutil.WriteFile(filepath.Join(mappedPath, "file"), []byte("test content"), os.ModePerm) err = os.WriteFile(filepath.Join(mappedPath, "file"), []byte("test content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
request.Filepath = testFile1 request.Filepath = testFile1
request.Target = path.Join("/vdir", "file") request.Target = path.Join("/vdir", "file")
err = c.updateQuotaAfterRename(request.Filepath, request.Target, filepath.Join(mappedPath, "file"), 12) err = c.updateQuotaAfterRename(request.Filepath, request.Target, filepath.Join(mappedPath, "file"), 12)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(user.GetHomeDir(), "testfile1"), []byte("test content"), os.ModePerm) err = os.WriteFile(filepath.Join(user.GetHomeDir(), "testfile1"), []byte("test content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
request.Target = testFile1 request.Target = testFile1
request.Filepath = path.Join("/vdir", "file") request.Filepath = path.Join("/vdir", "file")

View file

@ -3,7 +3,6 @@ package common
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"sort" "sort"
@ -413,7 +412,7 @@ func loadHostListFromFile(name string) (*HostList, error) {
return nil, fmt.Errorf("host list file %#v is too big: %v bytes", name, info.Size()) return nil, fmt.Errorf("host list file %#v is too big: %v bytes", name, info.Size())
} }
content, err := ioutil.ReadFile(name) content, err := os.ReadFile(name)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read input file %#v: %v", name, err) return nil, fmt.Errorf("unable to read input file %#v: %v", name, err)
} }

View file

@ -4,7 +4,6 @@ import (
"crypto/rand" "crypto/rand"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -32,13 +31,13 @@ func TestBasicDefender(t *testing.T) {
data, err := json.Marshal(bl) data, err := json.Marshal(bl)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(blFile, data, os.ModePerm) err = os.WriteFile(blFile, data, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
data, err = json.Marshal(sl) data, err = json.Marshal(sl)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(slFile, data, os.ModePerm) err = os.WriteFile(slFile, data, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
config := &DefenderConfig{ config := &DefenderConfig{
@ -160,7 +159,7 @@ func TestLoadHostListFromFile(t *testing.T) {
_, err = rand.Read(content) _, err = rand.Read(content)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(hostsFilePath, content, os.ModePerm) err = os.WriteFile(hostsFilePath, content, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, err = loadHostListFromFile(hostsFilePath) _, err = loadHostListFromFile(hostsFilePath)
@ -173,7 +172,7 @@ func TestLoadHostListFromFile(t *testing.T) {
asJSON, err := json.Marshal(hl) asJSON, err := json.Marshal(hl)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(hostsFilePath, asJSON, os.ModePerm) err = os.WriteFile(hostsFilePath, asJSON, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
hostList, err := loadHostListFromFile(hostsFilePath) hostList, err := loadHostListFromFile(hostsFilePath)
@ -183,7 +182,7 @@ func TestLoadHostListFromFile(t *testing.T) {
hl.IPAddresses = append(hl.IPAddresses, "invalidip") hl.IPAddresses = append(hl.IPAddresses, "invalidip")
asJSON, err = json.Marshal(hl) asJSON, err = json.Marshal(hl)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(hostsFilePath, asJSON, os.ModePerm) err = os.WriteFile(hostsFilePath, asJSON, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
hostList, err = loadHostListFromFile(hostsFilePath) hostList, err = loadHostListFromFile(hostsFilePath)
@ -195,7 +194,7 @@ func TestLoadHostListFromFile(t *testing.T) {
asJSON, err = json.Marshal(hl) asJSON, err = json.Marshal(hl)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(hostsFilePath, asJSON, os.ModePerm) err = os.WriteFile(hostsFilePath, asJSON, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
hostList, err = loadHostListFromFile(hostsFilePath) hostList, err = loadHostListFromFile(hostsFilePath)
@ -215,7 +214,7 @@ func TestLoadHostListFromFile(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
} }
err = ioutil.WriteFile(hostsFilePath, []byte("non json content"), os.ModePerm) err = os.WriteFile(hostsFilePath, []byte("non json content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, err = loadHostListFromFile(hostsFilePath) _, err = loadHostListFromFile(hostsFilePath)
assert.Error(t, err) assert.Error(t, err)

View file

@ -1,7 +1,6 @@
package common package common
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -20,7 +19,7 @@ func TestBasicAuth(t *testing.T) {
authUserFile := filepath.Join(os.TempDir(), "http_users.txt") authUserFile := filepath.Join(os.TempDir(), "http_users.txt")
authUserData := []byte("test1:$2y$05$bcHSED7aO1cfLto6ZdDBOOKzlwftslVhtpIkRhAtSa4GuLmk5mola\n") authUserData := []byte("test1:$2y$05$bcHSED7aO1cfLto6ZdDBOOKzlwftslVhtpIkRhAtSa4GuLmk5mola\n")
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
httpAuth, err = NewBasicAuthProvider(authUserFile) httpAuth, err = NewBasicAuthProvider(authUserFile)
@ -31,30 +30,30 @@ func TestBasicAuth(t *testing.T) {
require.True(t, httpAuth.ValidateCredentials("test1", "password1")) require.True(t, httpAuth.ValidateCredentials("test1", "password1"))
authUserData = append(authUserData, []byte("test2:$1$OtSSTL8b$bmaCqEksI1e7rnZSjsIDR1\n")...) authUserData = append(authUserData, []byte("test2:$1$OtSSTL8b$bmaCqEksI1e7rnZSjsIDR1\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
require.False(t, httpAuth.ValidateCredentials("test2", "wrong2")) require.False(t, httpAuth.ValidateCredentials("test2", "wrong2"))
require.True(t, httpAuth.ValidateCredentials("test2", "password2")) require.True(t, httpAuth.ValidateCredentials("test2", "password2"))
authUserData = append(authUserData, []byte("test2:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...) authUserData = append(authUserData, []byte("test2:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
require.False(t, httpAuth.ValidateCredentials("test2", "wrong2")) require.False(t, httpAuth.ValidateCredentials("test2", "wrong2"))
require.True(t, httpAuth.ValidateCredentials("test2", "password2")) require.True(t, httpAuth.ValidateCredentials("test2", "password2"))
authUserData = append(authUserData, []byte("test3:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...) authUserData = append(authUserData, []byte("test3:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
require.False(t, httpAuth.ValidateCredentials("test3", "password3")) require.False(t, httpAuth.ValidateCredentials("test3", "password3"))
authUserData = append(authUserData, []byte("test4:$invalid$gLnIkRIf$Xr/6$aJfmIr$ihP4b2N2tcs/\n")...) authUserData = append(authUserData, []byte("test4:$invalid$gLnIkRIf$Xr/6$aJfmIr$ihP4b2N2tcs/\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
require.False(t, httpAuth.ValidateCredentials("test4", "password3")) require.False(t, httpAuth.ValidateCredentials("test4", "password3"))
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
authUserData = append(authUserData, []byte("test5:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...) authUserData = append(authUserData, []byte("test5:$apr1$gLnIkRIf$Xr/6aJfmIrihP4b2N2tcs/\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
err = os.Chmod(authUserFile, 0001) err = os.Chmod(authUserFile, 0001)
require.NoError(t, err) require.NoError(t, err)
@ -63,7 +62,7 @@ func TestBasicAuth(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
authUserData = append(authUserData, []byte("\"foo\"bar\"\r\n")...) authUserData = append(authUserData, []byte("\"foo\"bar\"\r\n")...)
err = ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err = os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
require.False(t, httpAuth.ValidateCredentials("test2", "password2")) require.False(t, httpAuth.ValidateCredentials("test2", "password2"))

View file

@ -5,7 +5,7 @@ import (
"crypto/x509" "crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"time" "time"
@ -104,7 +104,7 @@ func (m *CertManager) LoadCRLs() error {
if revocationList != "" && !filepath.IsAbs(revocationList) { if revocationList != "" && !filepath.IsAbs(revocationList) {
revocationList = filepath.Join(m.configDir, revocationList) revocationList = filepath.Join(m.configDir, revocationList)
} }
crlBytes, err := ioutil.ReadFile(revocationList) crlBytes, err := os.ReadFile(revocationList)
if err != nil { if err != nil {
logger.Warn(m.logSender, "unable to read revocation list %#v", revocationList) logger.Warn(m.logSender, "unable to read revocation list %#v", revocationList)
return err return err
@ -151,7 +151,7 @@ func (m *CertManager) LoadRootCAs() error {
if rootCA != "" && !filepath.IsAbs(rootCA) { if rootCA != "" && !filepath.IsAbs(rootCA) {
rootCA = filepath.Join(m.configDir, rootCA) rootCA = filepath.Join(m.configDir, rootCA)
} }
crt, err := ioutil.ReadFile(rootCA) crt, err := os.ReadFile(rootCA)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package common
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -273,13 +272,13 @@ func TestLoadCertificate(t *testing.T) {
caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt") caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt")
certPath := filepath.Join(os.TempDir(), "test.crt") certPath := filepath.Join(os.TempDir(), "test.crt")
keyPath := filepath.Join(os.TempDir(), "test.key") keyPath := filepath.Join(os.TempDir(), "test.key")
err := ioutil.WriteFile(caCrtPath, []byte(caCRT), os.ModePerm) err := os.WriteFile(caCrtPath, []byte(caCRT), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm) err = os.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(certPath, []byte(serverCert), os.ModePerm) err = os.WriteFile(certPath, []byte(serverCert), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyPath, []byte(serverKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(serverKey), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
certManager, err := NewCertManager(certPath, keyPath, configDir, logSenderTest) certManager, err := NewCertManager(certPath, keyPath, configDir, logSenderTest)
assert.NoError(t, err) assert.NoError(t, err)

View file

@ -2,7 +2,6 @@ package common
import ( import (
"errors" "errors"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -187,7 +186,7 @@ func TestTransferErrors(t *testing.T) {
Username: "test", Username: "test",
HomeDir: os.TempDir(), HomeDir: os.TempDir(),
} }
err := ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err := os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
file, err := os.Open(testFile) file, err := os.Open(testFile)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
@ -213,7 +212,7 @@ func TestTransferErrors(t *testing.T) {
} }
assert.NoFileExists(t, testFile) assert.NoFileExists(t, testFile)
err = ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err = os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
file, err = os.Open(testFile) file, err = os.Open(testFile)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
@ -233,7 +232,7 @@ func TestTransferErrors(t *testing.T) {
} }
assert.NoFileExists(t, testFile) assert.NoFileExists(t, testFile)
err = ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err = os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
file, err = os.Open(testFile) file, err = os.Open(testFile)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
@ -267,7 +266,7 @@ func TestRemovePartialCryptoFile(t *testing.T) {
transfer.ErrTransfer = errors.New("test error") transfer.ErrTransfer = errors.New("test error")
_, err = transfer.getUploadFileSize() _, err = transfer.getUploadFileSize()
assert.Error(t, err) assert.Error(t, err)
err = ioutil.WriteFile(testFile, []byte("test data"), os.ModePerm) err = os.WriteFile(testFile, []byte("test data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
size, err := transfer.getUploadFileSize() size, err := transfer.getUploadFileSize()
assert.NoError(t, err) assert.NoError(t, err)

View file

@ -2,7 +2,6 @@ package config_test
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -45,11 +44,11 @@ func TestLoadConfigTest(t *testing.T) {
configFilePath := filepath.Join(configDir, confName) configFilePath := filepath.Join(configDir, confName)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, []byte("{invalid json}"), os.ModePerm) err = os.WriteFile(configFilePath, []byte("{invalid json}"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, []byte("{\"sftpd\": {\"bind_port\": \"a\"}}"), os.ModePerm) err = os.WriteFile(configFilePath, []byte("{\"sftpd\": {\"bind_port\": \"a\"}}"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.Error(t, err) assert.Error(t, err)
@ -78,7 +77,7 @@ func TestEmptyBanner(t *testing.T) {
c := make(map[string]sftpd.Configuration) c := make(map[string]sftpd.Configuration)
c["sftpd"] = sftpdConf c["sftpd"] = sftpdConf
jsonConf, _ := json.Marshal(c) jsonConf, _ := json.Marshal(c)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -92,7 +91,7 @@ func TestEmptyBanner(t *testing.T) {
c1 := make(map[string]ftpd.Configuration) c1 := make(map[string]ftpd.Configuration)
c1["ftpd"] = ftpdConf c1["ftpd"] = ftpdConf
jsonConf, _ = json.Marshal(c1) jsonConf, _ = json.Marshal(c1)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -116,7 +115,7 @@ func TestInvalidUploadMode(t *testing.T) {
c["common"] = commonConf c["common"] = commonConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -139,7 +138,7 @@ func TestInvalidExternalAuthScope(t *testing.T) {
c["data_provider"] = providerConf c["data_provider"] = providerConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -162,7 +161,7 @@ func TestInvalidCredentialsPath(t *testing.T) {
c["data_provider"] = providerConf c["data_provider"] = providerConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -185,7 +184,7 @@ func TestInvalidProxyProtocol(t *testing.T) {
c["common"] = commonConf c["common"] = commonConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -208,7 +207,7 @@ func TestInvalidUsersBaseDir(t *testing.T) {
c["data_provider"] = providerConf c["data_provider"] = providerConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -308,7 +307,7 @@ func TestSFTPDBindingsCompatibility(t *testing.T) {
c["sftpd"] = sftpdConf c["sftpd"] = sftpdConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -349,7 +348,7 @@ func TestFTPDBindingsCompatibility(t *testing.T) {
c["ftpd"] = ftpdConf c["ftpd"] = ftpdConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -382,7 +381,7 @@ func TestWebDAVDBindingsCompatibility(t *testing.T) {
c["webdavd"] = webdavConf c["webdavd"] = webdavConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -413,7 +412,7 @@ func TestHTTPDBindingsCompatibility(t *testing.T) {
c["httpd"] = httpdConf c["httpd"] = httpdConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
assert.NoError(t, err) assert.NoError(t, err)
@ -635,7 +634,7 @@ func TestHTTPClientCertificatesFromEnv(t *testing.T) {
c["http"] = httpConf c["http"] = httpConf
jsonConf, err := json.Marshal(c) jsonConf, err := json.Marshal(c)
require.NoError(t, err) require.NoError(t, err)
err = ioutil.WriteFile(configFilePath, jsonConf, os.ModePerm) err = os.WriteFile(configFilePath, jsonConf, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
err = config.LoadConfig(configDir, confName) err = config.LoadConfig(configDir, confName)
require.NoError(t, err) require.NoError(t, err)

View file

@ -16,7 +16,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -1208,7 +1207,7 @@ func saveGCSCredentials(user *User) error {
if err != nil { if err != nil {
return &ValidationError{err: fmt.Sprintf("could not create GCS credentials dir: %v", err)} return &ValidationError{err: fmt.Sprintf("could not create GCS credentials dir: %v", err)}
} }
err = ioutil.WriteFile(credentialsFilePath, creds, 0600) err = os.WriteFile(credentialsFilePath, creds, 0600)
if err != nil { if err != nil {
return &ValidationError{err: fmt.Sprintf("could not save GCS credentials: %v", err)} return &ValidationError{err: fmt.Sprintf("could not save GCS credentials: %v", err)}
} }
@ -1535,7 +1534,7 @@ func addCredentialsToUser(user *User) error {
return nil return nil
} }
cred, err := ioutil.ReadFile(user.getGCSCredentialsFilePath()) cred, err := os.ReadFile(user.getGCSCredentialsFilePath())
if err != nil { if err != nil {
return err return err
} }
@ -1851,7 +1850,7 @@ func getPasswordHookResponse(username, password, ip, protocol string) ([]byte, e
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return result, fmt.Errorf("wrong http status code from chek password hook: %v, expected 200", resp.StatusCode) return result, fmt.Errorf("wrong http status code from chek password hook: %v, expected 200", resp.StatusCode)
} }
return ioutil.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
@ -1908,7 +1907,7 @@ func getPreLoginHookResponse(loginMethod, ip, protocol string, userAsJSON []byte
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return result, fmt.Errorf("wrong pre-login hook http status code: %v, expected 200", resp.StatusCode) return result, fmt.Errorf("wrong pre-login hook http status code: %v, expected 200", resp.StatusCode)
} }
return ioutil.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
@ -2075,7 +2074,7 @@ func getExternalAuthResponse(username, password, pkey, keyboardInteractive, ip,
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return result, fmt.Errorf("wrong external auth http status code: %v, expected 200", resp.StatusCode) return result, fmt.Errorf("wrong external auth http status code: %v, expected 200", resp.StatusCode)
} }
return ioutil.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()

View file

@ -3,7 +3,6 @@ package dataprovider
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -793,7 +792,7 @@ func (p *MemoryProvider) reloadConfig() error {
providerLog(logger.LevelWarn, "error loading dump: %v", err) providerLog(logger.LevelWarn, "error loading dump: %v", err)
return err return err
} }
content, err := ioutil.ReadFile(p.dbHandle.configFile) content, err := os.ReadFile(p.dbHandle.configFile)
if err != nil { if err != nil {
providerLog(logger.LevelWarn, "error loading dump: %v", err) providerLog(logger.LevelWarn, "error loading dump: %v", err)
return err return err

View file

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -85,7 +85,7 @@ func main() {
printResponse(0, "") printResponse(0, "")
} }
var authyResponse map[string]interface{} var authyResponse map[string]interface{}
respBody, err := ioutil.ReadAll(resp.Body) respBody, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
printResponse(0, "") printResponse(0, "")
} }

View file

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -88,7 +88,7 @@ func main() {
printResponse("") printResponse("")
} }
var authyResponse map[string]interface{} var authyResponse map[string]interface{}
respBody, err := ioutil.ReadAll(resp.Body) respBody, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
printResponse("") printResponse("")
} }

View file

@ -4,7 +4,7 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"time" "time"
@ -122,7 +122,7 @@ func main() {
printAuthResponse(-1) printAuthResponse(-1)
} }
var authyResponse map[string]interface{} var authyResponse map[string]interface{}
respBody, err := ioutil.ReadAll(resp.Body) respBody, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
printAuthResponse(-1) printAuthResponse(-1)
} }

View file

@ -5,8 +5,8 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"time" "time"
@ -116,7 +116,7 @@ func loadCACerts(configDir string) error {
} }
for _, ca := range ldapConfig.CACertificates { for _, ca := range ldapConfig.CACertificates {
caPath := getConfigPath(ca, configDir) caPath := getConfigPath(ca, configDir)
certs, err := ioutil.ReadFile(caPath) certs, err := os.ReadFile(caPath)
if err != nil { if err != nil {
logger.Warn(logSender, "", "error loading ca cert %#v: %v", caPath, err) logger.Warn(logSender, "", "error loading ca cert %#v: %v", caPath, err)
return err return err

View file

@ -1,7 +1,6 @@
package ftpd_test package ftpd_test
import ( import (
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -125,7 +124,7 @@ func TestZeroBytesTransfersCryptFs(t *testing.T) {
err = checkBasicFTP(client) err = checkBasicFTP(client)
assert.NoError(t, err) assert.NoError(t, err)
localDownloadPath := filepath.Join(homeBasePath, "emptydownload") localDownloadPath := filepath.Join(homeBasePath, "emptydownload")
err = ioutil.WriteFile(localDownloadPath, []byte(""), os.ModePerm) err = os.WriteFile(localDownloadPath, []byte(""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ftpUploadFile(localDownloadPath, testFileName, 0, client, 0) err = ftpUploadFile(localDownloadPath, testFileName, 0, client, 0)
assert.NoError(t, err) assert.NoError(t, err)
@ -160,7 +159,7 @@ func TestResumeCryptFs(t *testing.T) {
if assert.NoError(t, err) { if assert.NoError(t, err) {
testFilePath := filepath.Join(homeBasePath, testFileName) testFilePath := filepath.Join(homeBasePath, testFileName)
data := []byte("test data") data := []byte("test data")
err = ioutil.WriteFile(testFilePath, data, os.ModePerm) err = os.WriteFile(testFilePath, data, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ftpUploadFile(testFilePath, testFileName, int64(len(data)), client, 0) err = ftpUploadFile(testFilePath, testFileName, int64(len(data)), client, 0)
assert.NoError(t, err) assert.NoError(t, err)
@ -170,12 +169,12 @@ func TestResumeCryptFs(t *testing.T) {
localDownloadPath := filepath.Join(homeBasePath, testDLFileName) localDownloadPath := filepath.Join(homeBasePath, testDLFileName)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(4), client, 5) err = ftpDownloadFile(testFileName, localDownloadPath, int64(4), client, 5)
assert.NoError(t, err) assert.NoError(t, err)
readed, err := ioutil.ReadFile(localDownloadPath) readed, err := os.ReadFile(localDownloadPath)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, data[5:], readed) assert.Equal(t, data[5:], readed)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(8), client, 1) err = ftpDownloadFile(testFileName, localDownloadPath, int64(8), client, 1)
assert.NoError(t, err) assert.NoError(t, err)
readed, err = ioutil.ReadFile(localDownloadPath) readed, err = os.ReadFile(localDownloadPath)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, data[1:], readed) assert.Equal(t, data[1:], readed)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(0), client, 9) err = ftpDownloadFile(testFileName, localDownloadPath, int64(0), client, 9)
@ -196,7 +195,7 @@ func TestResumeCryptFs(t *testing.T) {
assert.Equal(t, int64(len(data)), size) assert.Equal(t, int64(len(data)), size)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(len(data)), client, 0) err = ftpDownloadFile(testFileName, localDownloadPath, int64(len(data)), client, 0)
assert.NoError(t, err) assert.NoError(t, err)
readed, err = ioutil.ReadFile(localDownloadPath) readed, err = os.ReadFile(localDownloadPath)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, data, readed) assert.Equal(t, data, readed)
} }

View file

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -87,7 +86,7 @@ func TestMain(m *testing.M) {
bannerFileName := "banner_file" bannerFileName := "banner_file"
bannerFile := filepath.Join(configDir, bannerFileName) bannerFile := filepath.Join(configDir, bannerFileName)
logger.InitLogger(logFilePath, 5, 1, 28, false, zerolog.DebugLevel) logger.InitLogger(logFilePath, 5, 1, 28, false, zerolog.DebugLevel)
err := ioutil.WriteFile(bannerFile, []byte("SFTPGo test ready\nsimple banner line\n"), os.ModePerm) err := os.WriteFile(bannerFile, []byte("SFTPGo test ready\nsimple banner line\n"), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error creating banner file: %v", err) logger.ErrorToConsole("error creating banner file: %v", err)
} }
@ -117,12 +116,12 @@ func TestMain(m *testing.M) {
certPath := filepath.Join(os.TempDir(), "test_ftpd.crt") certPath := filepath.Join(os.TempDir(), "test_ftpd.crt")
keyPath := filepath.Join(os.TempDir(), "test_ftpd.key") keyPath := filepath.Join(os.TempDir(), "test_ftpd.key")
err = ioutil.WriteFile(certPath, []byte(ftpsCert), os.ModePerm) err = os.WriteFile(certPath, []byte(ftpsCert), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing FTPS certificate: %v", err) logger.ErrorToConsole("error writing FTPS certificate: %v", err)
os.Exit(1) os.Exit(1)
} }
err = ioutil.WriteFile(keyPath, []byte(ftpsKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(ftpsKey), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing FTPS private key: %v", err) logger.ErrorToConsole("error writing FTPS private key: %v", err)
os.Exit(1) os.Exit(1)
@ -422,7 +421,7 @@ func TestLoginExternalAuth(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 0 providerConf.ExternalAuthScope = 0
@ -471,7 +470,7 @@ func TestPreLoginHook(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.PreLoginHook = preLoginPath providerConf.PreLoginHook = preLoginPath
err = dataprovider.Initialize(providerConf, configDir, true) err = dataprovider.Initialize(providerConf, configDir, true)
@ -498,7 +497,7 @@ func TestPreLoginHook(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
} }
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getFTPClient(u, false) client, err = getFTPClient(u, false)
if !assert.Error(t, err) { if !assert.Error(t, err) {
@ -506,7 +505,7 @@ func TestPreLoginHook(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
} }
user.Status = 0 user.Status = 0
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getFTPClient(u, false) client, err = getFTPClient(u, false)
if !assert.Error(t, err, "pre-login script returned a disabled user, login must fail") { if !assert.Error(t, err, "pre-login script returned a disabled user, login must fail") {
@ -538,7 +537,7 @@ func TestPostConnectHook(t *testing.T) {
u := getTestUser() u := getTestUser()
user, _, err := httpdtest.AddUser(u, http.StatusCreated) user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err := getFTPClient(user, true) client, err := getFTPClient(user, true)
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -547,7 +546,7 @@ func TestPostConnectHook(t *testing.T) {
err := client.Quit() err := client.Quit()
assert.NoError(t, err) assert.NoError(t, err)
} }
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getFTPClient(user, true) client, err = getFTPClient(user, true)
if !assert.Error(t, err) { if !assert.Error(t, err) {
@ -676,7 +675,7 @@ func TestZeroBytesTransfers(t *testing.T) {
err = checkBasicFTP(client) err = checkBasicFTP(client)
assert.NoError(t, err) assert.NoError(t, err)
localDownloadPath := filepath.Join(homeBasePath, "empty_download") localDownloadPath := filepath.Join(homeBasePath, "empty_download")
err = ioutil.WriteFile(localDownloadPath, []byte(""), os.ModePerm) err = os.WriteFile(localDownloadPath, []byte(""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ftpUploadFile(localDownloadPath, testFileName, 0, client, 0) err = ftpUploadFile(localDownloadPath, testFileName, 0, client, 0)
assert.NoError(t, err) assert.NoError(t, err)
@ -734,11 +733,11 @@ func TestDownloadErrors(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = os.MkdirAll(filepath.Dir(testFilePath2), os.ModePerm) err = os.MkdirAll(filepath.Dir(testFilePath2), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath1, []byte("file1"), os.ModePerm) err = os.WriteFile(testFilePath1, []byte("file1"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath2, []byte("file2"), os.ModePerm) err = os.WriteFile(testFilePath2, []byte("file2"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath3, []byte("file3"), os.ModePerm) err = os.WriteFile(testFilePath3, []byte("file3"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
localDownloadPath := filepath.Join(homeBasePath, testDLFileName) localDownloadPath := filepath.Join(homeBasePath, testDLFileName)
err = ftpDownloadFile(path.Join("/", subDir1, "file.zip"), localDownloadPath, 5, client, 0) err = ftpDownloadFile(path.Join("/", subDir1, "file.zip"), localDownloadPath, 5, client, 0)
@ -836,19 +835,19 @@ func TestResume(t *testing.T) {
if assert.NoError(t, err) { if assert.NoError(t, err) {
testFilePath := filepath.Join(homeBasePath, testFileName) testFilePath := filepath.Join(homeBasePath, testFileName)
data := []byte("test data") data := []byte("test data")
err = ioutil.WriteFile(testFilePath, data, os.ModePerm) err = os.WriteFile(testFilePath, data, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ftpUploadFile(testFilePath, testFileName, int64(len(data)), client, 0) err = ftpUploadFile(testFilePath, testFileName, int64(len(data)), client, 0)
assert.NoError(t, err) assert.NoError(t, err)
err = ftpUploadFile(testFilePath, testFileName, int64(len(data)+5), client, 5) err = ftpUploadFile(testFilePath, testFileName, int64(len(data)+5), client, 5)
assert.NoError(t, err) assert.NoError(t, err)
readed, err := ioutil.ReadFile(filepath.Join(user.GetHomeDir(), testFileName)) readed, err := os.ReadFile(filepath.Join(user.GetHomeDir(), testFileName))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "test test data", string(readed)) assert.Equal(t, "test test data", string(readed))
localDownloadPath := filepath.Join(homeBasePath, testDLFileName) localDownloadPath := filepath.Join(homeBasePath, testDLFileName)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(len(data)), client, 5) err = ftpDownloadFile(testFileName, localDownloadPath, int64(len(data)), client, 5)
assert.NoError(t, err) assert.NoError(t, err)
readed, err = ioutil.ReadFile(localDownloadPath) readed, err = os.ReadFile(localDownloadPath)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, data, readed) assert.Equal(t, data, readed)
err = client.Delete(testFileName) err = client.Delete(testFileName)
@ -867,7 +866,7 @@ func TestResume(t *testing.T) {
assert.Equal(t, int64(2*len(data)), size) assert.Equal(t, int64(2*len(data)), size)
err = ftpDownloadFile(testFileName, localDownloadPath, int64(2*len(data)), client, 0) err = ftpDownloadFile(testFileName, localDownloadPath, int64(2*len(data)), client, 0)
assert.NoError(t, err) assert.NoError(t, err)
readed, err = ioutil.ReadFile(localDownloadPath) readed, err = os.ReadFile(localDownloadPath)
assert.NoError(t, err) assert.NoError(t, err)
expected := append(data, data...) expected := append(data, data...)
assert.Equal(t, expected, readed) assert.Equal(t, expected, readed)
@ -2165,5 +2164,5 @@ func createTestFile(path string, size int64) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(path, content, os.ModePerm) return os.WriteFile(path, content, os.ModePerm)
} }

View file

@ -4,7 +4,6 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -604,7 +603,7 @@ func TestUploadFileStatError(t *testing.T) {
testFile := filepath.Join(user.HomeDir, "test", "testfile") testFile := filepath.Join(user.HomeDir, "test", "testfile")
err := os.MkdirAll(filepath.Dir(testFile), os.ModePerm) err := os.MkdirAll(filepath.Dir(testFile), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFile, []byte("data"), os.ModePerm) err = os.WriteFile(testFile, []byte("data"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = os.Chmod(filepath.Dir(testFile), 0001) err = os.Chmod(filepath.Dir(testFile), 0001)
assert.NoError(t, err) assert.NoError(t, err)
@ -658,7 +657,7 @@ func TestUploadOverwriteErrors(t *testing.T) {
assert.EqualError(t, err, common.ErrOpUnsupported.Error()) assert.EqualError(t, err, common.ErrOpUnsupported.Error())
} }
f, err := ioutil.TempFile("", "temp") f, err := os.CreateTemp("", "temp")
assert.NoError(t, err) assert.NoError(t, err)
err = f.Close() err = f.Close()
assert.NoError(t, err) assert.NoError(t, err)
@ -762,11 +761,11 @@ func TestVerifyTLSConnection(t *testing.T) {
caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt") caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt")
certPath := filepath.Join(os.TempDir(), "test.crt") certPath := filepath.Join(os.TempDir(), "test.crt")
keyPath := filepath.Join(os.TempDir(), "test.key") keyPath := filepath.Join(os.TempDir(), "test.key")
err := ioutil.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm) err := os.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(certPath, []byte(ftpsCert), os.ModePerm) err = os.WriteFile(certPath, []byte(ftpsCert), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyPath, []byte(ftpsKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(ftpsKey), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
certMgr, err = common.NewCertManager(certPath, keyPath, "", "ftp_test") certMgr, err = common.NewCertManager(certPath, keyPath, "", "ftp_test")

View file

@ -5,8 +5,8 @@ import (
"crypto/x509" "crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os"
"path/filepath" "path/filepath"
ftpserver "github.com/fclairamb/ftpserverlib" ftpserver "github.com/fclairamb/ftpserverlib"
@ -42,7 +42,7 @@ func NewServer(config *Configuration, configDir string, binding Binding, id int)
if !filepath.IsAbs(bannerFilePath) { if !filepath.IsAbs(bannerFilePath) {
bannerFilePath = filepath.Join(configDir, bannerFilePath) bannerFilePath = filepath.Join(configDir, bannerFilePath)
} }
bannerContent, err := ioutil.ReadFile(bannerFilePath) bannerContent, err := os.ReadFile(bannerFilePath)
if err == nil { if err == nil {
server.initialMsg = string(bannerContent) server.initialMsg = string(bannerContent)
} else { } else {

View file

@ -4,8 +4,8 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"time" "time"
@ -95,7 +95,7 @@ func (c *Config) loadCACerts(configDir string) (*x509.CertPool, error) {
if !filepath.IsAbs(ca) { if !filepath.IsAbs(ca) {
ca = filepath.Join(configDir, ca) ca = filepath.Join(configDir, ca)
} }
certs, err := ioutil.ReadFile(ca) certs, err := os.ReadFile(ca)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to load CA certificate: %v", err) return nil, fmt.Errorf("unable to load CA certificate: %v", err)
} }

View file

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -82,7 +82,7 @@ func dumpData(w http.ResponseWriter, r *http.Request) {
dump, err = json.Marshal(backup) dump, err = json.Marshal(backup)
} }
if err == nil { if err == nil {
err = ioutil.WriteFile(outputFile, dump, 0600) err = os.WriteFile(outputFile, dump, 0600)
} }
if err != nil { if err != nil {
logger.Warn(logSender, "", "dumping data error: %v, output file: %#v", err, outputFile) logger.Warn(logSender, "", "dumping data error: %v, output file: %#v", err, outputFile)
@ -101,7 +101,7 @@ func loadDataFromRequest(w http.ResponseWriter, r *http.Request) {
return return
} }
content, err := ioutil.ReadAll(r.Body) content, err := io.ReadAll(r.Body)
if err != nil || len(content) == 0 { if err != nil || len(content) == 0 {
if len(content) == 0 { if len(content) == 0 {
err = dataprovider.NewValidationError("request body is required") err = dataprovider.NewValidationError("request body is required")
@ -136,7 +136,7 @@ func loadData(w http.ResponseWriter, r *http.Request) {
return return
} }
content, err := ioutil.ReadFile(inputFile) content, err := os.ReadFile(inputFile)
if err != nil { if err != nil {
sendAPIResponse(w, r, err, "", getRespStatus(err)) sendAPIResponse(w, r, err, "", getRespStatus(err))
return return

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net" "net"
"net/http" "net/http"
@ -210,12 +209,12 @@ func TestMain(m *testing.M) {
// now start an https server // now start an https server
certPath := filepath.Join(os.TempDir(), "test.crt") certPath := filepath.Join(os.TempDir(), "test.crt")
keyPath := filepath.Join(os.TempDir(), "test.key") keyPath := filepath.Join(os.TempDir(), "test.key")
err = ioutil.WriteFile(certPath, []byte(httpsCert), os.ModePerm) err = os.WriteFile(certPath, []byte(httpsCert), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing HTTPS certificate: %v", err) logger.ErrorToConsole("error writing HTTPS certificate: %v", err)
os.Exit(1) os.Exit(1)
} }
err = ioutil.WriteFile(keyPath, []byte(httpsKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(httpsKey), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing HTTPS private key: %v", err) logger.ErrorToConsole("error writing HTTPS private key: %v", err)
os.Exit(1) os.Exit(1)
@ -1314,7 +1313,7 @@ func TestUserGCSConfig(t *testing.T) {
assert.NoError(t, err, string(bb)) assert.NoError(t, err, string(bb))
credentialFile := filepath.Join(credentialsPath, fmt.Sprintf("%v_gcs_credentials.json", user.Username)) credentialFile := filepath.Join(credentialsPath, fmt.Sprintf("%v_gcs_credentials.json", user.Username))
assert.FileExists(t, credentialFile) assert.FileExists(t, credentialFile)
creds, err := ioutil.ReadFile(credentialFile) creds, err := os.ReadFile(credentialFile)
assert.NoError(t, err) assert.NoError(t, err)
secret := kms.NewEmptySecret() secret := kms.NewEmptySecret()
err = json.Unmarshal(creds, secret) err = json.Unmarshal(creds, secret)
@ -1326,7 +1325,7 @@ func TestUserGCSConfig(t *testing.T) {
user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "") user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
assert.NoError(t, err) assert.NoError(t, err)
assert.FileExists(t, credentialFile) assert.FileExists(t, credentialFile)
creds, err = ioutil.ReadFile(credentialFile) creds, err = os.ReadFile(credentialFile)
assert.NoError(t, err) assert.NoError(t, err)
secret = kms.NewEmptySecret() secret = kms.NewEmptySecret()
err = json.Unmarshal(creds, secret) err = json.Unmarshal(creds, secret)
@ -1874,7 +1873,7 @@ func TestSecretObjectCompatibility(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
masterKeyPath := filepath.Join(os.TempDir(), "mkey") masterKeyPath := filepath.Join(os.TempDir(), "mkey")
err = ioutil.WriteFile(masterKeyPath, []byte("test key"), os.ModePerm) err = os.WriteFile(masterKeyPath, []byte("test key"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
config := kms.Configuration{ config := kms.Configuration{
Secrets: kms.Secrets{ Secrets: kms.Secrets{
@ -2338,14 +2337,14 @@ func TestProviderErrors(t *testing.T) {
backupContent, err := json.Marshal(backupData) backupContent, err := json.Marshal(backupData)
assert.NoError(t, err) assert.NoError(t, err)
backupFilePath := filepath.Join(backupsPath, "backup.json") backupFilePath := filepath.Join(backupsPath, "backup.json")
err = ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err = os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError) _, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError)
assert.NoError(t, err) assert.NoError(t, err)
backupData.Folders = append(backupData.Folders, vfs.BaseVirtualFolder{Name: "testFolder", MappedPath: filepath.Clean(os.TempDir())}) backupData.Folders = append(backupData.Folders, vfs.BaseVirtualFolder{Name: "testFolder", MappedPath: filepath.Clean(os.TempDir())})
backupContent, err = json.Marshal(backupData) backupContent, err = json.Marshal(backupData)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err = os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError) _, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError)
assert.NoError(t, err) assert.NoError(t, err)
@ -2354,7 +2353,7 @@ func TestProviderErrors(t *testing.T) {
backupData.Admins = append(backupData.Admins, getTestAdmin()) backupData.Admins = append(backupData.Admins, getTestAdmin())
backupContent, err = json.Marshal(backupData) backupContent, err = json.Marshal(backupData)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err = os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError) _, _, err = httpdtest.Loaddata(backupFilePath, "", "", http.StatusInternalServerError)
assert.NoError(t, err) assert.NoError(t, err)
@ -2663,7 +2662,7 @@ func TestLoaddata(t *testing.T) {
backupContent, err := json.Marshal(backupData) backupContent, err := json.Marshal(backupData)
assert.NoError(t, err) assert.NoError(t, err)
backupFilePath := filepath.Join(backupsPath, "backup.json") backupFilePath := filepath.Join(backupsPath, "backup.json")
err = ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err = os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "a", "", http.StatusBadRequest) _, _, err = httpdtest.Loaddata(backupFilePath, "a", "", http.StatusBadRequest)
assert.NoError(t, err) assert.NoError(t, err)
@ -2751,7 +2750,7 @@ func TestLoaddataMode(t *testing.T) {
} }
backupContent, _ := json.Marshal(backupData) backupContent, _ := json.Marshal(backupData)
backupFilePath := filepath.Join(backupsPath, "backup.json") backupFilePath := filepath.Join(backupsPath, "backup.json")
err := ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err := os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, _, err = httpdtest.Loaddata(backupFilePath, "0", "0", http.StatusOK) _, _, err = httpdtest.Loaddata(backupFilePath, "0", "0", http.StatusOK)
assert.NoError(t, err) assert.NoError(t, err)
@ -4501,7 +4500,7 @@ func TestWebMaintenanceMock(t *testing.T) {
backupData.Admins = append(backupData.Admins, admin) backupData.Admins = append(backupData.Admins, admin)
backupContent, err := json.Marshal(backupData) backupContent, err := json.Marshal(backupData)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(backupFilePath, backupContent, os.ModePerm) err = os.WriteFile(backupFilePath, backupContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
b, contentType, _ = getMultipartFormData(form, "backup_file", backupFilePath) b, contentType, _ = getMultipartFormData(form, "backup_file", backupFilePath)
@ -6397,7 +6396,7 @@ func createTestFile(path string, size int64) error {
return err return err
} }
} }
return ioutil.WriteFile(path, content, os.ModePerm) return os.WriteFile(path, content, os.ModePerm)
} }
func getMultipartFormData(values url.Values, fileFieldName, filePath string) (bytes.Buffer, string, error) { func getMultipartFormData(values url.Values, fileFieldName, filePath string) (bytes.Buffer, string, error) {

View file

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -698,11 +697,11 @@ func TestVerifyTLSConnection(t *testing.T) {
caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt") caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt")
certPath := filepath.Join(os.TempDir(), "testh.crt") certPath := filepath.Join(os.TempDir(), "testh.crt")
keyPath := filepath.Join(os.TempDir(), "testh.key") keyPath := filepath.Join(os.TempDir(), "testh.key")
err := ioutil.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm) err := os.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(certPath, []byte(httpdCert), os.ModePerm) err = os.WriteFile(certPath, []byte(httpdCert), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyPath, []byte(httpdKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(httpdKey), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
certMgr, err = common.NewCertManager(certPath, keyPath, "", "webdav_test") certMgr, err = common.NewCertManager(certPath, keyPath, "", "webdav_test")

View file

@ -4,7 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
@ -708,7 +708,7 @@ func getGCSConfig(r *http.Request) (vfs.GCSFsConfig, error) {
return config, err return config, err
} }
defer credentials.Close() defer credentials.Close()
fileBytes, err := ioutil.ReadAll(credentials) fileBytes, err := io.ReadAll(credentials)
if err != nil || len(fileBytes) == 0 { if err != nil || len(fileBytes) == 0 {
if len(fileBytes) == 0 { if len(fileBytes) == 0 {
err = errors.New("credentials file size must be greater than 0") err = errors.New("credentials file size must be greater than 0")
@ -1063,7 +1063,7 @@ func handleWebRestore(w http.ResponseWriter, r *http.Request) {
} }
defer backupFile.Close() defer backupFile.Close()
backupContent, err := ioutil.ReadAll(backupFile) backupContent, err := io.ReadAll(backupFile)
if err != nil || len(backupContent) == 0 { if err != nil || len(backupContent) == 0 {
if len(backupContent) == 0 { if len(backupContent) == 0 {
err = errors.New("backup file size must be greater than 0") err = errors.New("backup file size must be greater than 0")

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
@ -817,7 +816,7 @@ func checkResponse(actual int, expected int) error {
} }
func getResponseBody(resp *http.Response) ([]byte, error) { func getResponseBody(resp *http.Response) ([]byte, error) {
return ioutil.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
func checkFolder(expected *vfs.BaseVirtualFolder, actual *vfs.BaseVirtualFolder) error { func checkFolder(expected *vfs.BaseVirtualFolder, actual *vfs.BaseVirtualFolder) error {

View file

@ -4,7 +4,7 @@ package kms
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil" "os"
"strings" "strings"
"time" "time"
@ -107,7 +107,7 @@ func GetSecretFromCompatString(secret string) (*Secret, error) {
// Initialize configures the KMS support // Initialize configures the KMS support
func (c *Configuration) Initialize() error { func (c *Configuration) Initialize() error {
if c.Secrets.MasterKeyPath != "" { if c.Secrets.MasterKeyPath != "" {
mKey, err := ioutil.ReadFile(c.Secrets.MasterKeyPath) mKey, err := os.ReadFile(c.Secrets.MasterKeyPath)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,7 +4,6 @@ package service
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -249,7 +248,7 @@ func (s *Service) loadInitialData() error {
return fmt.Errorf("unable to restore input file %#v size too big: %v/%v bytes", return fmt.Errorf("unable to restore input file %#v size too big: %v/%v bytes",
s.LoadDataFrom, info.Size(), httpd.MaxRestoreSize) s.LoadDataFrom, info.Size(), httpd.MaxRestoreSize)
} }
content, err := ioutil.ReadFile(s.LoadDataFrom) content, err := os.ReadFile(s.LoadDataFrom)
if err != nil { if err != nil {
return fmt.Errorf("unable to read input file %#v: %v", s.LoadDataFrom, err) return fmt.Errorf("unable to read input file %#v: %v", s.LoadDataFrom, err)
} }

View file

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -288,7 +287,7 @@ func TestMockFsErrors(t *testing.T) {
} }
testfile := filepath.Join(u.HomeDir, "testfile") testfile := filepath.Join(u.HomeDir, "testfile")
request := sftp.NewRequest("Remove", testfile) request := sftp.NewRequest("Remove", testfile)
err := ioutil.WriteFile(testfile, []byte("test"), os.ModePerm) err := os.WriteFile(testfile, []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
_, err = c.Filewrite(request) _, err = c.Filewrite(request)
assert.EqualError(t, err, sftp.ErrSSHFxFailure.Error()) assert.EqualError(t, err, sftp.ErrSSHFxFailure.Error())
@ -340,7 +339,7 @@ func TestUploadFiles(t *testing.T) {
assert.Error(t, err, "upload new file in missing path must fail") assert.Error(t, err, "upload new file in missing path must fail")
c.BaseConnection.Fs = newMockOsFs(nil, nil, false, "123", os.TempDir()) c.BaseConnection.Fs = newMockOsFs(nil, nil, false, "123", os.TempDir())
f, err := ioutil.TempFile("", "temp") f, err := os.CreateTemp("", "temp")
assert.NoError(t, err) assert.NoError(t, err)
err = f.Close() err = f.Close()
assert.NoError(t, err) assert.NoError(t, err)
@ -626,7 +625,7 @@ func TestSSHCommandErrors(t *testing.T) {
err = os.MkdirAll(aDir, os.ModePerm) err = os.MkdirAll(aDir, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
tmpFile := filepath.Join(aDir, "testcopy") tmpFile := filepath.Join(aDir, "testcopy")
err = ioutil.WriteFile(tmpFile, []byte("aaa"), os.ModePerm) err = os.WriteFile(tmpFile, []byte("aaa"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = os.Chmod(aDir, 0001) err = os.Chmod(aDir, 0001)
assert.NoError(t, err) assert.NoError(t, err)
@ -889,7 +888,7 @@ func TestSystemCommandSizeForPath(t *testing.T) {
err = os.MkdirAll(testDir, os.ModePerm) err = os.MkdirAll(testDir, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
testFile := filepath.Join(testDir, "testfile") testFile := filepath.Join(testDir, "testfile")
err = ioutil.WriteFile(testFile, []byte("test content"), os.ModePerm) err = os.WriteFile(testFile, []byte("test content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = os.Symlink(testFile, testFile+".link") err = os.Symlink(testFile, testFile+".link")
assert.NoError(t, err) assert.NoError(t, err)
@ -938,7 +937,7 @@ func TestSystemCommandErrors(t *testing.T) {
homeDir := filepath.Join(os.TempDir(), "adir") homeDir := filepath.Join(os.TempDir(), "adir")
err := os.MkdirAll(homeDir, os.ModePerm) err := os.MkdirAll(homeDir, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(homeDir, "afile"), []byte("content"), os.ModePerm) err = os.WriteFile(filepath.Join(homeDir, "afile"), []byte("content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
user := dataprovider.User{ user := dataprovider.User{
Permissions: permissions, Permissions: permissions,
@ -1381,7 +1380,7 @@ func TestSCPErrorsMockFs(t *testing.T) {
assert.EqualError(t, err, errFake.Error()) assert.EqualError(t, err, errFake.Error())
testfile := filepath.Join(u.HomeDir, "testfile") testfile := filepath.Join(u.HomeDir, "testfile")
err = ioutil.WriteFile(testfile, []byte("test"), os.ModePerm) err = os.WriteFile(testfile, []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
stat, err := os.Stat(u.HomeDir) stat, err := os.Stat(u.HomeDir)
assert.NoError(t, err) assert.NoError(t, err)
@ -1549,7 +1548,7 @@ func TestSCPDownloadFileData(t *testing.T) {
args: []string{"-r", "-f", "/tmp"}, args: []string{"-r", "-f", "/tmp"},
}, },
} }
err := ioutil.WriteFile(testfile, []byte("test"), os.ModePerm) err := os.WriteFile(testfile, []byte("test"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
stat, err := os.Stat(testfile) stat, err := os.Stat(testfile)
assert.NoError(t, err) assert.NoError(t, err)
@ -1801,7 +1800,7 @@ func TestLoadHostKeys(t *testing.T) {
err := c.checkAndLoadHostKeys(configDir, serverConfig) err := c.checkAndLoadHostKeys(configDir, serverConfig)
assert.Error(t, err) assert.Error(t, err)
testfile := filepath.Join(os.TempDir(), "invalidkey") testfile := filepath.Join(os.TempDir(), "invalidkey")
err = ioutil.WriteFile(testfile, []byte("some bytes"), os.ModePerm) err = os.WriteFile(testfile, []byte("some bytes"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
c.HostKeys = []string{testfile} c.HostKeys = []string{testfile}
err = c.checkAndLoadHostKeys(configDir, serverConfig) err = c.checkAndLoadHostKeys(configDir, serverConfig)
@ -1856,7 +1855,7 @@ func TestCertCheckerInitErrors(t *testing.T) {
err := c.initializeCertChecker("") err := c.initializeCertChecker("")
assert.Error(t, err) assert.Error(t, err)
testfile := filepath.Join(os.TempDir(), "invalidkey") testfile := filepath.Join(os.TempDir(), "invalidkey")
err = ioutil.WriteFile(testfile, []byte("some bytes"), os.ModePerm) err = os.WriteFile(testfile, []byte("some bytes"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
c.TrustedUserCAKeys = []string{testfile} c.TrustedUserCAKeys = []string{testfile}
err = c.initializeCertChecker("") err = c.initializeCertChecker("")

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -309,7 +308,7 @@ func (c *Configuration) configureLoginBanner(serverConfig *ssh.ServerConfig, con
if !filepath.IsAbs(bannerFilePath) { if !filepath.IsAbs(bannerFilePath) {
bannerFilePath = filepath.Join(configDir, bannerFilePath) bannerFilePath = filepath.Join(configDir, bannerFilePath)
} }
bannerContent, err := ioutil.ReadFile(bannerFilePath) bannerContent, err := os.ReadFile(bannerFilePath)
if err == nil { if err == nil {
banner := string(bannerContent) banner := string(bannerContent)
serverConfig.BannerCallback = func(conn ssh.ConnMetadata) string { serverConfig.BannerCallback = func(conn ssh.ConnMetadata) string {
@ -718,7 +717,7 @@ func (c *Configuration) checkAndLoadHostKeys(configDir string, serverConfig *ssh
} }
logger.Info(logSender, "", "Loading private host key %#v", hostKey) logger.Info(logSender, "", "Loading private host key %#v", hostKey)
privateBytes, err := ioutil.ReadFile(hostKey) privateBytes, err := os.ReadFile(hostKey)
if err != nil { if err != nil {
return err return err
} }
@ -751,7 +750,7 @@ func (c *Configuration) initializeCertChecker(configDir string) error {
if !filepath.IsAbs(keyPath) { if !filepath.IsAbs(keyPath) {
keyPath = filepath.Join(configDir, keyPath) keyPath = filepath.Join(configDir, keyPath)
} }
keyBytes, err := ioutil.ReadFile(keyPath) keyBytes, err := os.ReadFile(keyPath)
if err != nil { if err != nil {
logger.Warn(logSender, "", "error loading trusted user CA key %#v: %v", keyPath, err) logger.Warn(logSender, "", "error loading trusted user CA key %#v: %v", keyPath, err)
logger.WarnToConsole("error loading trusted user CA key %#v: %v", keyPath, err) logger.WarnToConsole("error loading trusted user CA key %#v: %v", keyPath, err)

View file

@ -12,7 +12,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"math" "math"
"net" "net"
"net/http" "net/http"
@ -143,7 +142,7 @@ func TestMain(m *testing.M) {
loginBannerFileName := "login_banner" loginBannerFileName := "login_banner"
loginBannerFile := filepath.Join(configDir, loginBannerFileName) loginBannerFile := filepath.Join(configDir, loginBannerFileName)
logger.InitLogger(logFilePath, 5, 1, 28, false, zerolog.DebugLevel) logger.InitLogger(logFilePath, 5, 1, 28, false, zerolog.DebugLevel)
err := ioutil.WriteFile(loginBannerFile, []byte("simple login banner\n"), os.ModePerm) err := os.WriteFile(loginBannerFile, []byte("simple login banner\n"), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error creating login banner: %v", err) logger.ErrorToConsole("error creating login banner: %v", err)
} }
@ -210,7 +209,7 @@ func TestMain(m *testing.M) {
sftpdConf.EnabledSSHCommands = []string{"*"} sftpdConf.EnabledSSHCommands = []string{"*"}
keyIntAuthPath = filepath.Join(homeBasePath, "keyintauth.sh") keyIntAuthPath = filepath.Join(homeBasePath, "keyintauth.sh")
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing keyboard interactive script: %v", err) logger.ErrorToConsole("error writing keyboard interactive script: %v", err)
os.Exit(1) os.Exit(1)
@ -1500,7 +1499,7 @@ func TestMultiStepLoginKeyAndKeyInt(t *testing.T) {
}...) }...)
user, _, err := httpdtest.AddUser(u, http.StatusCreated) user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err := getSftpClient(user, true) client, err := getSftpClient(user, true)
if !assert.Error(t, err, "login with public key is disallowed and must fail") { if !assert.Error(t, err, "login with public key is disallowed and must fail") {
@ -1887,7 +1886,7 @@ func TestLoginKeyboardInteractiveAuth(t *testing.T) {
} }
user, _, err := httpdtest.AddUser(getTestUser(false), http.StatusCreated) user, _, err := httpdtest.AddUser(getTestUser(false), http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err := getKeyboardInteractiveSftpClient(user, []string{"1", "2"}) client, err := getKeyboardInteractiveSftpClient(user, []string{"1", "2"})
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -1904,19 +1903,19 @@ func TestLoginKeyboardInteractiveAuth(t *testing.T) {
user.Status = 1 user.Status = 1
user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "") user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, -1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, -1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"}) client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"})
if !assert.Error(t, err, "keyboard interactive auth must fail the script returned -1") { if !assert.Error(t, err, "keyboard interactive auth must fail the script returned -1") {
client.Close() client.Close()
} }
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, true, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, true, 1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"}) client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"})
if !assert.Error(t, err, "keyboard interactive auth must fail the script returned bad json") { if !assert.Error(t, err, "keyboard interactive auth must fail the script returned bad json") {
client.Close() client.Close()
} }
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 5, true, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 5, true, 1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"}) client, err = getKeyboardInteractiveSftpClient(user, []string{"1", "2"})
if !assert.Error(t, err, "keyboard interactive auth must fail the script returned bad json") { if !assert.Error(t, err, "keyboard interactive auth must fail the script returned bad json") {
@ -1939,7 +1938,7 @@ func TestPreLoginScript(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.PreLoginHook = preLoginPath providerConf.PreLoginHook = preLoginPath
err = dataprovider.Initialize(providerConf, configDir, true) err = dataprovider.Initialize(providerConf, configDir, true)
@ -1952,14 +1951,14 @@ func TestPreLoginScript(t *testing.T) {
defer client.Close() defer client.Close()
assert.NoError(t, checkBasicSFTP(client)) assert.NoError(t, checkBasicSFTP(client))
} }
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getSftpClient(u, usePubKey) client, err = getSftpClient(u, usePubKey)
if !assert.Error(t, err, "pre-login script returned a non json response, login must fail") { if !assert.Error(t, err, "pre-login script returned a non json response, login must fail") {
client.Close() client.Close()
} }
user.Status = 0 user.Status = 0
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getSftpClient(u, usePubKey) client, err = getSftpClient(u, usePubKey)
if !assert.Error(t, err, "pre-login script returned a disabled user, login must fail") { if !assert.Error(t, err, "pre-login script returned a disabled user, login must fail") {
@ -1991,7 +1990,7 @@ func TestPreLoginUserCreation(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.PreLoginHook = preLoginPath providerConf.PreLoginHook = preLoginPath
err = dataprovider.Initialize(providerConf, configDir, true) err = dataprovider.Initialize(providerConf, configDir, true)
@ -2031,7 +2030,7 @@ func TestPostConnectHook(t *testing.T) {
u := getTestUser(usePubKey) u := getTestUser(usePubKey)
user, _, err := httpdtest.AddUser(u, http.StatusCreated) user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err := getSftpClient(u, usePubKey) client, err := getSftpClient(u, usePubKey)
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -2039,7 +2038,7 @@ func TestPostConnectHook(t *testing.T) {
err = checkBasicSFTP(client) err = checkBasicSFTP(client)
assert.NoError(t, err) assert.NoError(t, err)
} }
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getSftpClient(u, usePubKey) client, err = getSftpClient(u, usePubKey)
if !assert.Error(t, err) { if !assert.Error(t, err) {
@ -2081,7 +2080,7 @@ func TestCheckPwdHook(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(checkPwdPath, getCheckPwdScriptsContents(2, defaultPassword), os.ModePerm) err = os.WriteFile(checkPwdPath, getCheckPwdScriptsContents(2, defaultPassword), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.CheckPasswordHook = checkPwdPath providerConf.CheckPasswordHook = checkPwdPath
providerConf.CheckPasswordScope = 1 providerConf.CheckPasswordScope = 1
@ -2097,14 +2096,14 @@ func TestCheckPwdHook(t *testing.T) {
client.Close() client.Close()
} }
err = ioutil.WriteFile(checkPwdPath, getCheckPwdScriptsContents(0, defaultPassword), os.ModePerm) err = os.WriteFile(checkPwdPath, getCheckPwdScriptsContents(0, defaultPassword), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getSftpClient(user, usePubKey) client, err = getSftpClient(user, usePubKey)
if !assert.Error(t, err) { if !assert.Error(t, err) {
client.Close() client.Close()
} }
err = ioutil.WriteFile(checkPwdPath, getCheckPwdScriptsContents(1, ""), os.ModePerm) err = os.WriteFile(checkPwdPath, getCheckPwdScriptsContents(1, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
user.Password = defaultPassword + "1" user.Password = defaultPassword + "1"
client, err = getSftpClient(user, usePubKey) client, err = getSftpClient(user, usePubKey)
@ -2157,7 +2156,7 @@ func TestLoginExternalAuthPwdAndPubKey(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 0 providerConf.ExternalAuthScope = 0
@ -2184,7 +2183,7 @@ func TestLoginExternalAuthPwdAndPubKey(t *testing.T) {
usePubKey = false usePubKey = false
u = getTestUser(usePubKey) u = getTestUser(usePubKey)
u.PublicKeys = []string{} u.PublicKeys = []string{}
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err = getSftpClient(u, usePubKey) client, err = getSftpClient(u, usePubKey)
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -2226,7 +2225,7 @@ func TestExternalAuthDifferentUsername(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, extAuthUsername), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, extAuthUsername), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 0 providerConf.ExternalAuthScope = 0
@ -2309,7 +2308,7 @@ func TestLoginExternalAuth(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = authScope providerConf.ExternalAuthScope = authScope
@ -2371,14 +2370,14 @@ func TestLoginExternalAuthInteractive(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 4 providerConf.ExternalAuthScope = 4
err = dataprovider.Initialize(providerConf, configDir, true) err = dataprovider.Initialize(providerConf, configDir, true)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm) err = os.WriteFile(keyIntAuthPath, getKeyboardInteractiveScriptContent([]string{"1", "2"}, 0, false, 1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client, err := getKeyboardInteractiveSftpClient(u, []string{"1", "2"}) client, err := getKeyboardInteractiveSftpClient(u, []string{"1", "2"})
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -2425,7 +2424,7 @@ func TestLoginExternalAuthErrors(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, true, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, true, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 0 providerConf.ExternalAuthScope = 0
@ -8322,7 +8321,7 @@ func createTestFile(path string, size int64) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(path, content, os.ModePerm) return os.WriteFile(path, content, os.ModePerm)
} }
func appendToTestFile(path string, size int64) error { func appendToTestFile(path string, size int64) error {
@ -8743,7 +8742,7 @@ func printLatestLogs(maxNumberOfLines int) {
} }
func getHostKeyFingerprint(name string) (string, error) { func getHostKeyFingerprint(name string) (string, error) {
privateBytes, err := ioutil.ReadFile(name) privateBytes, err := os.ReadFile(name)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -8775,20 +8774,20 @@ func createInitialFiles(scriptArgs string) {
preLoginPath = filepath.Join(homeBasePath, "prelogin.sh") preLoginPath = filepath.Join(homeBasePath, "prelogin.sh")
postConnectPath = filepath.Join(homeBasePath, "postconnect.sh") postConnectPath = filepath.Join(homeBasePath, "postconnect.sh")
checkPwdPath = filepath.Join(homeBasePath, "checkpwd.sh") checkPwdPath = filepath.Join(homeBasePath, "checkpwd.sh")
err := ioutil.WriteFile(pubKeyPath, []byte(testPubKey+"\n"), 0600) err := os.WriteFile(pubKeyPath, []byte(testPubKey+"\n"), 0600)
if err != nil { if err != nil {
logger.WarnToConsole("unable to save public key to file: %v", err) logger.WarnToConsole("unable to save public key to file: %v", err)
} }
err = ioutil.WriteFile(privateKeyPath, []byte(testPrivateKey+"\n"), 0600) err = os.WriteFile(privateKeyPath, []byte(testPrivateKey+"\n"), 0600)
if err != nil { if err != nil {
logger.WarnToConsole("unable to save private key to file: %v", err) logger.WarnToConsole("unable to save private key to file: %v", err)
} }
err = ioutil.WriteFile(gitWrapPath, []byte(fmt.Sprintf("%v -i %v -oStrictHostKeyChecking=no %v\n", err = os.WriteFile(gitWrapPath, []byte(fmt.Sprintf("%v -i %v -oStrictHostKeyChecking=no %v\n",
sshPath, privateKeyPath, scriptArgs)), os.ModePerm) sshPath, privateKeyPath, scriptArgs)), os.ModePerm)
if err != nil { if err != nil {
logger.WarnToConsole("unable to save gitwrap shell script: %v", err) logger.WarnToConsole("unable to save gitwrap shell script: %v", err)
} }
err = ioutil.WriteFile(trustedCAUserKey, []byte(testCAUserKey), 0600) err = os.WriteFile(trustedCAUserKey, []byte(testCAUserKey), 0600)
if err != nil { if err != nil {
logger.WarnToConsole("unable to save trusted CA user key: %v", err) logger.WarnToConsole("unable to save trusted CA user key: %v", err)
} }

View file

@ -1,7 +1,6 @@
package telemetry package telemetry
import ( import (
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@ -65,9 +64,9 @@ func TestInitialization(t *testing.T) {
certPath := filepath.Join(os.TempDir(), "test.crt") certPath := filepath.Join(os.TempDir(), "test.crt")
keyPath := filepath.Join(os.TempDir(), "test.key") keyPath := filepath.Join(os.TempDir(), "test.key")
err = ioutil.WriteFile(certPath, []byte(httpsCert), os.ModePerm) err = os.WriteFile(certPath, []byte(httpsCert), os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
err = ioutil.WriteFile(keyPath, []byte(httpsKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(httpsKey), os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
c.CertificateFile = certPath c.CertificateFile = certPath
@ -104,7 +103,7 @@ func TestShouldBind(t *testing.T) {
func TestRouter(t *testing.T) { func TestRouter(t *testing.T) {
authUserFile := filepath.Join(os.TempDir(), "http_users.txt") authUserFile := filepath.Join(os.TempDir(), "http_users.txt")
authUserData := []byte("test1:$2y$05$bcHSED7aO1cfLto6ZdDBOOKzlwftslVhtpIkRhAtSa4GuLmk5mola\n") authUserData := []byte("test1:$2y$05$bcHSED7aO1cfLto6ZdDBOOKzlwftslVhtpIkRhAtSa4GuLmk5mola\n")
err := ioutil.WriteFile(authUserFile, authUserData, os.ModePerm) err := os.WriteFile(authUserFile, authUserData, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
httpAuth, err = common.NewBasicAuthProvider(authUserFile) httpAuth, err = common.NewBasicAuthProvider(authUserFile)

View file

@ -17,7 +17,6 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -240,7 +239,7 @@ func GenerateRSAKeys(file string) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600) return os.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600)
} }
// GenerateECDSAKeys generate ecdsa private and public keys and write the // GenerateECDSAKeys generate ecdsa private and public keys and write the
@ -278,7 +277,7 @@ func GenerateECDSAKeys(file string) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600) return os.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600)
} }
// GenerateEd25519Keys generate ed25519 private and public keys and write the // GenerateEd25519Keys generate ed25519 private and public keys and write the
@ -310,7 +309,7 @@ func GenerateEd25519Keys(file string) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600) return os.WriteFile(file+".pub", ssh.MarshalAuthorizedKey(pub), 0600)
} }
// GetDirsForSFTPPath returns all the directory for the given path in reverse order // GetDirsForSFTPPath returns all the directory for the given path in reverse order

View file

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime" "mime"
"net/http" "net/http"
"os" "os"
@ -74,7 +73,7 @@ func NewGCSFs(connectionID, localTempDir string, config GCSFsConfig) (Fs, error)
fs.svc, err = storage.NewClient(ctx, option.WithCredentialsJSON([]byte(fs.config.Credentials.GetPayload()))) fs.svc, err = storage.NewClient(ctx, option.WithCredentialsJSON([]byte(fs.config.Credentials.GetPayload())))
} else { } else {
var creds []byte var creds []byte
creds, err = ioutil.ReadFile(fs.config.CredentialFile) creds, err = os.ReadFile(fs.config.CredentialFile)
if err != nil { if err != nil {
return fs, err return fs, err
} }

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@ -516,7 +515,7 @@ func TestResolvePathErrors(t *testing.T) {
testTxtFile := "file.txt" testTxtFile := "file.txt"
err = os.MkdirAll(filepath.Join(os.TempDir(), subDir, subDir), os.ModePerm) err = os.MkdirAll(filepath.Join(os.TempDir(), subDir, subDir), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(os.TempDir(), subDir, subDir, testTxtFile), []byte("content"), os.ModePerm) err = os.WriteFile(filepath.Join(os.TempDir(), subDir, subDir, testTxtFile), []byte("content"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = os.Chmod(filepath.Join(os.TempDir(), subDir, subDir), 0001) err = os.Chmod(filepath.Join(os.TempDir(), subDir, subDir), 0001)
assert.NoError(t, err) assert.NoError(t, err)
@ -577,7 +576,7 @@ func TestFileAccessErrors(t *testing.T) {
assert.EqualError(t, err, os.ErrNotExist.Error()) assert.EqualError(t, err, os.ErrNotExist.Error())
} }
f, err := ioutil.TempFile("", "temp") f, err := os.CreateTemp("", "temp")
assert.NoError(t, err) assert.NoError(t, err)
err = f.Close() err = f.Close()
assert.NoError(t, err) assert.NoError(t, err)
@ -664,7 +663,7 @@ func TestContentType(t *testing.T) {
baseTransfer := common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFile, baseTransfer := common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFile,
common.TransferDownload, 0, 0, 0, false, fs) common.TransferDownload, 0, 0, 0, false, fs)
fs = newMockOsFs(nil, false, fs.ConnectionID(), user.GetHomeDir(), nil) fs = newMockOsFs(nil, false, fs.ConnectionID(), user.GetHomeDir(), nil)
err := ioutil.WriteFile(testFilePath, []byte(""), os.ModePerm) err := os.WriteFile(testFilePath, []byte(""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
davFile := newWebDavFile(baseTransfer, nil, nil) davFile := newWebDavFile(baseTransfer, nil, nil)
davFile.Fs = fs davFile.Fs = fs
@ -737,7 +736,7 @@ func TestTransferReadWriteErrors(t *testing.T) {
baseTransfer = common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFile, baseTransfer = common.NewBaseTransfer(nil, connection.BaseConnection, nil, testFilePath, testFile,
common.TransferDownload, 0, 0, 0, false, fs) common.TransferDownload, 0, 0, 0, false, fs)
err = ioutil.WriteFile(testFilePath, []byte(""), os.ModePerm) err = os.WriteFile(testFilePath, []byte(""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
f, err := os.Open(testFilePath) f, err := os.Open(testFilePath)
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -818,7 +817,7 @@ func TestTransferSeek(t *testing.T) {
assert.True(t, os.IsNotExist(err)) assert.True(t, os.IsNotExist(err))
davFile.Connection.RemoveTransfer(davFile.BaseTransfer) davFile.Connection.RemoveTransfer(davFile.BaseTransfer)
err = ioutil.WriteFile(testFilePath, testFileContents, os.ModePerm) err = os.WriteFile(testFilePath, testFileContents, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
f, err := os.Open(testFilePath) f, err := os.Open(testFilePath)
if assert.NoError(t, err) { if assert.NoError(t, err) {
@ -1217,11 +1216,11 @@ func TestVerifyTLSConnection(t *testing.T) {
caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt") caCrlPath := filepath.Join(os.TempDir(), "testcrl.crt")
certPath := filepath.Join(os.TempDir(), "test.crt") certPath := filepath.Join(os.TempDir(), "test.crt")
keyPath := filepath.Join(os.TempDir(), "test.key") keyPath := filepath.Join(os.TempDir(), "test.key")
err := ioutil.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm) err := os.WriteFile(caCrlPath, []byte(caCRL), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(certPath, []byte(webDavCert), os.ModePerm) err = os.WriteFile(certPath, []byte(webDavCert), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(keyPath, []byte(webDavKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(webDavKey), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
certMgr, err = common.NewCertManager(certPath, keyPath, "", "webdav_test") certMgr, err = common.NewCertManager(certPath, keyPath, "", "webdav_test")

View file

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -109,12 +108,12 @@ func TestMain(m *testing.M) {
certPath = filepath.Join(os.TempDir(), "test_dav.crt") certPath = filepath.Join(os.TempDir(), "test_dav.crt")
keyPath = filepath.Join(os.TempDir(), "test_dav.key") keyPath = filepath.Join(os.TempDir(), "test_dav.key")
err = ioutil.WriteFile(certPath, []byte(webDavCert), os.ModePerm) err = os.WriteFile(certPath, []byte(webDavCert), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing WebDAV certificate: %v", err) logger.ErrorToConsole("error writing WebDAV certificate: %v", err)
os.Exit(1) os.Exit(1)
} }
err = ioutil.WriteFile(keyPath, []byte(webDavKey), os.ModePerm) err = os.WriteFile(keyPath, []byte(webDavKey), os.ModePerm)
if err != nil { if err != nil {
logger.ErrorToConsole("error writing WebDAV private key: %v", err) logger.ErrorToConsole("error writing WebDAV private key: %v", err)
os.Exit(1) os.Exit(1)
@ -563,7 +562,7 @@ func TestLoginExternalAuth(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm) err = os.WriteFile(extAuthPath, getExtAuthScriptContent(u, false, ""), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.ExternalAuthHook = extAuthPath providerConf.ExternalAuthHook = extAuthPath
providerConf.ExternalAuthScope = 0 providerConf.ExternalAuthScope = 0
@ -602,7 +601,7 @@ func TestPreLoginHook(t *testing.T) {
err = config.LoadConfig(configDir, "") err = config.LoadConfig(configDir, "")
assert.NoError(t, err) assert.NoError(t, err)
providerConf := config.GetProviderConf() providerConf := config.GetProviderConf()
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(u, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
providerConf.PreLoginHook = preLoginPath providerConf.PreLoginHook = preLoginPath
err = dataprovider.Initialize(providerConf, configDir, true) err = dataprovider.Initialize(providerConf, configDir, true)
@ -617,7 +616,7 @@ func TestPreLoginHook(t *testing.T) {
// test login with an existing user // test login with an existing user
client = getWebDavClient(user) client = getWebDavClient(user)
assert.NoError(t, checkBasicFunc(client)) assert.NoError(t, checkBasicFunc(client))
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, true), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
// update the user to remove it from the cache // update the user to remove it from the cache
user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "") user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
@ -628,7 +627,7 @@ func TestPreLoginHook(t *testing.T) {
user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "") user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
assert.NoError(t, err) assert.NoError(t, err)
user.Status = 0 user.Status = 0
err = ioutil.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm) err = os.WriteFile(preLoginPath, getPreLoginScriptContent(user, false), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client = getWebDavClient(user) client = getWebDavClient(user)
assert.Error(t, checkBasicFunc(client)) assert.Error(t, checkBasicFunc(client))
@ -657,11 +656,11 @@ func TestPostConnectHook(t *testing.T) {
u := getTestUser() u := getTestUser()
user, _, err := httpdtest.AddUser(u, http.StatusCreated) user, _, err := httpdtest.AddUser(u, http.StatusCreated)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(0), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client := getWebDavClient(user) client := getWebDavClient(user)
assert.NoError(t, checkBasicFunc(client)) assert.NoError(t, checkBasicFunc(client))
err = ioutil.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm) err = os.WriteFile(postConnectPath, getPostConnectScriptContent(1), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
assert.Error(t, checkBasicFunc(client)) assert.Error(t, checkBasicFunc(client))
@ -774,11 +773,11 @@ func TestDownloadErrors(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = os.MkdirAll(filepath.Dir(testFilePath2), os.ModePerm) err = os.MkdirAll(filepath.Dir(testFilePath2), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath1, []byte("file1"), os.ModePerm) err = os.WriteFile(testFilePath1, []byte("file1"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath2, []byte("file2"), os.ModePerm) err = os.WriteFile(testFilePath2, []byte("file2"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
err = ioutil.WriteFile(testFilePath3, []byte("file3"), os.ModePerm) err = os.WriteFile(testFilePath3, []byte("file3"), os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
localDownloadPath := filepath.Join(homeBasePath, testDLFileName) localDownloadPath := filepath.Join(homeBasePath, testDLFileName)
err = downloadFile(path.Join("/", subDir1, "file.zipp"), localDownloadPath, 5, client) err = downloadFile(path.Join("/", subDir1, "file.zipp"), localDownloadPath, 5, client)
@ -1207,7 +1206,7 @@ func TestBytesRangeRequests(t *testing.T) {
testFileName := "test_file.txt" testFileName := "test_file.txt"
testFilePath := filepath.Join(homeBasePath, testFileName) testFilePath := filepath.Join(homeBasePath, testFileName)
fileContent := []byte("test file contents") fileContent := []byte("test file contents")
err = ioutil.WriteFile(testFilePath, fileContent, os.ModePerm) err = os.WriteFile(testFilePath, fileContent, os.ModePerm)
assert.NoError(t, err) assert.NoError(t, err)
client := getWebDavClient(user) client := getWebDavClient(user)
err = uploadFile(testFilePath, testFileName, int64(len(fileContent)), client) err = uploadFile(testFilePath, testFileName, int64(len(fileContent)), client)
@ -1222,7 +1221,7 @@ func TestBytesRangeRequests(t *testing.T) {
if assert.NoError(t, err) { if assert.NoError(t, err) {
defer resp.Body.Close() defer resp.Body.Close()
assert.Equal(t, http.StatusPartialContent, resp.StatusCode) assert.Equal(t, http.StatusPartialContent, resp.StatusCode)
bodyBytes, err := ioutil.ReadAll(resp.Body) bodyBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "file contents", string(bodyBytes)) assert.Equal(t, "file contents", string(bodyBytes))
} }
@ -1231,7 +1230,7 @@ func TestBytesRangeRequests(t *testing.T) {
if assert.NoError(t, err) { if assert.NoError(t, err) {
defer resp.Body.Close() defer resp.Body.Close()
assert.Equal(t, http.StatusPartialContent, resp.StatusCode) assert.Equal(t, http.StatusPartialContent, resp.StatusCode)
bodyBytes, err := ioutil.ReadAll(resp.Body) bodyBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "file", string(bodyBytes)) assert.Equal(t, "file", string(bodyBytes))
} }
@ -1672,5 +1671,5 @@ func createTestFile(path string, size int64) error {
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(path, content, os.ModePerm) return os.WriteFile(path, content, os.ModePerm)
} }