refactor: remove ioutil (#2635)

Was deprecated in 1.16 and has more performant options available.
pull/2653/head
James Elliott 2021-12-02 00:14:15 +11:00 committed by GitHub
parent 8a12af97ab
commit 7df242f1e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 50 additions and 62 deletions

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -151,7 +150,7 @@ func prepareHostsFile() {
modified = true modified = true
} }
fd, err := ioutil.TempFile("/tmp/authelia/", "hosts") fd, err := os.CreateTemp("/tmp/authelia/", "hosts")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -174,7 +173,7 @@ func prepareHostsFile() {
// ReadHostsFile reads the hosts file. // ReadHostsFile reads the hosts file.
func readHostsFile() ([]byte, error) { func readHostsFile() ([]byte, error) {
bs, err := ioutil.ReadFile("/etc/hosts") bs, err := os.ReadFile("/etc/hosts")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/signal" "os/signal"
"sort" "sort"
@ -260,7 +259,7 @@ func getRunningSuite() (string, error) {
return "", nil return "", nil
} }
b, err := ioutil.ReadFile(runningSuiteFile) b, err := os.ReadFile(runningSuiteFile)
return string(b), err return string(b), err
} }

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -64,7 +63,7 @@ func main() {
} }
func createRunningSuiteFile(suite string) error { func createRunningSuiteFile(suite string) error {
return ioutil.WriteFile(runningSuiteFile, []byte(suite), 0600) return os.WriteFile(runningSuiteFile, []byte(suite), 0600)
} }
func removeRunningSuiteFile() error { func removeRunningSuiteFile() error {

View File

@ -3,7 +3,6 @@ package authentication
import ( import (
_ "embed" // Embed users_database.template.yml. _ "embed" // Embed users_database.template.yml.
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"sync" "sync"
@ -107,7 +106,7 @@ func checkDatabase(path string) []error {
var cfg []byte var cfg []byte
func generateDatabaseFromTemplate(path string) error { func generateDatabaseFromTemplate(path string) error {
err := ioutil.WriteFile(path, cfg, 0600) err := os.WriteFile(path, cfg, 0600)
if err != nil { if err != nil {
return fmt.Errorf("Unable to generate %v: %v", path, err) return fmt.Errorf("Unable to generate %v: %v", path, err)
} }
@ -116,7 +115,7 @@ func generateDatabaseFromTemplate(path string) error {
} }
func readDatabase(path string) (*DatabaseModel, error) { func readDatabase(path string) (*DatabaseModel, error) {
content, err := ioutil.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to read database from file %s: %s", path, err) return nil, fmt.Errorf("Unable to read database from file %s: %s", path, err)
} }
@ -200,7 +199,7 @@ func (p *FileUserProvider) UpdatePassword(username string, newPassword string) e
return err return err
} }
err = ioutil.WriteFile(p.configuration.Path, b, fileAuthenticationMode) err = os.WriteFile(p.configuration.Path, b, fileAuthenticationMode)
p.lock.Unlock() p.lock.Unlock()
return err return err

View File

@ -1,7 +1,6 @@
package authentication package authentication
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
"runtime" "runtime"
@ -15,7 +14,7 @@ import (
) )
func WithDatabase(content []byte, f func(path string)) { func WithDatabase(content []byte, f func(path string)) {
tmpfile, err := ioutil.TempFile("", "users_database.*.yaml") tmpfile, err := os.CreateTemp("", "users_database.*.yaml")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -1,7 +1,7 @@
package configuration package configuration
import ( import (
"io/ioutil" "os"
"strings" "strings"
"github.com/authelia/authelia/v4/internal/utils" "github.com/authelia/authelia/v4/internal/utils"
@ -46,7 +46,7 @@ func isSecretKey(key string) (isSecretKey bool) {
} }
func loadSecret(path string) (value string, err error) { func loadSecret(path string) (value string, err error) {
content, err := ioutil.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -2,7 +2,7 @@ package configuration
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"testing" "testing"
@ -58,7 +58,7 @@ func TestKoanfSecretCallbackWithValidSecrets(t *testing.T) {
"AUTHELIA__STORAGE_MYSQL_FAKE_PASSWORD": "storage.mysql.fake_password", "AUTHELIA__STORAGE_MYSQL_FAKE_PASSWORD": "storage.mysql.fake_password",
} }
dir, err := ioutil.TempDir("", "authelia-test-callbacks") dir, err := os.MkdirTemp("", "authelia-test-callbacks")
assert.NoError(t, err) assert.NoError(t, err)
secretOne := filepath.Join(dir, "secert_one") secretOne := filepath.Join(dir, "secert_one")
@ -108,7 +108,7 @@ func TestKoanfSecretCallbackShouldErrorOnFSError(t *testing.T) {
"AUTHELIA_THEME": "theme", "AUTHELIA_THEME": "theme",
} }
dir, err := ioutil.TempDir("", "authelia-test-callbacks") dir, err := os.MkdirTemp("", "authelia-test-callbacks")
assert.NoError(t, err) assert.NoError(t, err)
secret := filepath.Join(dir, "inaccessible") secret := filepath.Join(dir, "inaccessible")

View File

@ -2,7 +2,6 @@ package configuration
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -20,7 +19,7 @@ import (
func TestShouldErrorSecretNotExist(t *testing.T) { func TestShouldErrorSecretNotExist(t *testing.T) {
testReset() testReset()
dir, err := ioutil.TempDir("", "authelia-test-secret-not-exist") dir, err := os.MkdirTemp("", "authelia-test-secret-not-exist")
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, os.Setenv(DefaultEnvPrefix+"JWT_SECRET_FILE", filepath.Join(dir, "jwt"))) assert.NoError(t, os.Setenv(DefaultEnvPrefix+"JWT_SECRET_FILE", filepath.Join(dir, "jwt")))
@ -163,7 +162,7 @@ func TestShouldRaiseIOErrOnUnreadableFile(t *testing.T) {
testReset() testReset()
dir, err := ioutil.TempDir("", "authelia-conf") dir, err := os.MkdirTemp("", "authelia-conf")
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, os.WriteFile(filepath.Join(dir, "myconf.yml"), []byte("server:\n port: 9091\n"), 0000)) assert.NoError(t, os.WriteFile(filepath.Join(dir, "myconf.yml"), []byte("server:\n port: 9091\n"), 0000))
@ -264,7 +263,7 @@ func TestShouldNotReadConfigurationOnFSAccessDenied(t *testing.T) {
testReset() testReset()
dir, err := ioutil.TempDir("", "authelia-config") dir, err := os.MkdirTemp("", "authelia-config")
assert.NoError(t, err) assert.NoError(t, err)
cfg := filepath.Join(dir, "config.yml") cfg := filepath.Join(dir, "config.yml")
@ -282,7 +281,7 @@ func TestShouldNotReadConfigurationOnFSAccessDenied(t *testing.T) {
func TestShouldNotLoadDirectoryConfiguration(t *testing.T) { func TestShouldNotLoadDirectoryConfiguration(t *testing.T) {
testReset() testReset()
dir, err := ioutil.TempDir("", "authelia-config") dir, err := os.MkdirTemp("", "authelia-config")
assert.NoError(t, err) assert.NoError(t, err)
val := schema.NewStructValidator() val := schema.NewStructValidator()

View File

@ -3,7 +3,6 @@ package configuration
import ( import (
_ "embed" // Embed config.template.yml. _ "embed" // Embed config.template.yml.
"fmt" "fmt"
"io/ioutil"
"os" "os"
) )
@ -16,7 +15,7 @@ func EnsureConfigurationExists(path string) (created bool, err error) {
_, err = os.Stat(path) _, err = os.Stat(path)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
err := ioutil.WriteFile(path, template, 0600) err := os.WriteFile(path, template, 0600)
if err != nil { if err != nil {
return false, fmt.Errorf(errFmtGenerateConfiguration, err) return false, fmt.Errorf(errFmtGenerateConfiguration, err)
} }

View File

@ -2,7 +2,6 @@ package configuration
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -14,7 +13,7 @@ import (
) )
func TestShouldGenerateConfiguration(t *testing.T) { func TestShouldGenerateConfiguration(t *testing.T) {
dir, err := ioutil.TempDir("", "authelia-config") dir, err := os.MkdirTemp("", "authelia-config")
assert.NoError(t, err) assert.NoError(t, err)
cfg := filepath.Join(dir, "config.yml") cfg := filepath.Join(dir, "config.yml")
@ -32,7 +31,7 @@ func TestShouldNotGenerateConfigurationOnFSAccessDenied(t *testing.T) {
t.Skip("skipping test due to being on windows") t.Skip("skipping test due to being on windows")
} }
dir, err := ioutil.TempDir("", "authelia-config") dir, err := os.MkdirTemp("", "authelia-config")
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, os.Mkdir(filepath.Join(dir, "zero"), 0000)) assert.NoError(t, os.Mkdir(filepath.Join(dir, "zero"), 0000))
@ -45,7 +44,7 @@ func TestShouldNotGenerateConfigurationOnFSAccessDenied(t *testing.T) {
} }
func TestShouldNotGenerateConfiguration(t *testing.T) { func TestShouldNotGenerateConfiguration(t *testing.T) {
dir, err := ioutil.TempDir("", "authelia-config") dir, err := os.MkdirTemp("", "authelia-config")
assert.NoError(t, err) assert.NoError(t, err)
cfg := filepath.Join(dir, "..", "not-a-dir", "config.yml") cfg := filepath.Join(dir, "..", "not-a-dir", "config.yml")

View File

@ -2,7 +2,7 @@ package logging
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"os" "os"
"testing" "testing"
@ -14,7 +14,7 @@ import (
) )
func TestShouldWriteLogsToFile(t *testing.T) { func TestShouldWriteLogsToFile(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "logs-dir") dir, err := os.MkdirTemp("/tmp", "logs-dir")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -30,14 +30,14 @@ func TestShouldWriteLogsToFile(t *testing.T) {
f, err := os.OpenFile(path, os.O_RDONLY, 0) f, err := os.OpenFile(path, os.O_RDONLY, 0)
require.NoError(t, err) require.NoError(t, err)
b, err := ioutil.ReadAll(f) b, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
assert.Contains(t, string(b), "level=info msg=\"This is a test\"\n") assert.Contains(t, string(b), "level=info msg=\"This is a test\"\n")
} }
func TestShouldWriteLogsToFileAndStdout(t *testing.T) { func TestShouldWriteLogsToFileAndStdout(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "logs-dir") dir, err := os.MkdirTemp("/tmp", "logs-dir")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -53,14 +53,14 @@ func TestShouldWriteLogsToFileAndStdout(t *testing.T) {
f, err := os.OpenFile(path, os.O_RDONLY, 0) f, err := os.OpenFile(path, os.O_RDONLY, 0)
require.NoError(t, err) require.NoError(t, err)
b, err := ioutil.ReadAll(f) b, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
assert.Contains(t, string(b), "level=info msg=\"This is a test\"\n") assert.Contains(t, string(b), "level=info msg=\"This is a test\"\n")
} }
func TestShouldFormatLogsAsJSON(t *testing.T) { func TestShouldFormatLogsAsJSON(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "logs-dir") dir, err := os.MkdirTemp("/tmp", "logs-dir")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -76,7 +76,7 @@ func TestShouldFormatLogsAsJSON(t *testing.T) {
f, err := os.OpenFile(path, os.O_RDONLY, 0) f, err := os.OpenFile(path, os.O_RDONLY, 0)
require.NoError(t, err) require.NoError(t, err)
b, err := ioutil.ReadAll(f) b, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
assert.Contains(t, string(b), "{\"level\":\"info\",\"msg\":\"This is a test\",") assert.Contains(t, string(b), "{\"level\":\"info\",\"msg\":\"This is a test\",")

View File

@ -2,7 +2,6 @@ package notification
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -39,7 +38,7 @@ func (n *FileNotifier) StartupCheck() (err error) {
} }
} }
if err := ioutil.WriteFile(n.path, []byte(""), fileNotifierMode); err != nil { if err := os.WriteFile(n.path, []byte(""), fileNotifierMode); err != nil {
return err return err
} }
@ -50,7 +49,7 @@ func (n *FileNotifier) StartupCheck() (err error) {
func (n *FileNotifier) Send(recipient, subject, body, _ string) error { func (n *FileNotifier) Send(recipient, subject, body, _ string) error {
content := fmt.Sprintf("Date: %s\nRecipient: %s\nSubject: %s\nBody: %s", time.Now(), recipient, subject, body) content := fmt.Sprintf("Date: %s\nRecipient: %s\nSubject: %s\nBody: %s", time.Now(), recipient, subject, body)
err := ioutil.WriteFile(n.path, []byte(content), fileNotifierMode) err := os.WriteFile(n.path, []byte(content), fileNotifierMode)
if err != nil { if err != nil {
return err return err

View File

@ -2,7 +2,7 @@ package server
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"path/filepath" "path/filepath"
"text/template" "text/template"
@ -24,7 +24,7 @@ func ServeTemplatedFile(publicDir, file, assetPath, duoSelfEnrollment, rememberM
logger.Fatalf("Unable to open %s: %s", file, err) logger.Fatalf("Unable to open %s: %s", file, err)
} }
b, err := ioutil.ReadAll(a) b, err := io.ReadAll(a)
if err != nil { if err != nil {
logger.Fatalf("Unable to read %s: %s", file, err) logger.Fatalf("Unable to read %s: %s", file, err)
} }

View File

@ -1,7 +1,7 @@
package suites package suites
import ( import (
"io/ioutil" "io"
"net/http" "net/http"
"testing" "testing"
@ -18,7 +18,7 @@ func doHTTPGetQuery(t *testing.T, url string) []byte {
assert.NoError(t, err) assert.NoError(t, err)
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
return body return body
} }

View File

@ -2,7 +2,6 @@ package suites
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"time" "time"
) )
@ -11,8 +10,8 @@ var standaloneSuiteName = "Standalone"
func init() { func init() {
_ = os.MkdirAll("/tmp/authelia/StandaloneSuite/", 0700) _ = os.MkdirAll("/tmp/authelia/StandaloneSuite/", 0700)
_ = ioutil.WriteFile("/tmp/authelia/StandaloneSuite/jwt", []byte("very_important_secret"), 0600) //nolint:gosec _ = os.WriteFile("/tmp/authelia/StandaloneSuite/jwt", []byte("very_important_secret"), 0600)
_ = ioutil.WriteFile("/tmp/authelia/StandaloneSuite/session", []byte("unsecure_session_secret"), 0600) //nolint:gosec _ = os.WriteFile("/tmp/authelia/StandaloneSuite/session", []byte("unsecure_session_secret"), 0600)
dockerEnvironment := NewDockerEnvironment([]string{ dockerEnvironment := NewDockerEnvironment([]string{
"internal/suites/docker-compose.yml", "internal/suites/docker-compose.yml",

View File

@ -3,7 +3,7 @@ package suites
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -165,7 +165,7 @@ func (s *StandaloneSuite) TestShouldRespectMethodsACL() {
res, err := client.Do(req) res, err := client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 302) s.Assert().Equal(res.StatusCode, 302)
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/") urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/")
@ -191,7 +191,7 @@ func (s *StandaloneSuite) TestShouldRespondWithCorrectStatusCode() {
res, err := client.Do(req) res, err := client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 302) s.Assert().Equal(res.StatusCode, 302)
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/") urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/")
@ -202,7 +202,7 @@ func (s *StandaloneSuite) TestShouldRespondWithCorrectStatusCode() {
res, err = client.Do(req) res, err = client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 303) s.Assert().Equal(res.StatusCode, 303)
body, err = ioutil.ReadAll(res.Body) body, err = io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
urlEncodedAdminURL = url.QueryEscape(SecureBaseURL + "/") urlEncodedAdminURL = url.QueryEscape(SecureBaseURL + "/")
@ -221,7 +221,7 @@ func (s *StandaloneSuite) TestShouldVerifyAPIVerifyUnauthorized() {
res, err := client.Do(req) res, err := client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 401) s.Assert().Equal(res.StatusCode, 401)
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal("Unauthorized", string(body)) s.Assert().Equal("Unauthorized", string(body))
} }
@ -238,7 +238,7 @@ func (s *StandaloneSuite) TestShouldVerifyAPIVerifyRedirectFromXOriginalURL() {
res, err := client.Do(req) res, err := client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 302) s.Assert().Equal(res.StatusCode, 302)
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
urlEncodedAdminURL := url.QueryEscape(AdminBaseURL) urlEncodedAdminURL := url.QueryEscape(AdminBaseURL)
@ -257,7 +257,7 @@ func (s *StandaloneSuite) TestShouldVerifyAPIVerifyRedirectFromXOriginalHostURI(
res, err := client.Do(req) res, err := client.Do(req)
s.Assert().NoError(err) s.Assert().NoError(err)
s.Assert().Equal(res.StatusCode, 302) s.Assert().Equal(res.StatusCode, 302)
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
s.Assert().NoError(err) s.Assert().NoError(err)
urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/") urlEncodedAdminURL := url.QueryEscape(SecureBaseURL + "/")

View File

@ -3,7 +3,6 @@ package suites
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -37,7 +36,7 @@ func (rs *RodSession) collectCoverage(page *rod.Page) {
_ = os.MkdirAll(coverageDir, 0775) _ = os.MkdirAll(coverageDir, 0775)
if coverageData != "<nil>" { if coverageData != "<nil>" {
err = ioutil.WriteFile(fmt.Sprintf("%s/coverage-%d.json", coverageDir, now.Unix()), []byte(coverageData), 0664) //nolint:gosec err = os.WriteFile(fmt.Sprintf("%s/coverage-%d.json", coverageDir, now.Unix()), []byte(coverageData), 0664) //nolint:gosec
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -86,7 +85,7 @@ func fixCoveragePath(path string, file os.FileInfo, err error) error {
} }
if coverage { if coverage {
read, err := ioutil.ReadFile(path) read, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }
@ -95,7 +94,7 @@ func fixCoveragePath(path string, file os.FileInfo, err error) error {
ciPath := strings.TrimSuffix(wd, "internal/suites") ciPath := strings.TrimSuffix(wd, "internal/suites")
content := strings.ReplaceAll(string(read), "/node/src/app/", ciPath+"web/") content := strings.ReplaceAll(string(read), "/node/src/app/", ciPath+"web/")
err = ioutil.WriteFile(path, []byte(content), 0) err = os.WriteFile(path, []byte(content), 0)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -40,7 +40,7 @@ func NewX509CertPool(directory string) (certPool *x509.CertPool, warnings []erro
logger.Tracef("Starting scan of directory %s for certificates", directory) logger.Tracef("Starting scan of directory %s for certificates", directory)
if directory != "" { if directory != "" {
certsFileInfo, err := ioutil.ReadDir(directory) certsFileInfo, err := os.ReadDir(directory)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("could not read certificates from directory %v", err)) errors = append(errors, fmt.Errorf("could not read certificates from directory %v", err))
} else { } else {
@ -52,7 +52,7 @@ func NewX509CertPool(directory string) (certPool *x509.CertPool, warnings []erro
logger.Tracef("Found possible cert %s, attempting to add it to the pool", certPath) logger.Tracef("Found possible cert %s, attempting to add it to the pool", certPath)
certBytes, err := ioutil.ReadFile(certPath) certBytes, err := os.ReadFile(certPath)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("could not read certificate %v", err)) errors = append(errors, fmt.Errorf("could not read certificate %v", err))
} else if ok := certPool.AppendCertsFromPEM(certBytes); !ok { } else if ok := certPool.AppendCertsFromPEM(certBytes); !ok {

View File

@ -2,7 +2,6 @@ package utils
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -31,7 +30,7 @@ func TestShouldHashString(t *testing.T) {
} }
func TestShouldHashPath(t *testing.T) { func TestShouldHashPath(t *testing.T) {
dir, err := ioutil.TempDir("", "authelia-hashing") dir, err := os.MkdirTemp("", "authelia-hashing")
assert.NoError(t, err) assert.NoError(t, err)
err = os.WriteFile(filepath.Join(dir, "myfile"), []byte("output\n"), 0600) err = os.WriteFile(filepath.Join(dir, "myfile"), []byte("output\n"), 0600)