multi: repleace ioutil.ReadFile

This commit is contained in:
erik authored and ErikEk committed 2024-04-25 11:22:43 +02:00
1 parent 619c8f4eb8
commit ab83343c87
23 files changed
+55 -62

No files matched your search

+9 -9
View File
@@ -1,7 +1,7 @@
package cert_test package cert_test
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@@ -42,10 +42,10 @@ func TestIsOutdatedCert(t *testing.T) {
// number of IPs and domains. // number of IPs and domains.
for numIPs := 1; numIPs <= len(extraIPs); numIPs++ { for numIPs := 1; numIPs <= len(extraIPs); numIPs++ {
for numDomains := 1; numDomains <= len(extraDomains); numDomains++ { for numDomains := 1; numDomains <= len(extraDomains); numDomains++ {
certBytes, err := ioutil.ReadFile(certPath) certBytes, err := os.ReadFile(certPath)
require.NoError(t, err) require.NoError(t, err)
keyBytes, err := ioutil.ReadFile(keyPath) keyBytes, err := os.ReadFile(keyPath)
require.NoError(t, err) require.NoError(t, err)
_, parsedCert, err := cert.LoadCertFromBytes( _, parsedCert, err := cert.LoadCertFromBytes(
@@ -98,10 +98,10 @@ func TestIsOutdatedPermutation(t *testing.T) {
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes) err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
require.NoError(t, err) require.NoError(t, err)
certBytes, err = ioutil.ReadFile(certPath) certBytes, err = os.ReadFile(certPath)
require.NoError(t, err) require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath) keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err) require.NoError(t, err)
_, parsedCert, err := cert.LoadCertFromBytes(certBytes, keyBytes) _, parsedCert, err := cert.LoadCertFromBytes(certBytes, keyBytes)
@@ -171,10 +171,10 @@ func TestTLSDisableAutofill(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Read certs from disk. // Read certs from disk.
certBytes, err = ioutil.ReadFile(certPath) certBytes, err = os.ReadFile(certPath)
require.NoError(t, err) require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath) keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err) require.NoError(t, err)
// Load the certificate. // Load the certificate.
@@ -230,10 +230,10 @@ func TestTLSConfig(t *testing.T) {
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes) err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
require.NoError(t, err) require.NoError(t, err)
certBytes, err = ioutil.ReadFile(certPath) certBytes, err = os.ReadFile(certPath)
require.NoError(t, err) require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath) keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err) require.NoError(t, err)
// Load the certificate. // Load the certificate.
+3 -3
View File
@@ -3,7 +3,7 @@ package cert
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"io/ioutil" "os"
"sync" "sync"
) )
@@ -31,11 +31,11 @@ var (
func GetCertBytesFromPath(certPath, keyPath string) (certBytes, func GetCertBytesFromPath(certPath, keyPath string) (certBytes,
keyBytes []byte, err error) { keyBytes []byte, err error) {
certBytes, err = ioutil.ReadFile(certPath) certBytes, err = os.ReadFile(certPath)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
keyBytes, err = ioutil.ReadFile(keyPath) keyBytes, err = os.ReadFile(keyPath)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
+1 -2
View File
@@ -2,7 +2,6 @@ package chanbackup
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@@ -138,7 +137,7 @@ func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) {
// Now that we've confirmed the target file is populated, we'll read // Now that we've confirmed the target file is populated, we'll read
// all the contents of the file. This function ensures that file is // all the contents of the file. This function ensures that file is
// always closed, even if we can't read the contents. // always closed, even if we can't read the contents.
multiBytes, err := ioutil.ReadFile(b.fileName) multiBytes, err := os.ReadFile(b.fileName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+1 -2
View File
@@ -3,7 +3,6 @@ package chanbackup
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@@ -27,7 +26,7 @@ func assertBackupMatches(t *testing.T, filePath string,
t.Helper() t.Helper()
packedBackup, err := ioutil.ReadFile(filePath) packedBackup, err := os.ReadFile(filePath)
require.NoError(t, err, "unable to test file") require.NoError(t, err, "unable to test file")
if !bytes.Equal(packedBackup, currentBackup) { if !bytes.Equal(packedBackup, currentBackup) {
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net" "net"
"os"
"strconv" "strconv"
"strings" "strings"
"unicode" "unicode"
@@ -352,7 +353,7 @@ func printMacaroon(ctx *cli.Context) error {
macPath := lncfg.CleanAndExpandPath(ctx.String("macaroon_file")) macPath := lncfg.CleanAndExpandPath(ctx.String("macaroon_file"))
// Load the specified macaroon file. // Load the specified macaroon file.
macBytes, err = ioutil.ReadFile(macPath) macBytes, err = os.ReadFile(macPath)
if err != nil { if err != nil {
return fmt.Errorf("unable to read macaroon path %v: %v", return fmt.Errorf("unable to read macaroon path %v: %v",
macPath, err) macPath, err)
@@ -441,7 +442,7 @@ func constrainMacaroon(ctx *cli.Context) error {
sourceMacFile := lncfg.CleanAndExpandPath(args.First()) sourceMacFile := lncfg.CleanAndExpandPath(args.First())
args = args.Tail() args = args.Tail()
sourceMacBytes, err := ioutil.ReadFile(sourceMacFile) sourceMacBytes, err := os.ReadFile(sourceMacFile)
if err != nil { if err != nil {
return fmt.Errorf("error trying to read source macaroon file "+ return fmt.Errorf("error trying to read source macaroon file "+
"%s: %v", sourceMacFile, err) "%s: %v", sourceMacFile, err)
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@@ -1016,7 +1015,7 @@ func readTerminalOrFile(quit chan struct{}) (string, error) {
// If it's a path to an existing file and it's small enough, let's try // If it's a path to an existing file and it's small enough, let's try
// to read its content now. // to read its content now.
content, err := ioutil.ReadFile(maybeFile) content, err := os.ReadFile(maybeFile)
if err != nil { if err != nil {
return "", err return "", err
} }
+1 -2
View File
@@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@@ -423,7 +422,7 @@ func profileAddMacaroon(ctx *cli.Context) error {
// Now load and possibly encrypt the macaroon file. // Now load and possibly encrypt the macaroon file.
macPath := lncfg.CleanAndExpandPath(ctx.GlobalString("macaroonpath")) macPath := lncfg.CleanAndExpandPath(ctx.GlobalString("macaroonpath"))
macBytes, err := ioutil.ReadFile(macPath) macBytes, err := os.ReadFile(macPath)
if err != nil { if err != nil {
return fmt.Errorf("unable to read macaroon path: %w", err) return fmt.Errorf("unable to read macaroon path: %w", err)
} }
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@@ -712,7 +711,7 @@ func createWatchOnly(ctx *cli.Context) error {
} }
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First()) jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
jsonBytes, err := ioutil.ReadFile(jsonFile) jsonBytes, err := os.ReadFile(jsonFile)
if err != nil { if err != nil {
return fmt.Errorf("error reading JSON from file %v: %v", return fmt.Errorf("error reading JSON from file %v: %v",
jsonFile, err) jsonFile, err)
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"os" "os"
"strconv" "strconv"
@@ -2833,7 +2832,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error)
}, nil }, nil
case ctx.IsSet("multi_file"): case ctx.IsSet("multi_file"):
packedMulti, err := ioutil.ReadFile(ctx.String("multi_file")) packedMulti, err := os.ReadFile(ctx.String("multi_file"))
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to decode multi packed "+ return nil, fmt.Errorf("unable to decode multi packed "+
"backup: %v", err) "backup: %v", err)
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path" "path"
"strings" "strings"
@@ -129,7 +130,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) (
var tlsCert []byte var tlsCert []byte
if tlsCertPath != "" && !insecure { if tlsCertPath != "" && !insecure {
var err error var err error
tlsCert, err = ioutil.ReadFile(tlsCertPath) tlsCert, err = os.ReadFile(tlsCertPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not load TLS cert "+ return nil, fmt.Errorf("could not load TLS cert "+
"file: %v", err) "file: %v", err)
@@ -167,7 +168,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) (
} }
// Now load and possibly encrypt the macaroon file. // Now load and possibly encrypt the macaroon file.
macBytes, err := ioutil.ReadFile(macPath) macBytes, err := os.ReadFile(macPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read macaroon path (check "+ return nil, fmt.Errorf("unable to read macaroon path (check "+
"the network setting!): %v", err) "the network setting!): %v", err)
@@ -222,7 +223,7 @@ func loadProfileFile(file string) (*profileFile, error) {
return nil, errNoProfileFile return nil, errNoProfileFile
} }
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not load profile file %s: %w", return nil, fmt.Errorf("could not load profile file %s: %w",
file, err) file, err)
+2 -3
View File
@@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"os/user" "os/user"
@@ -1846,7 +1845,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
// We convert the cookie into a user name and password. // We convert the cookie into a user name and password.
if conf.RPCCookie != "" { if conf.RPCCookie != "" {
cookie, err := ioutil.ReadFile(conf.RPCCookie) cookie, err := os.ReadFile(conf.RPCCookie)
if err != nil { if err != nil {
return fmt.Errorf("cannot read cookie file: %w", return fmt.Errorf("cannot read cookie file: %w",
err) err)
@@ -2119,7 +2118,7 @@ func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath,
if rpcCookiePath != "" { if rpcCookiePath != "" {
cookiePath = rpcCookiePath cookiePath = rpcCookiePath
} }
cookie, err := ioutil.ReadFile(cookiePath) cookie, err := os.ReadFile(cookiePath)
if err == nil { if err == nil {
splitCookie := strings.Split(string(cookie), ":") splitCookie := strings.Split(string(cookie), ":")
if len(splitCookie) == 2 { if len(splitCookie) == 2 {
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@@ -329,7 +328,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
case d.cfg.WalletUnlockPasswordFile != "" && walletExists: case d.cfg.WalletUnlockPasswordFile != "" && walletExists:
d.logger.Infof("Attempting automatic wallet unlock with " + d.logger.Infof("Attempting automatic wallet unlock with " +
"password provided in file") "password provided in file")
pwBytes, err := ioutil.ReadFile(d.cfg.WalletUnlockPasswordFile) pwBytes, err := os.ReadFile(d.cfg.WalletUnlockPasswordFile)
if err != nil { if err != nil {
return nil, nil, nil, fmt.Errorf("error reading "+ return nil, nil, nil, fmt.Errorf("error reading "+
"password from file %s: %v", "password from file %s: %v",
+6 -7
View File
@@ -3,7 +3,6 @@ package itest
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@@ -285,7 +284,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) {
// Read the entire Multi backup stored within // Read the entire Multi backup stored within
// this node's channel.backup file. // this node's channel.backup file.
multi, err := ioutil.ReadFile(backupFilePath) multi, err := os.ReadFile(backupFilePath)
require.NoError(st, err) require.NoError(st, err)
// Now that we have Dave's backup file, we'll // Now that we have Dave's backup file, we'll
@@ -376,7 +375,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) {
// Read the entire Multi backup stored within // Read the entire Multi backup stored within
// this node's channel.backup file. // this node's channel.backup file.
multi, err := ioutil.ReadFile(backupFilePath) multi, err := os.ReadFile(backupFilePath)
require.NoError(st, err) require.NoError(st, err)
// Now that we have Dave's backup file, we'll // Now that we have Dave's backup file, we'll
@@ -501,7 +500,7 @@ func runChanRestoreScenarioUnConfirmed(ht *lntest.HarnessTest, useFile bool) {
backupFilePath := dave.Cfg.ChanBackupPath() backupFilePath := dave.Cfg.ChanBackupPath()
// Read the entire Multi backup stored within this node's // Read the entire Multi backup stored within this node's
// channel.backup file. // channel.backup file.
multi, err = ioutil.ReadFile(backupFilePath) multi, err = os.ReadFile(backupFilePath)
require.NoError(ht, err) require.NoError(ht, err)
} else { } else {
// For this restoration method, we'll grab the current // For this restoration method, we'll grab the current
@@ -646,7 +645,7 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
// Read the entire Multi backup stored within this node's // Read the entire Multi backup stored within this node's
// channels.backup file. // channels.backup file.
multi, err := ioutil.ReadFile(backupFilePath) multi, err := os.ReadFile(backupFilePath)
require.NoError(ht, err) require.NoError(ht, err)
// If this was a zero conf taproot channel, then since it's private, // If this was a zero conf taproot channel, then since it's private,
@@ -774,7 +773,7 @@ func runChanRestoreScenarioForceClose(ht *lntest.HarnessTest, zeroConf bool) {
// Read the entire Multi backup stored within this node's // Read the entire Multi backup stored within this node's
// channel.backup file. // channel.backup file.
multi, err := ioutil.ReadFile(backupFilePath) multi, err := os.ReadFile(backupFilePath)
require.NoError(ht, err) require.NoError(ht, err)
// Now that we have Dave's backup file, we'll create a new nodeRestorer // Now that we have Dave's backup file, we'll create a new nodeRestorer
@@ -907,7 +906,7 @@ func testChannelBackupUpdates(ht *lntest.HarnessTest) {
// the on disk back up file to our currentBackup pointer above. // the on disk back up file to our currentBackup pointer above.
assertBackupFileState := func() { assertBackupFileState := func() {
err := wait.NoError(func() error { err := wait.NoError(func() error {
packedBackup, err := ioutil.ReadFile(backupFilePath) packedBackup, err := os.ReadFile(backupFilePath)
if err != nil { if err != nil {
return fmt.Errorf("unable to read backup "+ return fmt.Errorf("unable to read backup "+
"file: %v", err) "file: %v", err)
+3 -3
View File
@@ -4,7 +4,7 @@ import (
"context" "context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
@@ -708,7 +708,7 @@ func testAbandonChannel(ht *lntest.HarnessTest) {
// To make sure the channel is removed from the backup file as well // To make sure the channel is removed from the backup file as well
// when being abandoned, grab a backup snapshot so we can compare it // when being abandoned, grab a backup snapshot so we can compare it
// with the later state. // with the later state.
bkupBefore, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath()) bkupBefore, err := os.ReadFile(alice.Cfg.ChanBackupPath())
require.NoError(ht, err, "channel backup before abandoning channel") require.NoError(ht, err, "channel backup before abandoning channel")
// Send request to abandon channel. // Send request to abandon channel.
@@ -733,7 +733,7 @@ func testAbandonChannel(ht *lntest.HarnessTest) {
// Make sure the channel is no longer in the channel backup list. // Make sure the channel is no longer in the channel backup list.
err = wait.NoError(func() error { err = wait.NoError(func() error {
bkupAfter, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath()) bkupAfter, err := os.ReadFile(alice.Cfg.ChanBackupPath())
if err != nil { if err != nil {
return fmt.Errorf("could not get channel backup "+ return fmt.Errorf("could not get channel backup "+
"before abandoning channel: %v", err) "before abandoning channel: %v", err)
+1 -1
View File
@@ -218,7 +218,7 @@ func lastCompactionDate(dbFile string) (time.Time, error) {
return zeroTime, nil return zeroTime, nil
} }
tsBytes, err := ioutil.ReadFile(tsFile) tsBytes, err := os.ReadFile(tsFile)
if err != nil { if err != nil {
return zeroTime, err return zeroTime, err
} }
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/pprof" "net/http/pprof"
@@ -83,7 +82,7 @@ func AdminAuthOptions(cfg *Config, skipMacaroons bool) ([]grpc.DialOption,
// Get the admin macaroon if macaroons are active. // Get the admin macaroon if macaroons are active.
if !skipMacaroons && !cfg.NoMacaroons { if !skipMacaroons && !cfg.NoMacaroons {
// Load the admin macaroon file. // Load the admin macaroon file.
macBytes, err := ioutil.ReadFile(cfg.AdminMacPath) macBytes, err := os.ReadFile(cfg.AdminMacPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read macaroon "+ return nil, fmt.Errorf("unable to read macaroon "+
"path (check the network setting!): %v", err) "path (check the network setting!): %v", err)
+1 -1
View File
@@ -297,7 +297,7 @@ func (hn *HarnessNode) ReadMacaroon(macPath string, timeout time.Duration) (
// using it. // using it.
var mac *macaroon.Macaroon var mac *macaroon.Macaroon
err := wait.NoError(func() error { err := wait.NoError(func() error {
macBytes, err := ioutil.ReadFile(macPath) macBytes, err := os.ReadFile(macPath)
if err != nil { if err != nil {
return fmt.Errorf("error reading macaroon file: %w", return fmt.Errorf("error reading macaroon file: %w",
err) err)
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"crypto/x509" "crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"time" "time"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
@@ -1259,7 +1259,7 @@ func extractSignature(in *psbt.PInput,
func connectRPC(hostPort, tlsCertPath, macaroonPath string, func connectRPC(hostPort, tlsCertPath, macaroonPath string,
timeout time.Duration) (*grpc.ClientConn, error) { timeout time.Duration) (*grpc.ClientConn, error) {
certBytes, err := ioutil.ReadFile(tlsCertPath) certBytes, err := os.ReadFile(tlsCertPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("error reading TLS cert file %v: %w", return nil, fmt.Errorf("error reading TLS cert file %v: %w",
tlsCertPath, err) tlsCertPath, err)
@@ -1271,7 +1271,7 @@ func connectRPC(hostPort, tlsCertPath, macaroonPath string,
"certificate") "certificate")
} }
macBytes, err := ioutil.ReadFile(macaroonPath) macBytes, err := os.ReadFile(macaroonPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("error reading macaroon file %v: %w", return nil, fmt.Errorf("error reading macaroon file %v: %w",
macaroonPath, err) macaroonPath, err)
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os"
"sort" "sort"
"strings" "strings"
"testing" "testing"
@@ -229,7 +229,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
var testCases []testCase var testCases []testCase
jsonText, err := ioutil.ReadFile(set.jsonFile) jsonText, err := os.ReadFile(set.jsonFile)
require.NoError(t, err) require.NoError(t, err)
err = json.Unmarshal(jsonText, &testCases) err = json.Unmarshal(jsonText, &testCases)
+2 -2
View File
@@ -8,9 +8,9 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"net" "net"
"os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@@ -183,7 +183,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
func parseTestGraph(t *testing.T, useCache bool, path string) ( func parseTestGraph(t *testing.T, useCache bool, path string) (
*testGraphInstance, error) { *testGraphInstance, error) {
graphJSON, err := ioutil.ReadFile(path) graphJSON, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+5 -4
View File
@@ -12,6 +12,7 @@ import (
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"net" "net"
"os"
"testing" "testing"
"time" "time"
@@ -199,7 +200,7 @@ func TestGenerateEphemeralCert(t *testing.T) {
keyBytes, err := tlsManager.loadEphemeralCertificate() keyBytes, err := tlsManager.loadEphemeralCertificate()
require.NoError(t, err, "failed to generate new certificate") require.NoError(t, err, "failed to generate new certificate")
certBytes, err := ioutil.ReadFile(tmpCertPath) certBytes, err := os.ReadFile(tmpCertPath)
require.NoError(t, err) require.NoError(t, err)
tlsr, err := cert.NewTLSReloader(certBytes, keyBytes) tlsr, err := cert.NewTLSReloader(certBytes, keyBytes)
@@ -207,15 +208,15 @@ func TestGenerateEphemeralCert(t *testing.T) {
tlsManager.tlsReloader = tlsr tlsManager.tlsReloader = tlsr
// Make sure .tmp file is created at the tmp cert path. // Make sure .tmp file is created at the tmp cert path.
_, err = ioutil.ReadFile(tmpCertPath) _, err = os.ReadFile(tmpCertPath)
require.NoError(t, err, "couldn't find temp cert file") require.NoError(t, err, "couldn't find temp cert file")
// But no key should be stored. // But no key should be stored.
_, err = ioutil.ReadFile(cfg.TLSKeyPath) _, err = os.ReadFile(cfg.TLSKeyPath)
require.Error(t, err, "shouldn't have found file") require.Error(t, err, "shouldn't have found file")
// And no permanent cert file should be stored. // And no permanent cert file should be stored.
_, err = ioutil.ReadFile(cfg.TLSCertPath) _, err = os.ReadFile(cfg.TLSCertPath)
require.Error(t, err, "shouldn't have found a permanent cert file") require.Error(t, err, "shouldn't have found a permanent cert file")
// Now test that when we reload the certificate it generates the new // Now test that when we reload the certificate it generates the new
+1 -1
View File
@@ -124,7 +124,7 @@ func (f *OnionFile) PrivateKey() ([]byte, error) {
} }
// Try to read the Tor private key to pass into the AddOnion call. // Try to read the Tor private key to pass into the AddOnion call.
privateKeyContent, err := ioutil.ReadFile(f.privateKeyPath) privateKeyContent, err := os.ReadFile(f.privateKeyPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net/textproto" "net/textproto"
"os"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@@ -597,7 +597,7 @@ func (c *Controller) getAuthCookie(info protocolInfo) ([]byte, error) {
cookieFilePath = strings.Trim(cookieFilePath, "\"") cookieFilePath = strings.Trim(cookieFilePath, "\"")
// Read the cookie from the file and ensure it has the correct length. // Read the cookie from the file and ensure it has the correct length.
cookie, err := ioutil.ReadFile(cookieFilePath) cookie, err := os.ReadFile(cookieFilePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }