From 79468d8602eab4abcae6f8cb4189d77351c687ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=CC=88=D0=B4=D0=BE=D1=80=20=D0=9F=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D1=81=D0=BA=D0=B8=D0=B8=CC=86?= Date: Sat, 19 Aug 2023 01:37:41 +0300 Subject: [PATCH] change ioutil.ReadFile -> os.ReadFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Фёдор Партанский --- ccaas_builder/cmd/build/main.go | 5 +-- ccaas_builder/cmd/build/main_test.go | 3 +- ccaas_builder/cmd/detect/main.go | 3 +- cmd/common/comm/client_test.go | 3 +- cmd/common/comm/config.go | 4 +- cmd/configtxgen/main.go | 5 +-- cmd/osnadmin/main_test.go | 3 +- common/channelconfig/util_test.go | 6 +-- common/crypto/expiration_test.go | 6 +-- common/fabhttp/fabhttp_suite_test.go | 3 +- common/fabhttp/tls.go | 4 +- common/fabhttp/tls_test.go | 2 +- .../ledger/blkstorage/blockfile_mgr_test.go | 3 +- common/ledger/blkstorage/blockindex_test.go | 6 +-- common/ledger/blkstorage/reset_test.go | 2 +- common/ledger/snapshot/file_test.go | 3 +- common/viperutil/config_util.go | 5 +-- .../persistence/chaincode_package_test.go | 23 +++++------ core/chaincode/persistence/persistence.go | 2 +- core/common/ccprovider/ccprovider.go | 4 +- core/container/externalbuilder/copy_test.go | 4 +- .../externalbuilder/externalbuilder.go | 2 +- core/container/externalbuilder/instance.go | 3 +- core/deliverservice/config.go | 8 ++-- core/deliverservice/config_test.go | 5 +-- core/handlers/auth/filter/expiration_test.go | 4 +- core/ledger/confighistory/mgr_test.go | 4 +- .../kvledger/channelinfo_provider_test.go | 4 +- .../rwset_backward_compatibility_test.go | 4 +- core/ledger/kvledger/snapshot_test.go | 8 ++-- .../privacyenabledstate/snapshot_test.go | 3 +- .../txmgmt/rwsetutil/kv_rwset_test.go | 3 +- .../kvledger/txmgmt/rwsetutil/rwset_test.go | 3 +- .../statecouchdb/couchdoc_conv_test.go | 6 +-- .../statedb/statecouchdb/redolog_test.go | 4 +- core/operations/operations_suite_test.go | 3 +- core/peer/config.go | 14 +++---- discovery/client/client_test.go | 4 +- discovery/test/integration_test.go | 6 +-- gossip/api/crypto_test.go | 4 +- integration/configtx/configtx_test.go | 4 +- integration/e2e/e2e_test.go | 4 +- integration/gateway/gateway_discovery_test.go | 2 +- integration/ledger/snapshot_test.go | 4 +- integration/lifecycle/lifecycle_test.go | 4 +- integration/msp/rsaca_test.go | 2 +- integration/nwo/configblock.go | 2 +- integration/nwo/deploy.go | 2 +- integration/nwo/network.go | 14 +++---- integration/nwo/operational_client.go | 4 +- integration/nwo/signingid.go | 6 +-- integration/pkcs11/pkcs11_test.go | 6 +-- integration/raft/cft_test.go | 26 ++++++------- .../raft/channel_participation_test.go | 4 +- integration/raft/config_test.go | 30 +++++++-------- integration/raft/migration_test.go | 2 +- integration/smartbft/smartbft_test.go | 14 +++---- internal/cryptogen/msp/msp_test.go | 3 +- internal/fileutil/fileutil_test.go | 5 +-- internal/ledgerutil/compare/compare_test.go | 3 +- internal/peer/chaincode/package_test.go | 7 ++-- internal/peer/chaincode/signpackage_test.go | 8 ++-- .../chaincode/calculatepackageid_test.go | 6 +-- internal/pkg/comm/config_test.go | 8 ++-- internal/pkg/comm/connection_test.go | 6 +-- internal/pkg/comm/creds_test.go | 6 +-- internal/pkg/comm/server_test.go | 38 +++++++++---------- internal/pkg/peer/orderers/connection_test.go | 8 ++-- msp/configbuilder.go | 4 +- orderer/common/cluster/util_test.go | 6 +-- orderer/common/filerepo/filerepo_test.go | 3 +- .../common/msgprocessor/expiration_test.go | 4 +- orderer/common/server/etcdraft_test.go | 4 +- orderer/common/server/main.go | 17 ++++----- orderer/common/server/main_test.go | 11 +++--- orderer/common/server/server_test.go | 3 +- orderer/common/server/util_test.go | 5 +-- .../consensus/etcdraft/blockpuller_test.go | 6 +-- orderer/consensus/etcdraft/consenter_test.go | 2 +- orderer/consensus/etcdraft/util_test.go | 4 +- .../consensus/smartbft/synchronizer_test.go | 4 +- protoutil/signeddata_test.go | 4 +- 82 files changed, 237 insertions(+), 259 deletions(-) diff --git a/ccaas_builder/cmd/build/main.go b/ccaas_builder/cmd/build/main.go index 58616cceb1b..cf574e8c3f1 100644 --- a/ccaas_builder/cmd/build/main.go +++ b/ccaas_builder/cmd/build/main.go @@ -10,7 +10,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -74,7 +73,7 @@ func run() error { return errors.WithMessagef(err, "%s not found ", metadataFile) } - metadataFileContents, cause := ioutil.ReadFile(metadataFile) + metadataFileContents, cause := os.ReadFile(metadataFile) if cause != nil { return errors.WithMessagef(cause, "%s file not readable", metadataFile) } @@ -104,7 +103,7 @@ func run() error { return errors.WithMessagef(err, "%s not found ", connectionSrcFile) } - connectionFileContents, err := ioutil.ReadFile(connectionSrcFile) + connectionFileContents, err := os.ReadFile(connectionSrcFile) if err != nil { return err } diff --git a/ccaas_builder/cmd/build/main_test.go b/ccaas_builder/cmd/build/main_test.go index eb43a896290..4b0fae56641 100644 --- a/ccaas_builder/cmd/build/main_test.go +++ b/ccaas_builder/cmd/build/main_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package main import ( - "io/ioutil" "os" "os/exec" "path" @@ -169,7 +168,7 @@ func TestTemplating(t *testing.T) { gt.Expect(err).NotTo(HaveOccurred()) // check that the file has the exepected contents - connectionFileContents, err := ioutil.ReadFile(chkfile) + connectionFileContents, err := os.ReadFile(chkfile) gt.Expect(err).NotTo(HaveOccurred()) expectedJson := `{ diff --git a/ccaas_builder/cmd/detect/main.go b/ccaas_builder/cmd/detect/main.go index cd3e666a7c8..eb661765205 100644 --- a/ccaas_builder/cmd/detect/main.go +++ b/ccaas_builder/cmd/detect/main.go @@ -9,7 +9,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -53,7 +52,7 @@ func run() error { return errors.WithMessagef(err, "%s not found ", metadataFile) } - mdbytes, cause := ioutil.ReadFile(metadataFile) + mdbytes, cause := os.ReadFile(metadataFile) if cause != nil { err := errors.WithMessagef(cause, "%s not readable", metadataFile) return err diff --git a/cmd/common/comm/client_test.go b/cmd/common/comm/client_test.go index 33880dab46a..583cd4179fe 100644 --- a/cmd/common/comm/client_test.go +++ b/cmd/common/comm/client_test.go @@ -8,7 +8,6 @@ package comm import ( "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -99,7 +98,7 @@ func TestClientBadConfig(t *testing.T) { } func loadFileOrDie(path string) []byte { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { fmt.Println("Failed opening file", path, ":", err) os.Exit(1) diff --git a/cmd/common/comm/config.go b/cmd/common/comm/config.go index 8338b58ff27..d6d628695b0 100644 --- a/cmd/common/comm/config.go +++ b/cmd/common/comm/config.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package comm import ( - "io/ioutil" + "os" "time" "github.com/hyperledger/fabric/common/crypto/tlsgen" @@ -64,7 +64,7 @@ func (conf Config) ToSecureOptions(newSelfSignedTLSCert genTLSCertFunc) (comm.Se } func loadFile(path string) ([]byte, error) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return nil, errors.Errorf("Failed opening file %s: %v", path, err) } diff --git a/cmd/configtxgen/main.go b/cmd/configtxgen/main.go index f5b355b2bc8..919d14ff780 100644 --- a/cmd/configtxgen/main.go +++ b/cmd/configtxgen/main.go @@ -9,7 +9,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -133,7 +132,7 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou func doInspectBlock(inspectBlock string) error { logger.Info("Inspecting block") - data, err := ioutil.ReadFile(inspectBlock) + data, err := os.ReadFile(inspectBlock) if err != nil { return fmt.Errorf("could not read block %s", inspectBlock) } @@ -152,7 +151,7 @@ func doInspectBlock(inspectBlock string) error { func doInspectChannelCreateTx(inspectChannelCreateTx string) error { logger.Info("Inspecting transaction") - data, err := ioutil.ReadFile(inspectChannelCreateTx) + data, err := os.ReadFile(inspectChannelCreateTx) if err != nil { return fmt.Errorf("could not read channel create tx: %s", err) } diff --git a/cmd/osnadmin/main_test.go b/cmd/osnadmin/main_test.go index 493be2342fa..4f63b8acb95 100644 --- a/cmd/osnadmin/main_test.go +++ b/cmd/osnadmin/main_test.go @@ -12,7 +12,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math" "net/http/httptest" "net/url" @@ -75,7 +74,7 @@ var _ = Describe("osnadmin", func() { Expect(err).NotTo(HaveOccurred()) caCertPool := x509.NewCertPool() - clientCAPem, err := ioutil.ReadFile(filepath.Join(tempDir, "client-ca.pem")) + clientCAPem, err := os.ReadFile(filepath.Join(tempDir, "client-ca.pem")) Expect(err).NotTo(HaveOccurred()) caCertPool.AppendCertsFromPEM(clientCAPem) diff --git a/common/channelconfig/util_test.go b/common/channelconfig/util_test.go index 200a9f31a4b..ce1d8963bae 100644 --- a/common/channelconfig/util_test.go +++ b/common/channelconfig/util_test.go @@ -9,7 +9,7 @@ package channelconfig import ( "bytes" "fmt" - "io/ioutil" + "os" "testing" "github.com/golang/protobuf/proto" @@ -299,7 +299,7 @@ func TestValidateCapabilities(t *testing.T) { func TestExtractMSPIDsForApplicationOrgs(t *testing.T) { // load test_configblock.json that contains the application group // and other properties needed to build channel config and extract MSPIDs - blockData, err := ioutil.ReadFile("testdata/test_configblock.json") + blockData, err := os.ReadFile("testdata/test_configblock.json") require.NoError(t, err) block := &cb.Block{} protolator.DeepUnmarshalJSON(bytes.NewBuffer(blockData), block) @@ -348,7 +348,7 @@ func TestMarshalEtcdRaftMetadata(t *testing.T) { var outputCerts, inputCerts [3][]byte for i := range unpacked.GetConsenters() { outputCerts[i] = unpacked.GetConsenters()[i].GetClientTlsCert() - inputCerts[i], _ = ioutil.ReadFile(fmt.Sprintf("testdata/tls-client-%d.pem", i+1)) + inputCerts[i], _ = os.ReadFile(fmt.Sprintf("testdata/tls-client-%d.pem", i+1)) } for i := 0; i < len(inputCerts)-1; i++ { diff --git a/common/crypto/expiration_test.go b/common/crypto/expiration_test.go index 6284bc11baf..b818f4c6ff8 100644 --- a/common/crypto/expiration_test.go +++ b/common/crypto/expiration_test.go @@ -11,7 +11,7 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -25,7 +25,7 @@ import ( ) func TestX509CertExpiresAt(t *testing.T) { - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "cert.pem")) + certBytes, err := os.ReadFile(filepath.Join("testdata", "cert.pem")) require.NoError(t, err) sId := &msp.SerializedIdentity{ IdBytes: certBytes, @@ -37,7 +37,7 @@ func TestX509CertExpiresAt(t *testing.T) { } func TestX509InvalidCertExpiresAt(t *testing.T) { - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "badCert.pem")) + certBytes, err := os.ReadFile(filepath.Join("testdata", "badCert.pem")) require.NoError(t, err) sId := &msp.SerializedIdentity{ IdBytes: certBytes, diff --git a/common/fabhttp/fabhttp_suite_test.go b/common/fabhttp/fabhttp_suite_test.go index 45336223fe9..7eb4b4519a6 100644 --- a/common/fabhttp/fabhttp_suite_test.go +++ b/common/fabhttp/fabhttp_suite_test.go @@ -9,7 +9,6 @@ package fabhttp_test import ( "crypto/tls" "crypto/x509" - "io/ioutil" "net/http" "os" "path/filepath" @@ -51,7 +50,7 @@ func generateCertificates(tempDir string) { func newHTTPClient(tlsDir string, withClientCert bool, tlsOpts ...func(config *tls.Config)) *http.Client { clientCertPool := x509.NewCertPool() - caCert, err := ioutil.ReadFile(filepath.Join(tlsDir, "server-ca.pem")) + caCert, err := os.ReadFile(filepath.Join(tlsDir, "server-ca.pem")) Expect(err).NotTo(HaveOccurred()) clientCertPool.AppendCertsFromPEM(caCert) diff --git a/common/fabhttp/tls.go b/common/fabhttp/tls.go index 9e17c776d9b..e31aa8bf322 100644 --- a/common/fabhttp/tls.go +++ b/common/fabhttp/tls.go @@ -9,7 +9,7 @@ package fabhttp import ( "crypto/tls" "crypto/x509" - "io/ioutil" + "os" "github.com/hyperledger/fabric/internal/pkg/comm" ) @@ -32,7 +32,7 @@ func (t TLS) Config() (*tls.Config, error) { } caCertPool := x509.NewCertPool() for _, caPath := range t.ClientCACertFiles { - caPem, err := ioutil.ReadFile(caPath) + caPem, err := os.ReadFile(caPath) if err != nil { return nil, err } diff --git a/common/fabhttp/tls_test.go b/common/fabhttp/tls_test.go index cb0c8d47e69..7a209a15cd7 100644 --- a/common/fabhttp/tls_test.go +++ b/common/fabhttp/tls_test.go @@ -51,7 +51,7 @@ var _ = Describe("TLS", func() { ) Expect(err).NotTo(HaveOccurred()) - pemBytes, err := ioutil.ReadFile(filepath.Join(tempDir, "client-ca.pem")) + pemBytes, err := os.ReadFile(filepath.Join(tempDir, "client-ca.pem")) Expect(err).NotTo(HaveOccurred()) clientCAPool := x509.NewCertPool() diff --git a/common/ledger/blkstorage/blockfile_mgr_test.go b/common/ledger/blkstorage/blockfile_mgr_test.go index dc05b2ab505..4d16f9dcaf7 100644 --- a/common/ledger/blkstorage/blockfile_mgr_test.go +++ b/common/ledger/blkstorage/blockfile_mgr_test.go @@ -8,7 +8,6 @@ package blkstorage import ( "fmt" - "io/ioutil" "os" "testing" @@ -479,7 +478,7 @@ func testBlockfileMgrSimulateCrashAtFirstBlockInFile(t *testing.T, deleteBlkfile // verify that the block file number 1 has been created with partial bytes as a side-effect of crash lastFilePath := blockfileMgr.currentFileWriter.filePath - lastFileContent, err := ioutil.ReadFile(lastFilePath) + lastFileContent, err := os.ReadFile(lastFilePath) require.NoError(t, err) require.Equal(t, lastFileContent, partialBytesForNextBlock) diff --git a/common/ledger/blkstorage/blockindex_test.go b/common/ledger/blkstorage/blockindex_test.go index 5daa989ba80..62f824f808b 100644 --- a/common/ledger/blkstorage/blockindex_test.go +++ b/common/ledger/blkstorage/blockindex_test.go @@ -311,7 +311,7 @@ func TestExportUniqueTxIDs(t *testing.T) { require.NoError(t, err) fileHashes, err = blkfileMgr.index.exportUniqueTxIDs(testSnapshotDir, testNewHashFunc) require.NoError(t, err) - verifyExportedTxIDs(t, testSnapshotDir, fileHashes, "txid-1", "txid-2", "txid-3", configTxID) //"txid-1" appears once, Txids appear in radix sort order + verifyExportedTxIDs(t, testSnapshotDir, fileHashes, "txid-1", "txid-2", "txid-3", configTxID) // "txid-1" appears once, Txids appear in radix sort order os.Remove(filepath.Join(testSnapshotDir, snapshotDataFileName)) os.Remove(filepath.Join(testSnapshotDir, snapshotMetadataFileName)) @@ -399,13 +399,13 @@ func verifyExportedTxIDs(t *testing.T, dir string, fileHashes map[string][]byte, require.Contains(t, fileHashes, snapshotMetadataFileName) dataFile := filepath.Join(dir, snapshotDataFileName) - dataFileContent, err := ioutil.ReadFile(dataFile) + dataFileContent, err := os.ReadFile(dataFile) require.NoError(t, err) dataFileHash := sha256.Sum256(dataFileContent) require.Equal(t, dataFileHash[:], fileHashes[snapshotDataFileName]) metadataFile := filepath.Join(dir, snapshotMetadataFileName) - metadataFileContent, err := ioutil.ReadFile(metadataFile) + metadataFileContent, err := os.ReadFile(metadataFile) require.NoError(t, err) metadataFileHash := sha256.Sum256(metadataFileContent) require.Equal(t, metadataFileHash[:], fileHashes[snapshotMetadataFileName]) diff --git a/common/ledger/blkstorage/reset_test.go b/common/ledger/blkstorage/reset_test.go index a0ebfbe3b48..9294ce4c94b 100644 --- a/common/ledger/blkstorage/reset_test.go +++ b/common/ledger/blkstorage/reset_test.go @@ -249,7 +249,7 @@ func assertBlockStorePostReset(t *testing.T, store *BlockStore, originallyCommit } func assertRecordedHeight(t *testing.T, ledgerDir, expectedRecordedHt string) { - bytes, err := ioutil.ReadFile(path.Join(ledgerDir, fileNamePreRestHt)) + bytes, err := os.ReadFile(path.Join(ledgerDir, fileNamePreRestHt)) require.NoError(t, err) require.Equal(t, expectedRecordedHt, string(bytes)) } diff --git a/common/ledger/snapshot/file_test.go b/common/ledger/snapshot/file_test.go index 1cecd1cdef4..32655a9f545 100644 --- a/common/ledger/snapshot/file_test.go +++ b/common/ledger/snapshot/file_test.go @@ -11,7 +11,6 @@ import ( "crypto/sha256" "errors" "hash" - "io/ioutil" "os" "path" "testing" @@ -214,7 +213,7 @@ func TestFileReaderErrorPropagation(t *testing.T) { } func computeSha256(t *testing.T, file string) []byte { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) require.NoError(t, err) sha := sha256.Sum256(data) return sha[:] diff --git a/common/viperutil/config_util.go b/common/viperutil/config_util.go index 24e5bced44d..25d3ebda241 100644 --- a/common/viperutil/config_util.go +++ b/common/viperutil/config_util.go @@ -10,7 +10,6 @@ import ( "encoding/pem" "fmt" "io" - "io/ioutil" "math" "os" "path/filepath" @@ -286,7 +285,7 @@ func stringFromFileDecodeHook(f reflect.Kind, t reflect.Kind, data interface{}) } switch { case ok && fileName != nil: - bytes, err := ioutil.ReadFile(fileName.(string)) + bytes, err := os.ReadFile(fileName.(string)) if err != nil { return data, err } @@ -333,7 +332,7 @@ func pemBlocksFromFileDecodeHook(f reflect.Kind, t reflect.Kind, data interface{ switch { case ok && fileName != "": var result []string - bytes, err := ioutil.ReadFile(fileName) + bytes, err := os.ReadFile(fileName) if err != nil { return data, err } diff --git a/core/chaincode/persistence/chaincode_package_test.go b/core/chaincode/persistence/chaincode_package_test.go index 5a2dfc92dd4..c2eb3a112d8 100644 --- a/core/chaincode/persistence/chaincode_package_test.go +++ b/core/chaincode/persistence/chaincode_package_test.go @@ -8,6 +8,7 @@ package persistence_test import ( "io/ioutil" + "os" pb "github.com/hyperledger/fabric-protos-go/peer" "github.com/hyperledger/fabric/core/chaincode/persistence" @@ -125,7 +126,7 @@ var _ = Describe("ChaincodePackageParser", func() { Describe("ParseChaincodePackage", func() { It("parses a chaincode package", func() { - data, err := ioutil.ReadFile("testdata/good-package.tar.gz") + data, err := os.ReadFile("testdata/good-package.tar.gz") Expect(err).NotTo(HaveOccurred()) ccPackage, err := ccpp.Parse(data) @@ -154,7 +155,7 @@ var _ = Describe("ChaincodePackageParser", func() { }) It("fails", func() { - data, err := ioutil.ReadFile("testdata/good-package.tar.gz") + data, err := os.ReadFile("testdata/good-package.tar.gz") Expect(err).NotTo(HaveOccurred()) ccPackage, err := ccpp.Parse(data) @@ -165,7 +166,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the chaincode package metadata is missing", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/missing-metadata.tar.gz") + data, err := os.ReadFile("testdata/missing-metadata.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -175,7 +176,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the chaincode package metadata is corrupt", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/bad-metadata.tar.gz") + data, err := os.ReadFile("testdata/bad-metadata.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -185,7 +186,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the label is empty or missing", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/empty-label.tar.gz") + data, err := os.ReadFile("testdata/empty-label.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -195,7 +196,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the label contains forbidden characters", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/bad-label.tar.gz") + data, err := os.ReadFile("testdata/bad-label.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -205,7 +206,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the tar file is corrupted", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/corrupted-package.tar.gz") + data, err := os.ReadFile("testdata/corrupted-package.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -215,7 +216,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the tar has non-regular files", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/non-regular-file.tar.gz") + data, err := os.ReadFile("testdata/non-regular-file.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -225,7 +226,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the tar has a corrupt header entry", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/corrupted-header.tar.gz") + data, err := os.ReadFile("testdata/corrupted-header.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -235,7 +236,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the tar has too many entries", func() { It("logs a warning but otherwise allows it", func() { - data, err := ioutil.ReadFile("testdata/too-many-files.tar.gz") + data, err := os.ReadFile("testdata/too-many-files.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) @@ -245,7 +246,7 @@ var _ = Describe("ChaincodePackageParser", func() { Context("when the tar is missing a code-package", func() { It("fails", func() { - data, err := ioutil.ReadFile("testdata/missing-codepackage.tar.gz") + data, err := os.ReadFile("testdata/missing-codepackage.tar.gz") Expect(err).NotTo(HaveOccurred()) _, err = ccpp.Parse(data) diff --git a/core/chaincode/persistence/persistence.go b/core/chaincode/persistence/persistence.go index 6d900cdb1fb..6132544c535 100644 --- a/core/chaincode/persistence/persistence.go +++ b/core/chaincode/persistence/persistence.go @@ -79,7 +79,7 @@ func (f *FilesystemIO) Remove(name string) error { // ReadFile reads a file from the filesystem func (f *FilesystemIO) ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) + return os.ReadFile(filename) } // ReadDir reads a directory from the filesystem diff --git a/core/common/ccprovider/ccprovider.go b/core/common/ccprovider/ccprovider.go index 67c0083ac62..6fdcd63baf2 100644 --- a/core/common/ccprovider/ccprovider.go +++ b/core/common/ccprovider/ccprovider.go @@ -96,7 +96,7 @@ func GetChaincodePackageFromPath(ccNameVersion string, ccInstallPath string) ([] path := fmt.Sprintf("%s/%s", ccInstallPath, strings.ReplaceAll(ccNameVersion, ":", ".")) var ccbytes []byte var err error - if ccbytes, err = ioutil.ReadFile(path); err != nil { + if ccbytes, err = os.ReadFile(path); err != nil { return nil, err } return ccbytes, nil @@ -354,7 +354,7 @@ func GetInstalledChaincodes() (*pb.ChaincodeQueryResponse, error) { return cqr, nil } -//-------- ChaincodeData is stored on the LSCC ------- +// -------- ChaincodeData is stored on the LSCC ------- // ChaincodeData defines the datastructure for chaincodes to be serialized by proto // Type provides an additional check by directing to use a specific package after instantiation diff --git a/core/container/externalbuilder/copy_test.go b/core/container/externalbuilder/copy_test.go index 2c75ffb706e..9cf83ad399b 100644 --- a/core/container/externalbuilder/copy_test.go +++ b/core/container/externalbuilder/copy_test.go @@ -71,7 +71,7 @@ var _ = Describe("copy", func() { Expect(destRootDir).To(BeADirectory()) Expect(filepath.Join(destRootDir, "file-in-root.txt")).To(BeARegularFile()) - contents, err := ioutil.ReadFile(filepath.Join(destRootDir, "file-in-root.txt")) + contents, err := os.ReadFile(filepath.Join(destRootDir, "file-in-root.txt")) Expect(err).NotTo(HaveOccurred()) Expect(contents).To(Equal([]byte("root file contents"))) @@ -82,7 +82,7 @@ var _ = Describe("copy", func() { Expect(destSubDir).To(BeADirectory()) Expect(filepath.Join(destSubDir, "file-in-subdir.txt")).To(BeARegularFile()) - contents, err = ioutil.ReadFile(filepath.Join(destSubDir, "file-in-subdir.txt")) + contents, err = os.ReadFile(filepath.Join(destSubDir, "file-in-subdir.txt")) Expect(err).NotTo(HaveOccurred()) Expect(contents).To(Equal([]byte("subdir file contents"))) diff --git a/core/container/externalbuilder/externalbuilder.go b/core/container/externalbuilder/externalbuilder.go index 02b319b0f57..5917b3fd60c 100644 --- a/core/container/externalbuilder/externalbuilder.go +++ b/core/container/externalbuilder/externalbuilder.go @@ -62,7 +62,7 @@ func (d *Detector) CachedBuild(ccid string) (*Instance, error) { } buildInfoPath := filepath.Join(durablePath, "build-info.json") - buildInfoData, err := ioutil.ReadFile(buildInfoPath) + buildInfoData, err := os.ReadFile(buildInfoPath) if err != nil { return nil, errors.WithMessagef(err, "could not read '%s' for build info", buildInfoPath) } diff --git a/core/container/externalbuilder/instance.go b/core/container/externalbuilder/instance.go index 444583fcac1..4bb11971ee1 100644 --- a/core/container/externalbuilder/instance.go +++ b/core/container/externalbuilder/instance.go @@ -8,7 +8,6 @@ package externalbuilder import ( "encoding/json" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -133,7 +132,7 @@ func (i *Instance) ChaincodeServerInfo() (*ccintf.ChaincodeServerInfo, error) { if err != nil { return nil, errors.WithMessage(err, "connection information not provided") } - b, err := ioutil.ReadFile(ccinfoPath) + b, err := os.ReadFile(ccinfoPath) if err != nil { return nil, errors.WithMessagef(err, "could not read '%s' for chaincode info", ccinfoPath) } diff --git a/core/deliverservice/config.go b/core/deliverservice/config.go index 09af248f052..e344749ea39 100644 --- a/core/deliverservice/config.go +++ b/core/deliverservice/config.go @@ -8,7 +8,7 @@ package deliverservice import ( "encoding/pem" - "io/ioutil" + "os" "time" "github.com/hyperledger/fabric/core/config" @@ -76,7 +76,7 @@ func LoadOverridesMap() (map[string]*orderers.Endpoint, error) { for _, override := range overrides { var rootCerts [][]byte if override.CACertsFile != "" { - pem, err := ioutil.ReadFile(override.CACertsFile) + pem, err := os.ReadFile(override.CACertsFile) if err != nil { logger.Warningf("could not read file '%s' specified for caCertsFile of orderer endpoint override from '%s' to '%s': %s", override.CACertsFile, override.From, override.To, err) continue @@ -165,12 +165,12 @@ func (c *DeliverServiceConfig) loadDeliverServiceConfig() { keyFile = config.GetPath("peer.tls.key.file") } - keyPEM, err := ioutil.ReadFile(keyFile) + keyPEM, err := os.ReadFile(keyFile) if err != nil { panic(errors.WithMessagef(err, "unable to load key at '%s'", keyFile)) } c.SecOpts.Key = keyPEM - certPEM, err := ioutil.ReadFile(certFile) + certPEM, err := os.ReadFile(certFile) if err != nil { panic(errors.WithMessagef(err, "unable to load cert at '%s'", certFile)) } diff --git a/core/deliverservice/config_test.go b/core/deliverservice/config_test.go index b3658bb83a6..ddaa069e035 100644 --- a/core/deliverservice/config_test.go +++ b/core/deliverservice/config_test.go @@ -8,7 +8,6 @@ package deliverservice_test import ( "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -27,10 +26,10 @@ func TestSecureOptsConfig(t *testing.T) { certPath := filepath.Join(cwd, "testdata", "cert.pem") keyPath := filepath.Join(cwd, "testdata", "key.pem") - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "cert.pem")) + certBytes, err := os.ReadFile(filepath.Join("testdata", "cert.pem")) require.NoError(t, err) - keyBytes, err := ioutil.ReadFile(filepath.Join("testdata", "key.pem")) + keyBytes, err := os.ReadFile(filepath.Join("testdata", "key.pem")) require.NoError(t, err) t.Run("client specific cert", func(t *testing.T) { diff --git a/core/handlers/auth/filter/expiration_test.go b/core/handlers/auth/filter/expiration_test.go index ddefff67bca..fb49a3762fb 100644 --- a/core/handlers/auth/filter/expiration_test.go +++ b/core/handlers/auth/filter/expiration_test.go @@ -8,7 +8,7 @@ package filter import ( "context" - "io/ioutil" + "os" "path/filepath" "testing" @@ -32,7 +32,7 @@ func corruptMutator(b []byte) []byte { } func createX509Identity(t *testing.T, certFileName string) []byte { - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", certFileName)) + certBytes, err := os.ReadFile(filepath.Join("testdata", certFileName)) require.NoError(t, err) sId := &msp.SerializedIdentity{ IdBytes: certBytes, diff --git a/core/ledger/confighistory/mgr_test.go b/core/ledger/confighistory/mgr_test.go index ba636ca0094..3019d1f36a1 100644 --- a/core/ledger/confighistory/mgr_test.go +++ b/core/ledger/confighistory/mgr_test.go @@ -458,13 +458,13 @@ func verifyExportedConfigHistory(t *testing.T, dir string, fileHashes map[string require.Contains(t, fileHashes, snapshotMetadataFileName) dataFile := filepath.Join(dir, snapshotDataFileName) - dataFileContent, err := ioutil.ReadFile(dataFile) + dataFileContent, err := os.ReadFile(dataFile) require.NoError(t, err) dataFileHash := sha256.Sum256(dataFileContent) require.Equal(t, dataFileHash[:], fileHashes[snapshotDataFileName]) metadataFile := filepath.Join(dir, snapshotMetadataFileName) - metadataFileContent, err := ioutil.ReadFile(metadataFile) + metadataFileContent, err := os.ReadFile(metadataFile) require.NoError(t, err) metadataFileHash := sha256.Sum256(metadataFileContent) require.Equal(t, metadataFileHash[:], fileHashes[snapshotMetadataFileName]) diff --git a/core/ledger/kvledger/channelinfo_provider_test.go b/core/ledger/kvledger/channelinfo_provider_test.go index e174be4c687..a6ee7466d6c 100644 --- a/core/ledger/kvledger/channelinfo_provider_test.go +++ b/core/ledger/kvledger/channelinfo_provider_test.go @@ -9,7 +9,7 @@ package kvledger import ( "bytes" "fmt" - "io/ioutil" + "os" "testing" "github.com/golang/protobuf/proto" @@ -280,7 +280,7 @@ func getEnvelopeFromConfig(channelName string, config *cb.Config) *cb.Envelope { // createTestOrgGroups returns application org ConfigGroups based on test_configblock.json. // The config block contains the following organizations(MSPIDs): org1(Org1MSP) and org2(Org2MSP) func createTestOrgGroups(t *testing.T) map[string]*cb.ConfigGroup { - blockData, err := ioutil.ReadFile("testdata/test_configblock.json") + blockData, err := os.ReadFile("testdata/test_configblock.json") require.NoError(t, err) block := &cb.Block{} require.NoError(t, protolator.DeepUnmarshalJSON(bytes.NewBuffer(blockData), block)) diff --git a/core/ledger/kvledger/rwset_backward_compatibility_test.go b/core/ledger/kvledger/rwset_backward_compatibility_test.go index dfe8eae56c1..9c36ea3af62 100644 --- a/core/ledger/kvledger/rwset_backward_compatibility_test.go +++ b/core/ledger/kvledger/rwset_backward_compatibility_test.go @@ -8,7 +8,7 @@ package kvledger import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/hyperledger/fabric-protos-go/common" @@ -23,7 +23,7 @@ import ( // TestBackwardCompatibilityRWSetV21 is added to protect against any changes in the hash function // that is used in preparing the rwset that includes a merkle tree for the range query func TestBackwardCompatibilityRWSetV21(t *testing.T) { - rwsetBytes, err := ioutil.ReadFile("testdata/rwsetbytes_v21") + rwsetBytes, err := os.ReadFile("testdata/rwsetbytes_v21") require.NoError(t, err) b := testGenerateSampleRWSet(t) require.Equal(t, rwsetBytes, b) diff --git a/core/ledger/kvledger/snapshot_test.go b/core/ledger/kvledger/snapshot_test.go index 91fb1e69215..b785e5735ea 100644 --- a/core/ledger/kvledger/snapshot_test.go +++ b/core/ledger/kvledger/snapshot_test.go @@ -625,7 +625,7 @@ func testCreateLedgerFromSnapshotErrorPaths(t *testing.T, originalSnapshotDir st files, err := ioutil.ReadDir(originalSnapshotDir) require.NoError(t, err) for _, f := range files { - content, err := ioutil.ReadFile(filepath.Join(originalSnapshotDir, f.Name())) + content, err := os.ReadFile(filepath.Join(originalSnapshotDir, f.Name())) require.NoError(t, err) err = os.WriteFile(filepath.Join(snapshotDirForTest, f.Name()), content, 0o600) require.NoError(t, err) @@ -871,14 +871,14 @@ func verifySnapshotOutput( filesAndHashes := map[string]string{} for _, f := range o.expectedBinaryFiles { - c, err := ioutil.ReadFile(filepath.Join(snapshotDir, f)) + c, err := os.ReadFile(filepath.Join(snapshotDir, f)) require.NoError(t, err) filesAndHashes[f] = hex.EncodeToString(util.ComputeSHA256(c)) } // verify the contents of the file snapshot_metadata.json m := &SnapshotSignableMetadata{} - mJSON, err := ioutil.ReadFile(filepath.Join(snapshotDir, SnapshotSignableMetadataFileName)) + mJSON, err := os.ReadFile(filepath.Join(snapshotDir, SnapshotSignableMetadataFileName)) require.NoError(t, err) require.NoError(t, json.Unmarshal(mJSON, m)) @@ -900,7 +900,7 @@ func verifySnapshotOutput( // verify the contents of the file snapshot_metadata_hash.json mh := &snapshotAdditionalMetadata{} - mhJSON, err := ioutil.ReadFile(filepath.Join(snapshotDir, snapshotAdditionalMetadataFileName)) + mhJSON, err := os.ReadFile(filepath.Join(snapshotDir, snapshotAdditionalMetadataFileName)) require.NoError(t, err) require.NoError(t, json.Unmarshal(mhJSON, mh)) require.Equal(t, diff --git a/core/ledger/kvledger/txmgmt/privacyenabledstate/snapshot_test.go b/core/ledger/kvledger/txmgmt/privacyenabledstate/snapshot_test.go index 047a226e564..8cbc64b9806 100644 --- a/core/ledger/kvledger/txmgmt/privacyenabledstate/snapshot_test.go +++ b/core/ledger/kvledger/txmgmt/privacyenabledstate/snapshot_test.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "hash" - "io/ioutil" "os" "path/filepath" "strings" @@ -314,7 +313,7 @@ func TestSnapshotImportMetadtaHintImport(t *testing.T) { } func sha256ForFileForTest(t *testing.T, file string) []byte { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) require.NoError(t, err) sha := sha256.Sum256(data) return sha[:] diff --git a/core/ledger/kvledger/txmgmt/rwsetutil/kv_rwset_test.go b/core/ledger/kvledger/txmgmt/rwsetutil/kv_rwset_test.go index 272f8db7c28..4e1061e5771 100644 --- a/core/ledger/kvledger/txmgmt/rwsetutil/kv_rwset_test.go +++ b/core/ledger/kvledger/txmgmt/rwsetutil/kv_rwset_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package rwsetutil import ( - "io/ioutil" "os" "testing" @@ -23,7 +22,7 @@ const kvrwsetV1ProtoBytesFile = "testdata/kvrwsetV1ProtoBytes" // is able to unmarshal the protobytes that are produced by the 'KVRWSet' proto message declared in // v1.0. This is to make sure that any incompatible changes does not go uncaught. func TestKVRWSetV1BackwardCompatible(t *testing.T) { - protoBytes, err := ioutil.ReadFile(kvrwsetV1ProtoBytesFile) + protoBytes, err := os.ReadFile(kvrwsetV1ProtoBytesFile) require.NoError(t, err) kvrwset1 := &kvrwset.KVRWSet{} require.NoError(t, proto.Unmarshal(protoBytes, kvrwset1)) diff --git a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_test.go b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_test.go index 50df94595b3..7974c4b52f4 100644 --- a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_test.go +++ b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_test.go @@ -17,7 +17,6 @@ limitations under the License. package rwsetutil import ( - "io/ioutil" "os" "testing" @@ -33,7 +32,7 @@ const rwsetV1ProtoBytesFile = "testdata/rwsetV1ProtoBytes" // is able to unmarshal the protobytes that are produced by the 'RWSet' proto message declared in // v1.0. This is to make sure that any incompatible changes does not go uncaught. func TestRWSetV1BackwardCompatible(t *testing.T) { - protoBytes, err := ioutil.ReadFile(rwsetV1ProtoBytesFile) + protoBytes, err := os.ReadFile(rwsetV1ProtoBytesFile) require.NoError(t, err) rwset1 := &rwset.TxReadWriteSet{} require.NoError(t, proto.Unmarshal(protoBytes, rwset1)) diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv_test.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv_test.go index c7036101bf0..7bc06c5b1cf 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv_test.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv_test.go @@ -10,7 +10,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "testing" "github.com/hyperledger/fabric/core/ledger/internal/version" @@ -69,7 +69,7 @@ func TestSortJSON(t *testing.T) { } func testSortJSON(t *testing.T, filePrefix int) { - input, err := ioutil.ReadFile( + input, err := os.ReadFile( fmt.Sprintf("testdata/json_documents/%d_unsorted.json", filePrefix, )) @@ -83,7 +83,7 @@ func testSortJSON(t *testing.T, filePrefix int) { var prettyPrintJSON bytes.Buffer err = json.Indent(&prettyPrintJSON, actualKV.Value, "", " ") require.NoError(t, err) - expected, err := ioutil.ReadFile( + expected, err := os.ReadFile( fmt.Sprintf("testdata/json_documents/%d_sorted.json", filePrefix, )) diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/redolog_test.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/redolog_test.go index c331d187da1..e2fcc438cd6 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/redolog_test.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/redolog_test.go @@ -8,7 +8,7 @@ package statecouchdb import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/davecgh/go-spew/spew" @@ -160,7 +160,7 @@ func redologTestSetup(t *testing.T) (p *redoLoggerProvider, cleanup func()) { } func TestReadExistingRedoRecord(t *testing.T) { - b, err := ioutil.ReadFile("testdata/persisted_redo_record") + b, err := os.ReadFile("testdata/persisted_redo_record") require.NoError(t, err) rec, err := decodeRedologVal(b) require.NoError(t, err) diff --git a/core/operations/operations_suite_test.go b/core/operations/operations_suite_test.go index 085b57dc18e..ffb8258c011 100644 --- a/core/operations/operations_suite_test.go +++ b/core/operations/operations_suite_test.go @@ -9,7 +9,6 @@ package operations_test import ( "crypto/tls" "crypto/x509" - "io/ioutil" "net/http" "os" "path/filepath" @@ -52,7 +51,7 @@ func generateCertificates(tempDir string) { func newHTTPClient(tlsDir string, withClientCert bool) *http.Client { clientCertPool := x509.NewCertPool() - caCert, err := ioutil.ReadFile(filepath.Join(tlsDir, "server-ca.pem")) + caCert, err := os.ReadFile(filepath.Join(tlsDir, "server-ca.pem")) Expect(err).NotTo(HaveOccurred()) clientCertPool.AppendCertsFromPEM(caCert) diff --git a/core/peer/config.go b/core/peer/config.go index f10b7a77b6f..61024bb2ac7 100644 --- a/core/peer/config.go +++ b/core/peer/config.go @@ -22,8 +22,8 @@ package peer import ( "crypto/tls" "fmt" - "io/ioutil" "net" + "os" "path/filepath" "runtime" "time" @@ -394,11 +394,11 @@ func GetServerConfig() (comm.ServerConfig, error) { } if serverConfig.SecOpts.UseTLS { // get the certs from the file system - serverKey, err := ioutil.ReadFile(config.GetPath("peer.tls.key.file")) + serverKey, err := os.ReadFile(config.GetPath("peer.tls.key.file")) if err != nil { return serverConfig, fmt.Errorf("error loading TLS key (%s)", err) } - serverCert, err := ioutil.ReadFile(config.GetPath("peer.tls.cert.file")) + serverCert, err := os.ReadFile(config.GetPath("peer.tls.cert.file")) if err != nil { return serverConfig, fmt.Errorf("error loading TLS certificate (%s)", err) } @@ -408,7 +408,7 @@ func GetServerConfig() (comm.ServerConfig, error) { if serverConfig.SecOpts.RequireClientCert { var clientRoots [][]byte for _, file := range viper.GetStringSlice("peer.tls.clientRootCAs.files") { - clientRoot, err := ioutil.ReadFile( + clientRoot, err := os.ReadFile( config.TranslatePath(filepath.Dir(viper.ConfigFileUsed()), file)) if err != nil { return serverConfig, @@ -420,7 +420,7 @@ func GetServerConfig() (comm.ServerConfig, error) { } // check for root cert if config.GetPath("peer.tls.rootcert.file") != "" { - rootCert, err := ioutil.ReadFile(config.GetPath("peer.tls.rootcert.file")) + rootCert, err := os.ReadFile(config.GetPath("peer.tls.rootcert.file")) if err != nil { return serverConfig, fmt.Errorf("error loading TLS root certificate (%s)", err) } @@ -492,12 +492,12 @@ func GetClientCertificate() (tls.Certificate, error) { } } // get the keypair from the file system - clientKey, err := ioutil.ReadFile(keyPath) + clientKey, err := os.ReadFile(keyPath) if err != nil { return cert, errors.WithMessage(err, "error loading client TLS key") } - clientCert, err := ioutil.ReadFile(certPath) + clientCert, err := os.ReadFile(certPath) if err != nil { return cert, errors.WithMessage(err, "error loading client TLS certificate") diff --git a/discovery/client/client_test.go b/discovery/client/client_test.go index 02f3dca458f..4fecd9cb574 100644 --- a/discovery/client/client_test.go +++ b/discovery/client/client_test.go @@ -11,8 +11,8 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "net" + "os" "path/filepath" "strconv" "testing" @@ -272,7 +272,7 @@ var ( ) func loadFileOrPanic(file string) []byte { - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { panic(err) } diff --git a/discovery/test/integration_test.go b/discovery/test/integration_test.go index 9b9c91c2ab5..a734a353574 100644 --- a/discovery/test/integration_test.go +++ b/discovery/test/integration_test.go @@ -810,7 +810,7 @@ func newPeer(dir, mspID string, org, id int) *testPeer { peerStr := fmt.Sprintf("peer%d.org%d.example.com", id, org) certFile := filepath.Join(dir, fmt.Sprintf("org%d.example.com", org), "peers", peerStr, "msp", "signcerts", fmt.Sprintf("%s-cert.pem", peerStr)) - certBytes, err := ioutil.ReadFile(certFile) + certBytes, err := os.ReadFile(certFile) if err != nil { panic(fmt.Sprintf("failed reading file %s: %v", certFile, err)) } @@ -942,7 +942,7 @@ func newSigner(msp, certPath, keyPath string) (*signer, error) { } func serializeIdentity(clientCert string, mspID string) ([]byte, error) { - b, err := ioutil.ReadFile(clientCert) + b, err := os.ReadFile(clientCert) if err != nil { return nil, errors.WithStack(err) } @@ -959,7 +959,7 @@ func (si *signer) Sign(msg []byte) ([]byte, error) { } func loadPrivateKey(file string) (*ecdsa.PrivateKey, error) { - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { return nil, errors.WithStack(err) } diff --git a/gossip/api/crypto_test.go b/gossip/api/crypto_test.go index 56f2a7a7ba9..b597b919030 100644 --- a/gossip/api/crypto_test.go +++ b/gossip/api/crypto_test.go @@ -8,7 +8,7 @@ package api import ( "encoding/pem" - "io/ioutil" + "os" "path/filepath" "testing" @@ -18,7 +18,7 @@ import ( ) func TestPeerIdentityTypeString(t *testing.T) { - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "peer.pem")) + certBytes, err := os.ReadFile(filepath.Join("testdata", "peer.pem")) require.NoError(t, err) for _, testCase := range []struct { diff --git a/integration/configtx/configtx_test.go b/integration/configtx/configtx_test.go index dab7cc3bfad..af24eae337b 100644 --- a/integration/configtx/configtx_test.go +++ b/integration/configtx/configtx_test.go @@ -243,7 +243,7 @@ var _ = Describe("ConfigTx", func() { // parsePrivateKey loads the PEM-encoded private key at the specified path. func parsePrivateKey(path string) crypto.PrivateKey { - pkBytes, err := ioutil.ReadFile(path) + pkBytes, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) pemBlock, _ := pem.Decode(pkBytes) privateKey, err := x509.ParsePKCS8PrivateKey(pemBlock.Bytes) @@ -254,7 +254,7 @@ func parsePrivateKey(path string) crypto.PrivateKey { // parseCertificate loads the PEM-encoded x509 certificate at the specified // path. func parseCertificate(path string) *x509.Certificate { - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) pemBlock, _ := pem.Decode(certBytes) cert, err := x509.ParseCertificate(pemBlock.Bytes) diff --git a/integration/e2e/e2e_test.go b/integration/e2e/e2e_test.go index b36e06ffc4d..06d7893d308 100644 --- a/integration/e2e/e2e_test.go +++ b/integration/e2e/e2e_test.go @@ -147,7 +147,7 @@ var _ = Describe("EndToEnd", func() { // Ensure that the temporary directories generated by launched external // chaincodes have been cleaned up. This must be done after the peers // have been terminated. - contents, err := ioutil.ReadFile(runArtifactsFilePath) + contents, err := os.ReadFile(runArtifactsFilePath) Expect(err).NotTo(HaveOccurred()) scanner := bufio.NewScanner(bytes.NewBuffer(contents)) for scanner.Scan() { @@ -220,7 +220,7 @@ var _ = Describe("EndToEnd", func() { nwo.DeployChaincode(network, "testchannel", orderer, chaincode) By("ensuring external cc run artifacts exist after deploying") - contents, err := ioutil.ReadFile(runArtifactsFilePath) + contents, err := os.ReadFile(runArtifactsFilePath) Expect(err).NotTo(HaveOccurred()) scanner := bufio.NewScanner(bytes.NewBuffer(contents)) for scanner.Scan() { diff --git a/integration/gateway/gateway_discovery_test.go b/integration/gateway/gateway_discovery_test.go index 17229f163f4..075012e50f5 100644 --- a/integration/gateway/gateway_discovery_test.go +++ b/integration/gateway/gateway_discovery_test.go @@ -40,7 +40,7 @@ var _ = Describe("GatewayService with endorser discovery", func() { ) loadPeerCert := func(peer *nwo.Peer) string { - peerCert, err := ioutil.ReadFile(network.PeerCert(peer)) + peerCert, err := os.ReadFile(network.PeerCert(peer)) Expect(err).NotTo(HaveOccurred()) return string(peerCert) } diff --git a/integration/ledger/snapshot_test.go b/integration/ledger/snapshot_test.go index 4c20a7752af..f5b3bb9339a 100644 --- a/integration/ledger/snapshot_test.go +++ b/integration/ledger/snapshot_test.go @@ -760,9 +760,9 @@ func compareSnapshotMetadata(snapshotDir1, snapshotDir2 string) { // compare metadata files for _, file := range []string{"_snapshot_signable_metadata.json", "_snapshot_additional_metadata.json"} { By("comparing metadata file from snapshots on multiple peers: " + file) - fileContent1, err := ioutil.ReadFile(filepath.Join(snapshotDir1, file)) + fileContent1, err := os.ReadFile(filepath.Join(snapshotDir1, file)) Expect(err).NotTo(HaveOccurred()) - fileContent2, err := ioutil.ReadFile(filepath.Join(snapshotDir2, file)) + fileContent2, err := os.ReadFile(filepath.Join(snapshotDir2, file)) Expect(err).NotTo(HaveOccurred()) Expect(fileContent1).To(Equal(fileContent2)) } diff --git a/integration/lifecycle/lifecycle_test.go b/integration/lifecycle/lifecycle_test.go index 870dce4101b..cb222847434 100644 --- a/integration/lifecycle/lifecycle_test.go +++ b/integration/lifecycle/lifecycle_test.go @@ -157,9 +157,9 @@ var _ = Describe("Lifecycle", func() { }) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) - fileBytes, err := ioutil.ReadFile(chaincode.PackageFile) + fileBytes, err := os.ReadFile(chaincode.PackageFile) Expect(err).NotTo(HaveOccurred()) - fileBytesFromPeer, err := ioutil.ReadFile(filepath.Join(network.RootDir, chaincode.PackageID+".tar.gz")) + fileBytesFromPeer, err := os.ReadFile(filepath.Join(network.RootDir, chaincode.PackageID+".tar.gz")) Expect(err).NotTo(HaveOccurred()) Expect(fileBytesFromPeer).To(Equal(fileBytes)) diff --git a/integration/msp/rsaca_test.go b/integration/msp/rsaca_test.go index 48f4d81820d..93f1153139b 100644 --- a/integration/msp/rsaca_test.go +++ b/integration/msp/rsaca_test.go @@ -206,7 +206,7 @@ func createMSP(baseDir, domain string, nodeOUs bool) (signCA *CA, tlsCA *CA, adm } writeLocalMSP(adminDir, adminUsername, ous, nil, signCA, tlsCA, nil, nodeOUs, true) - adminPemCert, err = ioutil.ReadFile(filepath.Join(adminDir, "msp", "signcerts", certFilename(adminUsername))) + adminPemCert, err = os.ReadFile(filepath.Join(adminDir, "msp", "signcerts", certFilename(adminUsername))) Expect(err).NotTo(HaveOccurred()) err = os.WriteFile(filepath.Join(adminDir, "msp", "admincerts", certFilename(adminUsername)), adminPemCert, 0o644) Expect(err).NotTo(HaveOccurred()) diff --git a/integration/nwo/configblock.go b/integration/nwo/configblock.go index 66a93a01678..e02dfaad740 100644 --- a/integration/nwo/configblock.go +++ b/integration/nwo/configblock.go @@ -273,7 +273,7 @@ func ComputeUpdateOrdererConfig(updateFile string, n *Network, channel string, c // UnmarshalBlockFromFile unmarshals a proto encoded block from a file. func UnmarshalBlockFromFile(blockFile string) *common.Block { - blockBytes, err := ioutil.ReadFile(blockFile) + blockBytes, err := os.ReadFile(blockFile) Expect(err).NotTo(HaveOccurred()) block, err := protoutil.UnmarshalBlock(blockBytes) diff --git a/integration/nwo/deploy.go b/integration/nwo/deploy.go index d9a57ef40ca..4df2d453184 100644 --- a/integration/nwo/deploy.go +++ b/integration/nwo/deploy.go @@ -49,7 +49,7 @@ type Chaincode struct { } func (c *Chaincode) SetPackageIDFromPackageFile() { - fileBytes, err := ioutil.ReadFile(c.PackageFile) + fileBytes, err := os.ReadFile(c.PackageFile) Expect(err).NotTo(HaveOccurred()) hashStr := fmt.Sprintf("%x", util.ComputeSHA256(fileBytes)) c.PackageID = c.Label + ":" + hashStr diff --git a/integration/nwo/network.go b/integration/nwo/network.go index 8c7a13aef86..bc10abfc74c 100644 --- a/integration/nwo/network.go +++ b/integration/nwo/network.go @@ -315,7 +315,7 @@ func (n *Network) OrdererConfigPath(o *Orderer) string { // object approximating its contents. func (n *Network) ReadOrdererConfig(o *Orderer) *fabricconfig.Orderer { var orderer fabricconfig.Orderer - ordererBytes, err := ioutil.ReadFile(n.OrdererConfigPath(o)) + ordererBytes, err := os.ReadFile(n.OrdererConfigPath(o)) Expect(err).NotTo(HaveOccurred()) err = yaml.Unmarshal(ordererBytes, &orderer) @@ -342,7 +342,7 @@ func (n *Network) WriteOrdererConfig(o *Orderer, config *fabricconfig.Orderer) { // object approximating its contents. func (n *Network) ReadConfigTxConfig() *fabricconfig.ConfigTx { var configtx fabricconfig.ConfigTx - configtxBytes, err := ioutil.ReadFile(n.ConfigTxConfigPath()) + configtxBytes, err := os.ReadFile(n.ConfigTxConfigPath()) Expect(err).NotTo(HaveOccurred()) err = yaml.Unmarshal(configtxBytes, &configtx) @@ -381,7 +381,7 @@ func (n *Network) PeerLedgerDir(p *Peer) string { // approximating its contents. func (n *Network) ReadPeerConfig(p *Peer) *fabricconfig.Core { var core fabricconfig.Core - coreBytes, err := ioutil.ReadFile(n.PeerConfigPath(p)) + coreBytes, err := os.ReadFile(n.PeerConfigPath(p)) Expect(err).NotTo(HaveOccurred()) err = yaml.Unmarshal(coreBytes, &core) @@ -902,7 +902,7 @@ func (n *Network) bootstrapIdemix() { func (n *Network) ConcatenateTLSCACertificates() { bundle := &bytes.Buffer{} for _, tlsCertPath := range n.listTLSCACertificates() { - certBytes, err := ioutil.ReadFile(tlsCertPath) + certBytes, err := os.ReadFile(tlsCertPath) Expect(err).NotTo(HaveOccurred()) bundle.Write(certBytes) } @@ -1075,7 +1075,7 @@ func (n *Network) VerifyMembership(expectedPeers []*Peer, channel string, chainc } func (n *Network) discoveredPeerMatcher(p *Peer, chaincodes ...string) types.GomegaMatcher { - peerCert, err := ioutil.ReadFile(n.PeerCert(p)) + peerCert, err := os.ReadFile(n.PeerCert(p)) Expect(err).NotTo(HaveOccurred()) var ccs []interface{} @@ -1491,7 +1491,7 @@ func (n *Network) Peer(orgName, peerName string) *Peer { // DiscoveredPeer creates a new DiscoveredPeer from the peer and chaincodes // passed as arguments. func (n *Network) DiscoveredPeer(p *Peer, chaincodes ...string) DiscoveredPeer { - peerCert, err := ioutil.ReadFile(n.PeerCert(p)) + peerCert, err := os.ReadFile(n.PeerCert(p)) Expect(err).NotTo(HaveOccurred()) return DiscoveredPeer{ @@ -1895,7 +1895,7 @@ func (n *Network) GenerateCoreConfig(p *Peer) { func (n *Network) LoadAppChannelGenesisBlock(channelID string) *common.Block { appGenesisPath := n.OutputBlockPath(channelID) - appGenesisBytes, err := ioutil.ReadFile(appGenesisPath) + appGenesisBytes, err := os.ReadFile(appGenesisPath) Expect(err).NotTo(HaveOccurred()) appGenesisBlock, err := protoutil.UnmarshalBlock(appGenesisBytes) Expect(err).NotTo(HaveOccurred()) diff --git a/integration/nwo/operational_client.go b/integration/nwo/operational_client.go index 66c66f2a531..793445b0c4d 100644 --- a/integration/nwo/operational_client.go +++ b/integration/nwo/operational_client.go @@ -9,8 +9,8 @@ package nwo import ( "crypto/tls" "crypto/x509" - "io/ioutil" "net/http" + "os" "path/filepath" "time" @@ -38,7 +38,7 @@ func operationalClients(n *Network, tlsDir string) (authClient, unauthClient *ht Expect(err).NotTo(HaveOccurred()) clientCertPool := x509.NewCertPool() - caCert, err := ioutil.ReadFile(filepath.Join(tlsDir, "ca.crt")) + caCert, err := os.ReadFile(filepath.Join(tlsDir, "ca.crt")) Expect(err).NotTo(HaveOccurred()) clientCertPool.AppendCertsFromPEM(caCert) diff --git a/integration/nwo/signingid.go b/integration/nwo/signingid.go index 3c396d218a7..9d2f68fbf46 100644 --- a/integration/nwo/signingid.go +++ b/integration/nwo/signingid.go @@ -13,7 +13,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" + "os" "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric-protos-go/msp" @@ -29,7 +29,7 @@ type SigningIdentity struct { // Serialize returns the probobuf encoding of an msp.SerializedIdenity. func (s *SigningIdentity) Serialize() ([]byte, error) { - cert, err := ioutil.ReadFile(s.CertPath) + cert, err := os.ReadFile(s.CertPath) if err != nil { return nil, err } @@ -43,7 +43,7 @@ func (s *SigningIdentity) Serialize() ([]byte, error) { // key, and returns the signature after low-S normlization. func (s *SigningIdentity) Sign(msg []byte) ([]byte, error) { digest := sha256.Sum256(msg) - pemKey, err := ioutil.ReadFile(s.KeyPath) + pemKey, err := os.ReadFile(s.KeyPath) if err != nil { return nil, err } diff --git a/integration/pkcs11/pkcs11_test.go b/integration/pkcs11/pkcs11_test.go index a87c8cf0b99..7e46e8e4b56 100644 --- a/integration/pkcs11/pkcs11_test.go +++ b/integration/pkcs11/pkcs11_test.go @@ -192,7 +192,7 @@ func configurePeerPKCS11(ctx *pkcs11.Ctx, sess pkcs11.SessionHandle, network *nw // Retrieves org CA cert orgCAPath := network.PeerOrgCADir(network.Organization(orgName)) - caBytes, err := ioutil.ReadFile(filepath.Join(orgCAPath, fmt.Sprintf("ca.%s-cert.pem", domain))) + caBytes, err := os.ReadFile(filepath.Join(orgCAPath, fmt.Sprintf("ca.%s-cert.pem", domain))) Expect(err).NotTo(HaveOccurred()) By("Updating the peer signcerts") @@ -224,7 +224,7 @@ func configureOrdererPKCS11(ctx *pkcs11.Ctx, sess pkcs11.SessionHandle, network // Retrieves org CA cert orgCAPath := network.OrdererOrgCADir(network.Organization(orgName)) - caBytes, err := ioutil.ReadFile(filepath.Join(orgCAPath, fmt.Sprintf("ca.%s-cert.pem", domain))) + caBytes, err := os.ReadFile(filepath.Join(orgCAPath, fmt.Sprintf("ca.%s-cert.pem", domain))) Expect(err).NotTo(HaveOccurred()) By("Updating the orderer signcerts") @@ -317,7 +317,7 @@ func buildCert(caBytes []byte, org1CAPath string, csr *x509.CertificateRequest, caCert, err := x509.ParseCertificate(pemBlock.Bytes) Expect(err).NotTo(HaveOccurred()) - keyBytes, err := ioutil.ReadFile(filepath.Join(org1CAPath, "priv_sk")) + keyBytes, err := os.ReadFile(filepath.Join(org1CAPath, "priv_sk")) Expect(err).NotTo(HaveOccurred()) pemBlock, _ = pem.Decode(keyBytes) diff --git a/integration/raft/cft_test.go b/integration/raft/cft_test.go index 164b307a937..efe8d11940e 100644 --- a/integration/raft/cft_test.go +++ b/integration/raft/cft_test.go @@ -286,7 +286,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { extendNetwork(network) ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(o4), "server.crt") - ordererCert, err := ioutil.ReadFile(ordererCertificatePath) + ordererCert, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) By("Adding new ordering service node") @@ -319,7 +319,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { By("Pick ordering service node to be evicted") victimIdx := FindLeader(ordererRunners) - 1 victim := orderers[victimIdx] - victimCertBytes, err := ioutil.ReadFile(filepath.Join(network.OrdererLocalTLSDir(victim), "server.crt")) + victimCertBytes, err := os.ReadFile(filepath.Join(network.OrdererLocalTLSDir(victim), "server.crt")) Expect(err).NotTo(HaveOccurred()) assertBlockReception(map[string]int{ @@ -572,18 +572,18 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { ordererTLSCAKeyPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "tlsca", "priv_sk") - ordererTLSCAKey, err := ioutil.ReadFile(ordererTLSCAKeyPath) + ordererTLSCAKey, err := os.ReadFile(ordererTLSCAKeyPath) Expect(err).NotTo(HaveOccurred()) ordererTLSCACertPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "tlsca", fmt.Sprintf("tlsca.%s-cert.pem", ordererDomain)) - ordererTLSCACert, err := ioutil.ReadFile(ordererTLSCACertPath) + ordererTLSCACert, err := os.ReadFile(ordererTLSCACertPath) Expect(err).NotTo(HaveOccurred()) serverTLSCerts := make(map[string][]byte) for _, orderer := range []*nwo.Orderer{o1, o2, o3} { tlsCertPath := filepath.Join(network.OrdererLocalTLSDir(orderer), "server.crt") - serverTLSCerts[tlsCertPath], err = ioutil.ReadFile(tlsCertPath) + serverTLSCerts[tlsCertPath], err = os.ReadFile(tlsCertPath) Expect(err).NotTo(HaveOccurred()) } @@ -904,16 +904,16 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { ordererDomain := network.Organization(orderer.Organization).Domain ordererCAKeyPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "ca", "priv_sk") - ordererCAKey, err := ioutil.ReadFile(ordererCAKeyPath) + ordererCAKey, err := os.ReadFile(ordererCAKeyPath) Expect(err).NotTo(HaveOccurred()) ordererCACertPath := network.OrdererCACert(orderer) - ordererCACert, err := ioutil.ReadFile(ordererCACertPath) + ordererCACert, err := os.ReadFile(ordererCACertPath) Expect(err).NotTo(HaveOccurred()) adminCertPath := network.OrdererUserCert(orderer, "Admin") - originalAdminCert, err := ioutil.ReadFile(adminCertPath) + originalAdminCert, err := os.ReadFile(adminCertPath) Expect(err).NotTo(HaveOccurred()) expiredAdminCert, earlyCACert := expireCertificate(originalAdminCert, ordererCACert, ordererCAKey, time.Now()) @@ -951,7 +951,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { By("Creating config update that adds another orderer admin") bootBlockPath := filepath.Join(network.RootDir, fmt.Sprintf("%s_block.pb", "testchannel")) - bootBlock, err := ioutil.ReadFile(bootBlockPath) + bootBlock, err := os.ReadFile(bootBlockPath) Expect(err).NotTo(HaveOccurred()) current := configFromBootstrapBlock(bootBlock) @@ -964,7 +964,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { defer os.RemoveAll(tempDir) nwo.ComputeUpdateOrdererConfig(configBlockFile, network, "testchannel", current, updatedConfig, peer) - updateTransaction, err := ioutil.ReadFile(configBlockFile) + updateTransaction, err := os.ReadFile(configBlockFile) Expect(err).NotTo(HaveOccurred()) By("Creating config update") @@ -1027,18 +1027,18 @@ func renewOrdererCertificates(network *nwo.Network, orderers ...*nwo.Orderer) { ordererTLSCAKeyPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "tlsca", "priv_sk") - ordererTLSCAKey, err := ioutil.ReadFile(ordererTLSCAKeyPath) + ordererTLSCAKey, err := os.ReadFile(ordererTLSCAKeyPath) Expect(err).NotTo(HaveOccurred()) ordererTLSCACertPath := filepath.Join(network.RootDir, "crypto", "ordererOrganizations", ordererDomain, "tlsca", fmt.Sprintf("tlsca.%s-cert.pem", ordererDomain)) - ordererTLSCACert, err := ioutil.ReadFile(ordererTLSCACertPath) + ordererTLSCACert, err := os.ReadFile(ordererTLSCACertPath) Expect(err).NotTo(HaveOccurred()) serverTLSCerts := map[string][]byte{} for _, orderer := range orderers { tlsCertPath := filepath.Join(network.OrdererLocalTLSDir(orderer), "server.crt") - serverTLSCerts[tlsCertPath], err = ioutil.ReadFile(tlsCertPath) + serverTLSCerts[tlsCertPath], err = os.ReadFile(tlsCertPath) Expect(err).NotTo(HaveOccurred()) } diff --git a/integration/raft/channel_participation_test.go b/integration/raft/channel_participation_test.go index 9bbf482a2fe..a770c6e41d4 100644 --- a/integration/raft/channel_participation_test.go +++ b/integration/raft/channel_participation_test.go @@ -822,7 +822,7 @@ func applicationChannelGenesisBlock(n *nwo.Network, orderers []*nwo.Orderer, pee // parseCertificate loads the PEM-encoded x509 certificate at the specified // path. func parseCertificate(path string) *x509.Certificate { - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) pemBlock, _ := pem.Decode(certBytes) cert, err := x509.ParseCertificate(pemBlock.Bytes) @@ -832,7 +832,7 @@ func parseCertificate(path string) *x509.Certificate { // parsePrivateKey loads the PEM-encoded private key at the specified path. func parsePrivateKey(path string) crypto.PrivateKey { - pkBytes, err := ioutil.ReadFile(path) + pkBytes, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) pemBlock, _ := pem.Decode(pkBytes) privateKey, err := x509.ParsePKCS8PrivateKey(pemBlock.Bytes) diff --git a/integration/raft/config_test.go b/integration/raft/config_test.go index 553eccc05d7..2c67800779e 100644 --- a/integration/raft/config_test.go +++ b/integration/raft/config_test.go @@ -292,7 +292,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { extendNetwork(network) secondOrdererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(orderer2), "server.crt") - secondOrdererCertificate, err := ioutil.ReadFile(secondOrdererCertificatePath) + secondOrdererCertificate, err := os.ReadFile(secondOrdererCertificatePath) Expect(err).NotTo(HaveOccurred()) By("Adding the second orderer") @@ -362,11 +362,11 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { caCertPath := filepath.Join(tmpDir, "ordererOrganizations", domain, "tlsca", fmt.Sprintf("tlsca.%s-cert.pem", domain)) - caCert, err := ioutil.ReadFile(caCertPath) + caCert, err := os.ReadFile(caCertPath) Expect(err).NotTo(HaveOccurred()) thirdOrdererCertificatePath := filepath.Join(ordererTLSPath, "server.crt") - thirdOrdererCertificate, err := ioutil.ReadFile(thirdOrdererCertificatePath) + thirdOrdererCertificate, err := os.ReadFile(thirdOrdererCertificatePath) Expect(err).NotTo(HaveOccurred()) By("Updating it on the file system") @@ -379,7 +379,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { for _, fileName := range []string{"server.crt", "server.key", "ca.crt"} { dst := filepath.Join(network.OrdererLocalTLSDir(orderer3), fileName) - data, err := ioutil.ReadFile(filepath.Join(ordererTLSPath, fileName)) + data, err := os.ReadFile(filepath.Join(ordererTLSPath, fileName)) Expect(err).NotTo(HaveOccurred()) err = os.WriteFile(dst, data, 0o644) @@ -797,7 +797,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Adding orderer4 to the channel") orderer4CertificatePath := filepath.Join(network.OrdererLocalTLSDir(o4), "server.crt") - orderer4Certificate, err := ioutil.ReadFile(orderer4CertificatePath) + orderer4Certificate, err := os.ReadFile(orderer4CertificatePath) Expect(err).NotTo(HaveOccurred()) addConsenter(network, peer, o1, "testchannel", etcdraft.Consenter{ @@ -992,7 +992,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Adding orderer2 to mychannel") ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(o2), "server.crt") - ordererCertificate, err := ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) addConsenter(network, peer, o1, "mychannel", etcdraft.Consenter{ @@ -1020,7 +1020,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Adding orderer3 to the channel") ordererCertificatePath = filepath.Join(network.OrdererLocalTLSDir(o3), "server.crt") - ordererCertificate, err = ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err = os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) addConsenter(network, peer, o1, "mychannel", etcdraft.Consenter{ ServerTlsCert: ordererCertificate, @@ -1157,7 +1157,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { firstEvictedNode := FindLeader(ordererRunners) - 1 By("Removing the leader from 3-node channel") - server1CertBytes, err := ioutil.ReadFile(filepath.Join(network.OrdererLocalTLSDir(orderers[firstEvictedNode]), "server.crt")) + server1CertBytes, err := os.ReadFile(filepath.Join(network.OrdererLocalTLSDir(orderers[firstEvictedNode]), "server.crt")) Expect(err).To(Not(HaveOccurred())) ordererEvicted1st := network.Orderers[(firstEvictedNode+1)%3] @@ -1210,7 +1210,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Eventually(assertFollower(expectedInfo, orderers[firstEvictedNode]), network.EventuallyTimeout, 100*time.Millisecond).Should(BeTrue()) By("Removing the leader from 2-node channel") - server2CertBytes, err := ioutil.ReadFile(filepath.Join(network.OrdererLocalTLSDir(orderers[secondEvictedNode]), "server.crt")) + server2CertBytes, err := os.ReadFile(filepath.Join(network.OrdererLocalTLSDir(orderers[secondEvictedNode]), "server.crt")) Expect(err).To(Not(HaveOccurred())) removeConsenter(network, peer, orderers[survivor], "testchannel", server2CertBytes) @@ -1284,7 +1284,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Eventually(o2Runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Current active nodes in cluster are: \\[2 3\\]")) By("Removing the first orderer from the application channel") - server1CertBytes, err := ioutil.ReadFile(filepath.Join(network.OrdererLocalTLSDir(o1), "server.crt")) + server1CertBytes, err := os.ReadFile(filepath.Join(network.OrdererLocalTLSDir(o1), "server.crt")) Expect(err).To(Not(HaveOccurred())) removeConsenter(network, peer, o2, "testchannel", server1CertBytes) @@ -1408,7 +1408,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { }, []*nwo.Orderer{o2, o3}, peer, network) By("Removing the first orderer from an application channel") - o1cert, err := ioutil.ReadFile(path.Join(network.OrdererLocalTLSDir(o1), "server.crt")) + o1cert, err := os.ReadFile(path.Join(network.OrdererLocalTLSDir(o1), "server.crt")) Expect(err).ToNot(HaveOccurred()) removeConsenter(network, peer, o2, "testchannel", o1cert) @@ -1544,7 +1544,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { for _, i := range []int{4, 5, 6} { By(fmt.Sprintf("Adding orderer%d", i+1)) ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(orderers[i]), "server.crt") - ordererCertificate, err := ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) addConsenter(network, peer, orderers[0], "testchannel", etcdraft.Consenter{ @@ -1872,10 +1872,10 @@ func refreshOrdererPEMs(n *nwo.Network) []*certificateChange { // Overwrite the destination files with the contents of the source files. for _, certChange := range fileChanges { - previousCertBytes, err := ioutil.ReadFile(certChange.dstFile) + previousCertBytes, err := os.ReadFile(certChange.dstFile) Expect(err).NotTo(HaveOccurred()) - newCertBytes, err := ioutil.ReadFile(certChange.srcFile) + newCertBytes, err := os.ReadFile(certChange.srcFile) Expect(err).NotTo(HaveOccurred()) err = os.WriteFile(certChange.dstFile, newCertBytes, 0o644) @@ -1886,7 +1886,7 @@ func refreshOrdererPEMs(n *nwo.Network) []*certificateChange { } // Read the previous key file - previousKeyBytes, err := ioutil.ReadFile(strings.Replace(certChange.dstFile, "server.crt", "server.key", -1)) + previousKeyBytes, err := os.ReadFile(strings.Replace(certChange.dstFile, "server.crt", "server.key", -1)) Expect(err).NotTo(HaveOccurred()) serverCertChanges = append(serverCertChanges, certChange) diff --git a/integration/raft/migration_test.go b/integration/raft/migration_test.go index 16d7714cb67..74ee9e56c90 100644 --- a/integration/raft/migration_test.go +++ b/integration/raft/migration_test.go @@ -395,7 +395,7 @@ var _ = Describe("ConsensusTypeMigration", func() { extendNetwork(network) secondOrdererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(orderer2), "server.crt") - secondOrdererCertificate, err := ioutil.ReadFile(secondOrdererCertificatePath) + secondOrdererCertificate, err := os.ReadFile(secondOrdererCertificatePath) Expect(err).NotTo(HaveOccurred()) By("10) Adding the second orderer to second channel") diff --git a/integration/smartbft/smartbft_test.go b/integration/smartbft/smartbft_test.go index f8fd012a2bf..d99e5929feb 100644 --- a/integration/smartbft/smartbft_test.go +++ b/integration/smartbft/smartbft_test.go @@ -277,10 +277,10 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(orderer5), "server.crt") - ordererCertificate, err := ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) - ordererIdentity, err := ioutil.ReadFile(network.OrdererCert(orderer5)) + ordererIdentity, err := os.ReadFile(network.OrdererCert(orderer5)) Expect(err).NotTo(HaveOccurred()) nwo.UpdateConsenters(network, peer, orderer, channel, func(orderers *common.Orderers) { @@ -810,10 +810,10 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(newOrderer), "server.crt") - ordererCertificate, err := ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) - ordererIdentity, err := ioutil.ReadFile(network.OrdererCert(newOrderer)) + ordererIdentity, err := os.ReadFile(network.OrdererCert(newOrderer)) Expect(err).NotTo(HaveOccurred()) By(fmt.Sprintf("Adding consenter with certificate %s", string(ordererIdentity))) @@ -1033,10 +1033,10 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) ordererCertificatePath := filepath.Join(network.OrdererLocalTLSDir(orderer5), "server.crt") - ordererCertificate, err := ioutil.ReadFile(ordererCertificatePath) + ordererCertificate, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) - ordererIdentity, err := ioutil.ReadFile(network.OrdererCert(orderer5)) + ordererIdentity, err := os.ReadFile(network.OrdererCert(orderer5)) Expect(err).NotTo(HaveOccurred()) nwo.UpdateConsenters(network, peer, network.Orderers[0], channel, func(orderers *common.Orderers) { @@ -1389,7 +1389,7 @@ func ordererOrganizationsAndConsenters(n *nwo.Network, orderers []*nwo.Orderer) // parseCertificate loads the PEM-encoded x509 certificate at the specified // path. func parseCertificate(path string) *x509.Certificate { - certBytes, err := ioutil.ReadFile(path) + certBytes, err := os.ReadFile(path) Expect(err).NotTo(HaveOccurred()) pemBlock, _ := pem.Decode(certBytes) cert, err := x509.ParseCertificate(pemBlock.Bytes) diff --git a/internal/cryptogen/msp/msp_test.go b/internal/cryptogen/msp/msp_test.go index b84f125fc8e..0d5fd43b2c0 100644 --- a/internal/cryptogen/msp/msp_test.go +++ b/internal/cryptogen/msp/msp_test.go @@ -6,7 +6,6 @@ SPDX-License-Identifier: Apache-2.0 package msp_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -189,7 +188,7 @@ func TestExportConfig(t *testing.T) { err = msp.ExportConfig(path, caFile, true) require.NoError(t, err) - configBytes, err := ioutil.ReadFile(configFile) + configBytes, err := os.ReadFile(configFile) if err != nil { t.Fatalf("failed to read config file: [%s]", err) } diff --git a/internal/fileutil/fileutil_test.go b/internal/fileutil/fileutil_test.go index 977f99bf39a..459800a54d2 100644 --- a/internal/fileutil/fileutil_test.go +++ b/internal/fileutil/fileutil_test.go @@ -8,7 +8,6 @@ package fileutil import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -218,7 +217,7 @@ func TestCreateAndSyncFileAtomically(t *testing.T) { err := CreateAndSyncFileAtomically(testPath, "tmpFile", "finalFile", content, 0o644) require.NoError(t, err) require.NoFileExists(t, filepath.Join(testPath, "tmpFile")) - contentRetrieved, err := ioutil.ReadFile(filepath.Join(testPath, "finalFile")) + contentRetrieved, err := os.ReadFile(filepath.Join(testPath, "finalFile")) require.NoError(t, err) require.Equal(t, content, contentRetrieved) }) @@ -253,7 +252,7 @@ func TestCreateAndSyncFileAtomically(t *testing.T) { require.NoError(t, err) err = CreateAndSyncFileAtomically(testPath, "tmpFile", "finalFile", content, 0o644) require.NoError(t, err) - contentRetrieved, err := ioutil.ReadFile(filepath.Join(testPath, "finalFile")) + contentRetrieved, err := os.ReadFile(filepath.Join(testPath, "finalFile")) require.NoError(t, err) require.Equal(t, content, contentRetrieved) }) diff --git a/internal/ledgerutil/compare/compare_test.go b/internal/ledgerutil/compare/compare_test.go index dfad376a469..b714724d432 100644 --- a/internal/ledgerutil/compare/compare_test.go +++ b/internal/ledgerutil/compare/compare_test.go @@ -12,6 +12,7 @@ import ( "fmt" "hash" "io/ioutil" + "os" "path/filepath" "testing" @@ -840,7 +841,7 @@ func TestJSONArrayFileWriter(t *testing.T) { require.NoError(t, err) // Read results of output and compare - resBytes, err := ioutil.ReadFile(filepath.Join(resultDir, "result.json")) + resBytes, err := os.ReadFile(filepath.Join(resultDir, "result.json")) require.NoError(t, err) res, err := ioutil.ReadAll(bytes.NewReader(resBytes)) require.NoError(t, err) diff --git a/internal/peer/chaincode/package_test.go b/internal/peer/chaincode/package_test.go index d74ae6ff308..75da11a8bee 100644 --- a/internal/peer/chaincode/package_test.go +++ b/internal/peer/chaincode/package_test.go @@ -8,7 +8,6 @@ package chaincode import ( "fmt" - "io/ioutil" "os" "testing" @@ -67,7 +66,7 @@ func TestCDSPackage(t *testing.T) { t.Fatalf("Run chaincode package cmd error:%v", err) } - b, err := ioutil.ReadFile(ccpackfile) + b, err := os.ReadFile(ccpackfile) if err != nil { t.Fatalf("package file %s not created", ccpackfile) } @@ -121,7 +120,7 @@ func TestSignedCDSPackage(t *testing.T) { t.Fatalf("could not create signed cds package %s", err) } - b, err := ioutil.ReadFile(ccpackfile) + b, err := os.ReadFile(ccpackfile) if err != nil { t.Fatalf("package file %s not created", ccpackfile) } @@ -153,7 +152,7 @@ func TestSignedCDSPackageWithSignature(t *testing.T) { t.Fatalf("could not create signed cds package %s", err) } - b, err := ioutil.ReadFile(ccpackfile) + b, err := os.ReadFile(ccpackfile) if err != nil { t.Fatalf("package file %s not created", ccpackfile) } diff --git a/internal/peer/chaincode/signpackage_test.go b/internal/peer/chaincode/signpackage_test.go index 87cd15dc405..dd2de3370df 100644 --- a/internal/peer/chaincode/signpackage_test.go +++ b/internal/peer/chaincode/signpackage_test.go @@ -8,7 +8,7 @@ package chaincode import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/golang/protobuf/proto" @@ -55,7 +55,7 @@ func TestSignExistingPackage(t *testing.T) { t.Fatalf("error creating signed :%v", err) } - b, err := ioutil.ReadFile(ccpackfile) + b, err := os.ReadFile(ccpackfile) if err != nil { t.Fatalf("package file %s not created", ccpackfile) } @@ -72,7 +72,7 @@ func TestSignExistingPackage(t *testing.T) { t.Fatalf("could not sign envelope") } - b, err = ioutil.ReadFile(signedfile) + b, err = os.ReadFile(signedfile) if err != nil { t.Fatalf("signed package file %s not created", signedfile) } @@ -112,7 +112,7 @@ func TestFailSignUnsignedPackage(t *testing.T) { t.Fatalf("error creating signed :%v", err) } - b, err := ioutil.ReadFile(ccpackfile) + b, err := os.ReadFile(ccpackfile) if err != nil { t.Fatalf("package file %s not created", ccpackfile) } diff --git a/internal/peer/lifecycle/chaincode/calculatepackageid_test.go b/internal/peer/lifecycle/chaincode/calculatepackageid_test.go index 203b9c967ff..8bc864b9f54 100644 --- a/internal/peer/lifecycle/chaincode/calculatepackageid_test.go +++ b/internal/peer/lifecycle/chaincode/calculatepackageid_test.go @@ -9,7 +9,7 @@ package chaincode_test import ( "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/hyperledger/fabric/internal/peer/lifecycle/chaincode" "github.com/hyperledger/fabric/internal/peer/lifecycle/chaincode/mock" @@ -35,7 +35,7 @@ var _ = Describe("CalculatePackageID", func() { } mockReader = &mock.Reader{} - data, err := ioutil.ReadFile("testdata/good-package.tar.gz") + data, err := os.ReadFile("testdata/good-package.tar.gz") Expect(err).NotTo(HaveOccurred()) mockReader.ReadFileReturns(data, nil) @@ -78,7 +78,7 @@ var _ = Describe("CalculatePackageID", func() { Context("when the package file cannot be parsed", func() { BeforeEach(func() { - data, err := ioutil.ReadFile("testdata/unparsed-package.tar.gz") + data, err := os.ReadFile("testdata/unparsed-package.tar.gz") Expect(err).NotTo(HaveOccurred()) mockReader.ReadFileReturns(data, nil) }) diff --git a/internal/pkg/comm/config_test.go b/internal/pkg/comm/config_test.go index 3b37e4ffcdc..12dd62a4287 100644 --- a/internal/pkg/comm/config_test.go +++ b/internal/pkg/comm/config_test.go @@ -9,7 +9,7 @@ package comm import ( "crypto/tls" "crypto/x509" - "io/ioutil" + "os" "path/filepath" "testing" "time" @@ -319,15 +319,15 @@ func LoadTestCerts(t *testing.T) TestCerts { var certs TestCerts var err error - certs.CAPEM, err = ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) + certs.CAPEM, err = os.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) if err != nil { t.Fatalf("unexpected error reading root cert for test: %v", err) } - certs.CertPEM, err = ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-client1-cert.pem")) + certs.CertPEM, err = os.ReadFile(filepath.Join("testdata", "certs", "Org1-client1-cert.pem")) if err != nil { t.Fatalf("unexpected error reading cert for test: %v", err) } - certs.KeyPEM, err = ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-client1-key.pem")) + certs.KeyPEM, err = os.ReadFile(filepath.Join("testdata", "certs", "Org1-client1-key.pem")) if err != nil { t.Fatalf("unexpected error reading key for test: %v", err) } diff --git a/internal/pkg/comm/connection_test.go b/internal/pkg/comm/connection_test.go index 238944e9cae..b93e2d44a88 100644 --- a/internal/pkg/comm/connection_test.go +++ b/internal/pkg/comm/connection_test.go @@ -9,7 +9,7 @@ package comm import ( "crypto/tls" "fmt" - "io/ioutil" + "os" "path/filepath" "testing" @@ -42,13 +42,13 @@ VQQLDAtIeXBlcmxlZGdlcjESMBAGA1UEAwwJbG9jYWxob3N0MFkwEwYHKoZIzj0C func loadRootCAs() [][]byte { rootCAs := [][]byte{} for i := 1; i <= numOrgs; i++ { - root, err := ioutil.ReadFile(fmt.Sprintf(orgCACert, i)) + root, err := os.ReadFile(fmt.Sprintf(orgCACert, i)) if err != nil { return [][]byte{} } rootCAs = append(rootCAs, root) for j := 1; j <= numChildOrgs; j++ { - root, err := ioutil.ReadFile(fmt.Sprintf(childCACert, i, j)) + root, err := os.ReadFile(fmt.Sprintf(childCACert, i, j)) if err != nil { return [][]byte{} } diff --git a/internal/pkg/comm/creds_test.go b/internal/pkg/comm/creds_test.go index 0fb6d663890..5072745c52d 100644 --- a/internal/pkg/comm/creds_test.go +++ b/internal/pkg/comm/creds_test.go @@ -10,8 +10,8 @@ import ( "context" "crypto/tls" "crypto/x509" - "io/ioutil" "net" + "os" "path/filepath" "sync" "testing" @@ -24,7 +24,7 @@ import ( func TestCreds(t *testing.T) { t.Parallel() - caPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) + caPEM, err := os.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) if err != nil { t.Fatalf("failed to read root certificate: %v", err) } @@ -124,7 +124,7 @@ func TestConfig(t *testing.T) { func TestAddRootCA(t *testing.T) { t.Parallel() - caPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) + caPEM, err := os.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) require.NoError(t, err, "failed to read root certificate") expectedCertPool := x509.NewCertPool() diff --git a/internal/pkg/comm/server_test.go b/internal/pkg/comm/server_test.go index 1c325ea495f..5126a7d7997 100644 --- a/internal/pkg/comm/server_test.go +++ b/internal/pkg/comm/server_test.go @@ -13,9 +13,9 @@ import ( "crypto/x509" "fmt" "io" - "io/ioutil" "log" "net" + "os" "path/filepath" "sync/atomic" "testing" @@ -276,7 +276,7 @@ func createCertPool(rootCAs [][]byte) (*x509.CertPool, error) { func loadOrg(parent int) (testOrg, error) { org := testOrg{} // load the CA - caPEM, err := ioutil.ReadFile(fmt.Sprintf(orgCACert, parent)) + caPEM, err := os.ReadFile(fmt.Sprintf(orgCACert, parent)) if err != nil { return org, err } @@ -284,11 +284,11 @@ func loadOrg(parent int) (testOrg, error) { // loop through and load servers serverCerts := []serverCert{} for i := 1; i <= numServerCerts; i++ { - keyPEM, err := ioutil.ReadFile(fmt.Sprintf(orgServerKey, parent, i)) + keyPEM, err := os.ReadFile(fmt.Sprintf(orgServerKey, parent, i)) if err != nil { return org, err } - certPEM, err := ioutil.ReadFile(fmt.Sprintf(orgServerCert, parent, i)) + certPEM, err := os.ReadFile(fmt.Sprintf(orgServerCert, parent, i)) if err != nil { return org, err } @@ -322,7 +322,7 @@ func loadOrg(parent int) (testOrg, error) { // utility function to load crypto material for child organizations func loadChildOrg(parent, child int) (testOrg, error) { // load the CA - caPEM, err := ioutil.ReadFile(fmt.Sprintf(childCACert, parent, child)) + caPEM, err := os.ReadFile(fmt.Sprintf(childCACert, parent, child)) if err != nil { return testOrg{}, err } @@ -330,11 +330,11 @@ func loadChildOrg(parent, child int) (testOrg, error) { // loop through and load servers serverCerts := []serverCert{} for i := 1; i <= numServerCerts; i++ { - keyPEM, err := ioutil.ReadFile(fmt.Sprintf(childServerKey, parent, child, i)) + keyPEM, err := os.ReadFile(fmt.Sprintf(childServerKey, parent, child, i)) if err != nil { return testOrg{}, err } - certPEM, err := ioutil.ReadFile(fmt.Sprintf(childServerCert, parent, child, i)) + certPEM, err := os.ReadFile(fmt.Sprintf(childServerCert, parent, child, i)) if err != nil { return testOrg{}, err } @@ -359,12 +359,12 @@ func loadChildOrg(parent, child int) (testOrg, error) { // loadTLSKeyPairFromFile creates a tls.Certificate from PEM-encoded key and cert files func loadTLSKeyPairFromFile(keyFile, certFile string) (tls.Certificate, error) { - certPEMBlock, err := ioutil.ReadFile(certFile) + certPEMBlock, err := os.ReadFile(certFile) if err != nil { return tls.Certificate{}, err } - keyPEMBlock, err := ioutil.ReadFile(keyFile) + keyPEMBlock, err := os.ReadFile(keyFile) if err != nil { return tls.Certificate{}, err } @@ -730,13 +730,13 @@ func TestWithSignedRootCertificates(t *testing.T) { // use Org1 testdata fileBase := "Org1" - certPEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-server1-cert.pem")) + certPEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-server1-cert.pem")) require.NoError(t, err, "failed to load test certificates") - keyPEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-server1-key.pem")) + keyPEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-server1-key.pem")) require.NoError(t, err, "failed to load test certificates: %v") - caPEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-cert.pem")) + caPEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-cert.pem")) require.NoError(t, err, "failed to load test certificates") // create our listener @@ -789,13 +789,13 @@ func TestWithSignedIntermediateCertificates(t *testing.T) { // use Org1 testdata fileBase := "Org1" - certPEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-server1-cert.pem")) + certPEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-server1-cert.pem")) require.NoError(t, err) - keyPEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-server1-key.pem")) + keyPEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-server1-key.pem")) require.NoError(t, err) - intermediatePEMBlock, err := ioutil.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-cert.pem")) + intermediatePEMBlock, err := os.ReadFile(filepath.Join("testdata", "certs", fileBase+"-child1-cert.pem")) if err != nil { t.Fatalf("Failed to load test certificates: %v", err) } @@ -1048,7 +1048,7 @@ func TestUpdateTLSCert(t *testing.T) { readFile := func(path string) []byte { fName := filepath.Join("testdata", "dynamic_cert_update", path) - data, err := ioutil.ReadFile(fName) + data, err := os.ReadFile(fName) if err != nil { panic(fmt.Errorf("Failed reading %s: %v", fName, err)) } @@ -1124,11 +1124,11 @@ func TestUpdateTLSCert(t *testing.T) { func TestCipherSuites(t *testing.T) { t.Parallel() - certPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-server1-cert.pem")) + certPEM, err := os.ReadFile(filepath.Join("testdata", "certs", "Org1-server1-cert.pem")) require.NoError(t, err) - keyPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-server1-key.pem")) + keyPEM, err := os.ReadFile(filepath.Join("testdata", "certs", "Org1-server1-key.pem")) require.NoError(t, err) - caPEM, err := ioutil.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) + caPEM, err := os.ReadFile(filepath.Join("testdata", "certs", "Org1-cert.pem")) require.NoError(t, err) certPool, err := createCertPool([][]byte{caPEM}) require.NoError(t, err) diff --git a/internal/pkg/peer/orderers/connection_test.go b/internal/pkg/peer/orderers/connection_test.go index ee904fc7648..7f9f98218eb 100644 --- a/internal/pkg/peer/orderers/connection_test.go +++ b/internal/pkg/peer/orderers/connection_test.go @@ -8,7 +8,7 @@ package orderers_test import ( "bytes" - "io/ioutil" + "os" "sort" . "github.com/onsi/ginkgo/v2" @@ -59,13 +59,13 @@ var _ = Describe("Connection", func() { BeforeEach(func() { var err error - cert1, err = ioutil.ReadFile("testdata/tlsca.example.com-cert.pem") + cert1, err = os.ReadFile("testdata/tlsca.example.com-cert.pem") Expect(err).NotTo(HaveOccurred()) - cert2, err = ioutil.ReadFile("testdata/tlsca.org1.example.com-cert.pem") + cert2, err = os.ReadFile("testdata/tlsca.org1.example.com-cert.pem") Expect(err).NotTo(HaveOccurred()) - cert3, err = ioutil.ReadFile("testdata/tlsca.org2.example.com-cert.pem") + cert3, err = os.ReadFile("testdata/tlsca.org2.example.com-cert.pem") Expect(err).NotTo(HaveOccurred()) org1 = orderers.OrdererOrg{ diff --git a/msp/configbuilder.go b/msp/configbuilder.go index 6744b63332f..c900badaa5b 100644 --- a/msp/configbuilder.go +++ b/msp/configbuilder.go @@ -59,7 +59,7 @@ type Configuration struct { } func readFile(file string) ([]byte, error) { - fileCont, err := ioutil.ReadFile(file) + fileCont, err := os.ReadFile(file) if err != nil { return nil, errors.Wrapf(err, "could not read file %s", file) } @@ -264,7 +264,7 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M if err == nil { // load the file, if there is a failure in loading it then // return an error - raw, err := ioutil.ReadFile(configFile) + raw, err := os.ReadFile(configFile) if err != nil { return nil, errors.Wrapf(err, "failed loading configuration file at [%s]", configFile) } diff --git a/orderer/common/cluster/util_test.go b/orderer/common/cluster/util_test.go index 7325b4ae1a5..5d2b38825b3 100644 --- a/orderer/common/cluster/util_test.go +++ b/orderer/common/cluster/util_test.go @@ -13,8 +13,8 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" "math" + "os" "strings" "sync" "testing" @@ -695,7 +695,7 @@ func TestLastConfigBlock(t *testing.T) { } func TestVerificationRegistryRegisterVerifier(t *testing.T) { - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") require.NoError(t, err) block := &common.Block{} @@ -737,7 +737,7 @@ func TestVerificationRegistryRegisterVerifier(t *testing.T) { } func TestVerificationRegistry(t *testing.T) { - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") require.NoError(t, err) block := &common.Block{} diff --git a/orderer/common/filerepo/filerepo_test.go b/orderer/common/filerepo/filerepo_test.go index 26b72738cd0..a6be95a8fcc 100644 --- a/orderer/common/filerepo/filerepo_test.go +++ b/orderer/common/filerepo/filerepo_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package filerepo_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -94,7 +93,7 @@ func TestFileRepo_Save(t *testing.T) { require.NoError(t, err) // Check file bytes - bytes, err := ioutil.ReadFile(filePath) + bytes, err := os.ReadFile(filePath) require.NoError(t, err) if tt.content != nil { require.Equal(t, tt.content, bytes) diff --git a/orderer/common/msgprocessor/expiration_test.go b/orderer/common/msgprocessor/expiration_test.go index c4adad44943..2c9880de7e8 100644 --- a/orderer/common/msgprocessor/expiration_test.go +++ b/orderer/common/msgprocessor/expiration_test.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package msgprocessor import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -53,7 +53,7 @@ func createEnvelope(t *testing.T, serializedIdentity []byte) *common.Envelope { } func createX509Identity(t *testing.T, certFileName string) []byte { - certBytes, err := ioutil.ReadFile(filepath.Join("testdata", certFileName)) + certBytes, err := os.ReadFile(filepath.Join("testdata", certFileName)) require.NoError(t, err) sId := &msp.SerializedIdentity{ IdBytes: certBytes, diff --git a/orderer/common/server/etcdraft_test.go b/orderer/common/server/etcdraft_test.go index f973372e9aa..0d1efe7e56f 100644 --- a/orderer/common/server/etcdraft_test.go +++ b/orderer/common/server/etcdraft_test.go @@ -86,7 +86,7 @@ func TestSpawnEtcdRaft(t *testing.T) { func copyYamlFiles(gt *GomegaWithT, src, dst string) { for _, file := range []string{"configtx.yaml", "examplecom-config.yaml", "orderer.yaml"} { - fileBytes, err := ioutil.ReadFile(filepath.Join(src, file)) + fileBytes, err := os.ReadFile(filepath.Join(src, file)) gt.Expect(err).NotTo(HaveOccurred()) err = os.WriteFile(filepath.Join(dst, file), fileBytes, 0o644) gt.Expect(err).NotTo(HaveOccurred()) @@ -166,7 +166,7 @@ func testEtcdRaftOSNJoinAppChan(gt *GomegaWithT, configPath, configtxgen, ordere // emulate a join-block for an application channel written to the join-block filerepo location func writeJoinBlock(gt *GomegaWithT, configPath string, configtxgen string, tempDir string) string { genesisBlockPath := generateBootstrapBlock(gt, configPath, configtxgen, "mychannel", "SampleOrgChannel") - genesisBlockBytes, err := ioutil.ReadFile(genesisBlockPath) + genesisBlockBytes, err := os.ReadFile(genesisBlockPath) gt.Expect(err).NotTo(HaveOccurred()) fileRepoDir := filepath.Join(tempDir, "ledger", "pendingops", "join") err = os.MkdirAll(fileRepoDir, 0o744) diff --git a/orderer/common/server/main.go b/orderer/common/server/main.go index 13f93a6b8a1..d8be8d0c56c 100644 --- a/orderer/common/server/main.go +++ b/orderer/common/server/main.go @@ -10,7 +10,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "net" "net/http" _ "net/http/pprof" // This is essentially the main package for the orderer @@ -142,7 +141,7 @@ func Main() { } if !reuseGrpcListener { - clusterServerConfig, clusterGRPCServer = configureClusterListener(conf, serverConfig, ioutil.ReadFile) + clusterServerConfig, clusterGRPCServer = configureClusterListener(conf, serverConfig, os.ReadFile) } // If we have a separate gRPC server for the cluster, @@ -409,19 +408,19 @@ func initializeClusterClientConfig(conf *localconfig.TopLevel) (comm.ClientConfi keyFile = conf.General.TLS.PrivateKey } - certBytes, err := ioutil.ReadFile(certFile) + certBytes, err := os.ReadFile(certFile) if err != nil { logger.Fatalf("Failed to load client TLS certificate file '%s' (%s)", certFile, err) } - keyBytes, err := ioutil.ReadFile(keyFile) + keyBytes, err := os.ReadFile(keyFile) if err != nil { logger.Fatalf("Failed to load client TLS key file '%s' (%s)", keyFile, err) } var serverRootCAs [][]byte for _, serverRoot := range conf.General.Cluster.RootCAs { - rootCACert, err := ioutil.ReadFile(serverRoot) + rootCACert, err := os.ReadFile(serverRoot) if err != nil { logger.Fatalf("Failed to load ServerRootCAs file '%s' (%s)", serverRoot, err) } @@ -457,19 +456,19 @@ func initializeServerConfig(conf *localconfig.TopLevel, metricsProvider metrics. if secureOpts.UseTLS { msg := "TLS" // load crypto material from files - serverCertificate, err := ioutil.ReadFile(conf.General.TLS.Certificate) + serverCertificate, err := os.ReadFile(conf.General.TLS.Certificate) if err != nil { logger.Fatalf("Failed to load server Certificate file '%s' (%s)", conf.General.TLS.Certificate, err) } - serverKey, err := ioutil.ReadFile(conf.General.TLS.PrivateKey) + serverKey, err := os.ReadFile(conf.General.TLS.PrivateKey) if err != nil { logger.Fatalf("Failed to load PrivateKey file '%s' (%s)", conf.General.TLS.PrivateKey, err) } var serverRootCAs, clientRootCAs [][]byte for _, serverRoot := range conf.General.TLS.RootCAs { - root, err := ioutil.ReadFile(serverRoot) + root, err := os.ReadFile(serverRoot) if err != nil { logger.Fatalf("Failed to load ServerRootCAs file '%s' (%s)", err, serverRoot) @@ -478,7 +477,7 @@ func initializeServerConfig(conf *localconfig.TopLevel, metricsProvider metrics. } if secureOpts.RequireClientCert { for _, clientRoot := range conf.General.TLS.ClientRootCAs { - root, err := ioutil.ReadFile(clientRoot) + root, err := os.ReadFile(clientRoot) if err != nil { logger.Fatalf("Failed to load ClientRootCAs file '%s' (%s)", err, clientRoot) diff --git a/orderer/common/server/main_test.go b/orderer/common/server/main_test.go index e085dd8f09e..2b806d27d60 100644 --- a/orderer/common/server/main_test.go +++ b/orderer/common/server/main_test.go @@ -5,7 +5,6 @@ package server import ( "fmt" - "io/ioutil" "net" "net/http" "os" @@ -75,7 +74,7 @@ func TestMain(m *testing.M) { func copyYamlFiles(src, dst string) { for _, file := range []string{"configtx.yaml", "examplecom-config.yaml", "orderer.yaml"} { - fileBytes, err := ioutil.ReadFile(filepath.Join(src, file)) + fileBytes, err := os.ReadFile(filepath.Join(src, file)) if err != nil { os.Exit(-1) } @@ -135,7 +134,7 @@ func TestInitializeServerConfig(t *testing.T) { }, } sc := initializeServerConfig(conf, nil) - expectedContent, _ := ioutil.ReadFile("main.go") + expectedContent, _ := os.ReadFile("main.go") require.Equal(t, expectedContent, sc.SecOpts.Certificate) require.Equal(t, expectedContent, sc.SecOpts.Key) require.Equal(t, [][]byte{expectedContent}, sc.SecOpts.ServerRootCAs) @@ -360,7 +359,7 @@ func TestVerifyNoSystemChannelJoinBlock(t *testing.T) { require.NoError(t, err) require.NotNil(t, fileRepo) - genesisBytes, err = ioutil.ReadFile(genesisFile) + genesisBytes, err = os.ReadFile(genesisFile) require.NoError(t, err) require.NotNil(t, genesisBytes) } @@ -970,7 +969,7 @@ func panicMsg(f func()) string { func produceGenesisFileEtcdRaft(t *testing.T, channelID string, tmpDir string) (string, []byte) { confRaft := genesisconfig.Load("SampleEtcdRaftSystemChannel", tmpDir) - serverCert, err := ioutil.ReadFile(string(confRaft.Orderer.EtcdRaft.Consenters[0].ServerTlsCert)) + serverCert, err := os.ReadFile(string(confRaft.Orderer.EtcdRaft.Consenters[0].ServerTlsCert)) require.NoError(t, err) bootstrapper, err := encoder.NewBootstrapper(confRaft) @@ -986,7 +985,7 @@ func produceGenesisFileEtcdRaft(t *testing.T, channelID string, tmpDir string) ( func produceGenesisFileEtcdRaftAppChannel(t *testing.T, channelID string, tmpDir string) (string, []byte) { confRaft := genesisconfig.Load("SampleOrgChannel", tmpDir) - serverCert, err := ioutil.ReadFile(string(confRaft.Orderer.EtcdRaft.Consenters[0].ServerTlsCert)) + serverCert, err := os.ReadFile(string(confRaft.Orderer.EtcdRaft.Consenters[0].ServerTlsCert)) require.NoError(t, err) bootstrapper, err := encoder.NewBootstrapper(confRaft) diff --git a/orderer/common/server/server_test.go b/orderer/common/server/server_test.go index 3b5d9ed794a..2a71b0102d8 100644 --- a/orderer/common/server/server_test.go +++ b/orderer/common/server/server_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package server import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -98,7 +97,7 @@ func testMsgTrace(handler func(dir string, msg *cb.Envelope) recvr, t *testing.T return nil } require.Nil(t, fileData, "Should only be one file") - fileData, err = ioutil.ReadFile(path) + fileData, err = os.ReadFile(path) require.Nil(t, err) return nil }) diff --git a/orderer/common/server/util_test.go b/orderer/common/server/util_test.go index f5db0791ed2..dca75a96d7d 100644 --- a/orderer/common/server/util_test.go +++ b/orderer/common/server/util_test.go @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0 package server import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -68,11 +67,11 @@ func TestValidateBootstrapBlock(t *testing.T) { defer os.RemoveAll(cryptoPath) systemChannelBlockPath, _ := produceGenesisFileEtcdRaft(t, "system", tempDir) - systemChannelBlockBytes, err := ioutil.ReadFile(systemChannelBlockPath) + systemChannelBlockBytes, err := os.ReadFile(systemChannelBlockPath) require.NoError(t, err) applicationChannelBlockPath, _ := produceGenesisFileEtcdRaftAppChannel(t, "mychannel", tempDir) - applicationChannelBlockBytes, err := ioutil.ReadFile(applicationChannelBlockPath) + applicationChannelBlockBytes, err := os.ReadFile(applicationChannelBlockPath) require.NoError(t, err) appBlock := &common.Block{} diff --git a/orderer/consensus/etcdraft/blockpuller_test.go b/orderer/consensus/etcdraft/blockpuller_test.go index d540369ef60..8d4de10a06c 100644 --- a/orderer/consensus/etcdraft/blockpuller_test.go +++ b/orderer/consensus/etcdraft/blockpuller_test.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package etcdraft_test import ( - "io/ioutil" + "os" "testing" "github.com/golang/protobuf/proto" @@ -26,7 +26,7 @@ import ( ) func TestEndpointconfigFromFromSupport(t *testing.T) { - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") require.NoError(t, err) goodConfigBlock := &common.Block{} @@ -115,7 +115,7 @@ func TestNewBlockPuller(t *testing.T) { ca, err := tlsgen.NewCA() require.NoError(t, err) - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") require.NoError(t, err) goodConfigBlock := &common.Block{} diff --git a/orderer/consensus/etcdraft/consenter_test.go b/orderer/consensus/etcdraft/consenter_test.go index 31af1f71e20..527f8aec555 100644 --- a/orderer/consensus/etcdraft/consenter_test.go +++ b/orderer/consensus/etcdraft/consenter_test.go @@ -82,7 +82,7 @@ var _ = Describe("Consenter", func() { walDir = path.Join(dataDir, "wal-") snapDir = path.Join(dataDir, "snap-") - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") Expect(err).NotTo(HaveOccurred()) goodConfigBlock := &common.Block{} diff --git a/orderer/consensus/etcdraft/util_test.go b/orderer/consensus/etcdraft/util_test.go index 9f391d48840..fbf42a642a1 100644 --- a/orderer/consensus/etcdraft/util_test.go +++ b/orderer/consensus/etcdraft/util_test.go @@ -12,7 +12,7 @@ import ( "encoding/base64" "encoding/pem" "fmt" - "io/ioutil" + "os" "path/filepath" "testing" "time" @@ -52,7 +52,7 @@ func TestIsConsenterOfChannel(t *testing.T) { require.NoError(t, err) validBlock := func() *common.Block { - b, err := ioutil.ReadFile(filepath.Join("testdata", "etcdraftgenesis.block")) + b, err := os.ReadFile(filepath.Join("testdata", "etcdraftgenesis.block")) require.NoError(t, err) block := &common.Block{} err = proto.Unmarshal(b, block) diff --git a/orderer/consensus/smartbft/synchronizer_test.go b/orderer/consensus/smartbft/synchronizer_test.go index b9d37b1f3b5..75dcac900f4 100644 --- a/orderer/consensus/smartbft/synchronizer_test.go +++ b/orderer/consensus/smartbft/synchronizer_test.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package smartbft_test import ( - "io/ioutil" + "os" "testing" "github.com/SmartBFT-Go/consensus/pkg/types" @@ -27,7 +27,7 @@ import ( func noopUpdateLastHash(_ *cb.Block) types.Reconfig { return types.Reconfig{} } func TestSynchronizerSync(t *testing.T) { - blockBytes, err := ioutil.ReadFile("testdata/mychannel.block") + blockBytes, err := os.ReadFile("testdata/mychannel.block") require.NoError(t, err) goodConfigBlock := &cb.Block{} diff --git a/protoutil/signeddata_test.go b/protoutil/signeddata_test.go index 1fdf5aa5681..1b7f6584e0a 100644 --- a/protoutil/signeddata_test.go +++ b/protoutil/signeddata_test.go @@ -9,7 +9,7 @@ package protoutil_test import ( "bytes" "encoding/pem" - "io/ioutil" + "os" "path/filepath" "testing" @@ -161,7 +161,7 @@ func TestLogMessageForSerializedIdentity(t *testing.T) { } func readFile(file string) ([]byte, error) { - fileCont, err := ioutil.ReadFile(file) + fileCont, err := os.ReadFile(file) if err != nil { return nil, errors.Wrapf(err, "could not read file %s", file) }