Removing the use of the ioutil package And Fix CVE-2021-42576 (#1954)

* fix CVE-2021-42576

Signed-off-by: qiangmzsx <qiangmzsx@gmail.com>

* Removing the use of the ioutil package

Signed-off-by: qiangmzsx <qiangmzsx@gmail.com>

* Update middleware/http/nethttpadaptor/nethttpadaptor.go

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>

Signed-off-by: qiangmzsx <qiangmzsx@gmail.com>
Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
This commit is contained in:
qiangmzsx 2022-08-11 04:45:00 +08:00 committed by GitHub
parent e818de3590
commit 79a3cd990a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 74 additions and 83 deletions

View File

@ -15,7 +15,7 @@ package webhook
import ( import (
"context" "context"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sync/atomic" "sync/atomic"
@ -43,7 +43,7 @@ func TestPublishMsg(t *testing.T) { //nolint:paralleltest
t.Errorf("Expected request to '/test', got '%s'", r.URL.EscapedPath()) t.Errorf("Expected request to '/test', got '%s'", r.URL.EscapedPath())
} }
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, msg, string(body)) assert.Equal(t, msg, string(body))
})) }))

View File

@ -16,7 +16,7 @@ package apns
import ( import (
"bytes" "bytes"
"context" "context"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"testing" "testing"
@ -316,7 +316,7 @@ func TestInvoke(t *testing.T) {
return &http.Response{ return &http.Response{
StatusCode: http.StatusBadRequest, StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(strings.NewReader(body)), Body: io.NopCloser(strings.NewReader(body)),
} }
}) })
_, err := testBinding.Invoke(context.TODO(), successRequest) _, err := testBinding.Invoke(context.TODO(), successRequest)

View File

@ -18,7 +18,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"time" "time"
"github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2021-12-01/eventgrid" "github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2021-12-01/eventgrid"
@ -279,7 +279,7 @@ func (a *AzureEventGrid) createSubscription(ctx context.Context) error {
res := result.FutureAPI.Response() res := result.FutureAPI.Response()
if res.StatusCode != fasthttp.StatusCreated { if res.StatusCode != fasthttp.StatusCreated {
bodyBytes, err := ioutil.ReadAll(res.Body) bodyBytes, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
a.logger.Debugf("Failed reading error body when creating or updating Event Grid subscription: %v", err) a.logger.Debugf("Failed reading error body when creating or updating Event Grid subscription: %v", err)

View File

@ -17,7 +17,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -213,7 +213,7 @@ func (s *SignalR) sendMessageToSignalR(ctx context.Context, url string, token st
defer resp.Body.Close() defer resp.Body.Close()
// Read the body regardless to drain it and ensure the connection can be reused // Read the body regardless to drain it and ensure the connection can be reused
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"sync/atomic" "sync/atomic"
@ -284,7 +284,7 @@ func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
func TestWriteShouldFail(t *testing.T) { func TestWriteShouldFail(t *testing.T) {
httpTransport := &mockTransport{ httpTransport := &mockTransport{
response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(strings.NewReader(""))}, response: &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(""))},
} }
s := NewSignalR(logger.NewLogger("test")) s := NewSignalR(logger.NewLogger("test"))
@ -335,7 +335,7 @@ func TestWriteShouldFail(t *testing.T) {
func TestWriteShouldSucceed(t *testing.T) { func TestWriteShouldSucceed(t *testing.T) {
httpTransport := &mockTransport{ httpTransport := &mockTransport{
response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(strings.NewReader(""))}, response: &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(""))},
} }
s := NewSignalR(logger.NewLogger("test")) s := NewSignalR(logger.NewLogger("test"))

View File

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"strconv" "strconv"
@ -214,9 +213,9 @@ func (g *GCPStorage) get(ctx context.Context, req *bindings.InvokeRequest) (*bin
} }
defer rc.Close() defer rc.Close()
data, err := ioutil.ReadAll(rc) data, err := io.ReadAll(rc)
if err != nil { if err != nil {
return nil, fmt.Errorf("gcp bucketgcp bucket binding error: ioutil.ReadAll: %v", err) return nil, fmt.Errorf("gcp bucketgcp bucket binding error: io.ReadAll: %v", err)
} }
if metadata.EncodeBase64 { if metadata.EncodeBase64 {

View File

@ -18,7 +18,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -148,7 +147,7 @@ func (h *HTTPSource) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*
// Read the response body. For empty responses (e.g. 204 No Content) // Read the response body. For empty responses (e.g. 204 No Content)
// `b` will be an empty slice. // `b` will be an empty slice.
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -15,7 +15,7 @@ package http_test
import ( import (
"context" "context"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -53,7 +53,7 @@ func TestInit(t *testing.T) {
input := req.Method input := req.Method
if req.Body != nil { if req.Body != nil {
defer req.Body.Close() defer req.Body.Close()
b, _ := ioutil.ReadAll(req.Body) b, _ := io.ReadAll(req.Body)
if len(b) > 0 { if len(b) > 0 {
input = string(b) input = string(b)
} }

View File

@ -18,7 +18,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"strconv" "strconv"
"github.com/google/uuid" "github.com/google/uuid"
@ -228,7 +228,7 @@ func (o *HuaweiOBS) get(ctx context.Context, req *bindings.InvokeRequest) (*bind
} }
}() }()
data, err := ioutil.ReadAll(out.Body) data, err := io.ReadAll(out.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("obs binding error. error reading obs object content: %w", err) return nil, fmt.Errorf("obs binding error. error reading obs object content: %w", err)
} }

View File

@ -18,7 +18,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
"testing/iotest" "testing/iotest"
@ -374,7 +374,7 @@ func TestGetOperation(t *testing.T) {
}, },
Metadata: map[string]string{}, Metadata: map[string]string{},
}, },
Body: ioutil.NopCloser(strings.NewReader("Hello Dapr")), Body: io.NopCloser(strings.NewReader("Hello Dapr")),
}, nil }, nil
}, },
}, },
@ -447,7 +447,7 @@ func TestGetOperation(t *testing.T) {
}, },
Metadata: map[string]string{}, Metadata: map[string]string{},
}, },
Body: ioutil.NopCloser(iotest.ErrReader(errors.New("unexpected data reading error"))), Body: io.NopCloser(iotest.ErrReader(errors.New("unexpected data reading error"))),
}, nil }, nil
}, },
}, },
@ -667,7 +667,7 @@ func TestInvoke(t *testing.T) {
}, },
Metadata: map[string]string{}, Metadata: map[string]string{},
}, },
Body: ioutil.NopCloser(strings.NewReader("Hello Dapr")), Body: io.NopCloser(strings.NewReader("Hello Dapr")),
}, nil }, nil
}, },
}, },

View File

@ -19,7 +19,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -153,7 +153,7 @@ func (ls *LocalStorage) get(filename string, req *bindings.InvokeRequest) (*bind
return nil, err return nil, err
} }
b, err := ioutil.ReadAll(f) b, err := io.ReadAll(f)
if err != nil { if err != nil {
ls.logger.Debugf("%s", err) ls.logger.Debugf("%s", err)

View File

@ -21,7 +21,7 @@ import (
"database/sql/driver" "database/sql/driver"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"reflect" "reflect"
"strconv" "strconv"
"time" "time"
@ -263,7 +263,7 @@ func initDB(url, pemPath string) (*sql.DB, error) {
if pemPath != "" { if pemPath != "" {
rootCertPool := x509.NewCertPool() rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile(pemPath) pem, err := os.ReadFile(pemPath)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "Error reading PEM file from %s", pemPath) return nil, errors.Wrapf(err, "Error reading PEM file from %s", pemPath)
} }

View File

@ -16,7 +16,7 @@ package sms
import ( import (
"context" "context"
"errors" "errors"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"sync/atomic" "sync/atomic"
@ -68,7 +68,7 @@ func TestParseDuration(t *testing.T) {
func TestWriteShouldSucceed(t *testing.T) { func TestWriteShouldSucceed(t *testing.T) {
httpTransport := &mockTransport{ httpTransport := &mockTransport{
response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(strings.NewReader(""))}, response: &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(""))},
} }
m := bindings.Metadata{} m := bindings.Metadata{}
m.Properties = map[string]string{ m.Properties = map[string]string{
@ -105,7 +105,7 @@ func TestWriteShouldSucceed(t *testing.T) {
func TestWriteShouldFail(t *testing.T) { func TestWriteShouldFail(t *testing.T) {
httpTransport := &mockTransport{ httpTransport := &mockTransport{
response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(strings.NewReader(""))}, response: &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(""))},
} }
m := bindings.Metadata{} m := bindings.Metadata{}
m.Properties = map[string]string{ m.Properties = map[string]string{

2
go.mod
View File

@ -90,7 +90,7 @@ require (
github.com/matoous/go-nanoid/v2 v2.0.0 github.com/matoous/go-nanoid/v2 v2.0.0
github.com/matryer/is v1.4.0 // indirect github.com/matryer/is v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect
github.com/microcosm-cc/bluemonday v1.0.7 // indirect github.com/microcosm-cc/bluemonday v1.0.17 // indirect
github.com/miekg/dns v1.1.48 // indirect github.com/miekg/dns v1.1.48 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4
github.com/moul/http2curl v1.0.0 // indirect github.com/moul/http2curl v1.0.0 // indirect

6
go.sum
View File

@ -2184,8 +2184,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182aff
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY= github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/microcosm-cc/bluemonday v1.0.7 h1:6yAQfk4XT+PI/dk1ZeBp1gr3Q2Hd1DR0O3aEyPUJVTE= github.com/microcosm-cc/bluemonday v1.0.17 h1:Z1a//hgsQ4yjC+8zEkV8IWySkXnsxmdSY642CTFQb5Y=
github.com/microcosm-cc/bluemonday v1.0.7/go.mod h1:HOT/6NaBlR0f9XlxD3zolN6Z3N8Lp4pvhp+jLS5ihnI= github.com/microcosm-cc/bluemonday v1.0.17/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
@ -3238,7 +3238,6 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
@ -3247,6 +3246,7 @@ golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=

View File

@ -18,7 +18,7 @@ import (
"crypto/x509" "crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
@ -331,7 +331,7 @@ func (c CertConfig) GetTokenCredential() (token azcore.TokenCredential, err erro
// If we have a certificate path, load it // If we have a certificate path, load it
if c.ClientCertificateConfig.CertificatePath != "" { if c.ClientCertificateConfig.CertificatePath != "" {
var errB error var errB error
data, errB = ioutil.ReadFile(ccc.CertificatePath) data, errB = os.ReadFile(ccc.CertificatePath)
if errB != nil { if errB != nil {
return nil, fmt.Errorf("failed to read the certificate file (%s): %v", ccc.CertificatePath, errB) return nil, fmt.Errorf("failed to read the certificate file (%s): %v", ccc.CertificatePath, errB)
} }

View File

@ -15,7 +15,6 @@ package azure
import ( import (
"encoding/base64" "encoding/base64"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -60,7 +59,7 @@ func TestGetClientCert(t *testing.T) {
func TestAuthorizorWithCertFile(t *testing.T) { func TestAuthorizorWithCertFile(t *testing.T) {
testCertFileName := "./.cert.pfx" testCertFileName := "./.cert.pfx"
certBytes := getTestCert() certBytes := getTestCert()
err := ioutil.WriteFile(testCertFileName, certBytes, 0o644) err := os.WriteFile(testCertFileName, certBytes, 0o644)
assert.NoError(t, err) assert.NoError(t, err)
settings, err := NewEnvironmentSettings( settings, err := NewEnvironmentSettings(

View File

@ -14,7 +14,7 @@ limitations under the License.
package nethttpadaptor package nethttpadaptor
import ( import (
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -33,7 +33,7 @@ func NewNetHTTPHandlerFunc(logger logger.Logger, h fasthttp.RequestHandler) http
c.Init(&fasthttp.Request{}, &remoteAddr, nil) c.Init(&fasthttp.Request{}, &remoteAddr, nil)
if r.Body != nil { if r.Body != nil {
reqBody, err := ioutil.ReadAll(r.Body) reqBody, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
logger.Errorf("error reading request body, %+v", err) logger.Errorf("error reading request body, %+v", err)

View File

@ -15,7 +15,7 @@ package nethttpadaptor
import ( import (
"context" "context"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -422,7 +422,7 @@ func TestNewNetHTTPHandlerFuncResponses(t *testing.T) {
return httptest.NewRequest("GET", "http://localhost:8080/test", nil) return httptest.NewRequest("GET", "http://localhost:8080/test", nil)
}, },
func(t *testing.T, res *http.Response) { func(t *testing.T, res *http.Response) {
body, _ := ioutil.ReadAll(res.Body) body, _ := io.ReadAll(res.Body)
assert.Equal(t, "test body!", string(body)) assert.Equal(t, "test body!", string(body))
}, },
}, },

View File

@ -22,7 +22,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -247,7 +246,7 @@ func (v *vaultSecretStore) getSecret(secret, version string) (*vaultKVResponse,
} }
} else { } else {
// treat the secret as string // treat the secret as string
b, err := ioutil.ReadAll(httpresp.Body) b, err := io.ReadAll(httpresp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't read response: %s", err) return nil, fmt.Errorf("couldn't read response: %s", err)
} }
@ -394,7 +393,7 @@ func (v *vaultSecretStore) initVaultToken() error {
return nil return nil
} }
data, err := ioutil.ReadFile(v.vaultTokenMountPath) data, err := os.ReadFile(v.vaultTokenMountPath)
if err != nil { if err != nil {
return fmt.Errorf("couldn't read vault token from mount path %s err: %s", v.vaultTokenMountPath, err) return fmt.Errorf("couldn't read vault token from mount path %s err: %s", v.vaultTokenMountPath, err)
} }
@ -477,7 +476,7 @@ func (v *vaultSecretStore) getRootCAsPools(vaultCAPem string, vaultCAPath string
// readCertificateFile reads the certificate at given path. // readCertificateFile reads the certificate at given path.
func readCertificateFile(certPool *x509.CertPool, path string) error { func readCertificateFile(certPool *x509.CertPool, path string) error {
// Read certificate file // Read certificate file
pemFile, err := ioutil.ReadFile(path) pemFile, err := os.ReadFile(path)
if err != nil { if err != nil {
return fmt.Errorf("couldn't read CA file from disk: %s", err) return fmt.Errorf("couldn't read CA file from disk: %s", err)
} }

View File

@ -15,7 +15,6 @@ package vault
import ( import (
"encoding/base64" "encoding/base64"
"io/ioutil"
"os" "os"
"strconv" "strconv"
"testing" "testing"
@ -35,7 +34,7 @@ const (
func TestReadVaultToken(t *testing.T) { func TestReadVaultToken(t *testing.T) {
t.Run("read correct token", func(t *testing.T) { t.Run("read correct token", func(t *testing.T) {
dir := os.TempDir() dir := os.TempDir()
f, err := ioutil.TempFile(dir, "vault-token") f, err := os.CreateTemp(dir, "vault-token")
assert.NoError(t, err) assert.NoError(t, err)
fileName := f.Name() fileName := f.Name()
defer os.Remove(fileName) defer os.Remove(fileName)
@ -55,7 +54,7 @@ func TestReadVaultToken(t *testing.T) {
t.Run("read incorrect token", func(t *testing.T) { t.Run("read incorrect token", func(t *testing.T) {
dir := os.TempDir() dir := os.TempDir()
f, err := ioutil.TempFile(dir, "vault-token") f, err := os.CreateTemp(dir, "vault-token")
assert.NoError(t, err) assert.NoError(t, err)
fileName := f.Name() fileName := f.Name()
defer os.Remove(fileName) defer os.Remove(fileName)

View File

@ -17,7 +17,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"reflect" "reflect"
"strconv" "strconv"
@ -246,7 +246,7 @@ func (j *localSecretStore) readLocalFile(secretsFile string) (map[string]interfa
defer jsonFile.Close() defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile) byteValue, err := io.ReadAll(jsonFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -15,7 +15,7 @@ package cosmosdb
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/a8m/documentdb" "github.com/a8m/documentdb"
@ -127,7 +127,7 @@ func TestCosmosDbQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var qq query.Query var qq query.Query
err = json.Unmarshal(data, &qq) err = json.Unmarshal(data, &qq)

View File

@ -15,7 +15,7 @@ package cockroachdb
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/agrea/ptr" "github.com/agrea/ptr"
@ -57,7 +57,7 @@ func TestPostgresqlQueryBuildQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var storeQuery query.Query var storeQuery query.Query
err = json.Unmarshal(data, &storeQuery) err = json.Unmarshal(data, &storeQuery)

View File

@ -15,7 +15,7 @@ package mongodb
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -50,7 +50,7 @@ func TestMongoQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var qq query.Query var qq query.Query
err = json.Unmarshal(data, &qq) err = json.Unmarshal(data, &qq)

View File

@ -18,7 +18,7 @@ import (
"crypto/x509" "crypto/x509"
"database/sql" "database/sql"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/go-sql-driver/mysql" "github.com/go-sql-driver/mysql"
@ -41,7 +41,7 @@ func (m *mySQLFactory) Open(connectionString string) (*sql.DB, error) {
func (m *mySQLFactory) RegisterTLSConfig(pemPath string) error { func (m *mySQLFactory) RegisterTLSConfig(pemPath string) error {
rootCertPool := x509.NewCertPool() rootCertPool := x509.NewCertPool()
pem, readErr := ioutil.ReadFile(pemPath) pem, readErr := os.ReadFile(pemPath)
if readErr != nil { if readErr != nil {
m.logger.Errorf("Error reading PEM file from $s", pemPath) m.logger.Errorf("Error reading PEM file from $s", pemPath)

View File

@ -18,7 +18,6 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -632,7 +631,7 @@ func connectToDB(t *testing.T) (*sql.DB, error) {
val := getPemPath() val := getPemPath()
if val != "" { if val != "" {
rootCertPool := x509.NewCertPool() rootCertPool := x509.NewCertPool()
pem, readErr := ioutil.ReadFile(val) pem, readErr := os.ReadFile(val)
assert.Nil(t, readErr, "Could not read PEM file") assert.Nil(t, readErr, "Could not read PEM file")

View File

@ -18,7 +18,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"strconv" "strconv"
@ -292,7 +291,7 @@ func (r *StateStore) writeDocument(req *state.SetRequest) error {
if req.Options.Concurrency != state.FirstWrite { if req.Options.Concurrency != state.FirstWrite {
etag = nil etag = nil
} }
err = r.client.putObject(ctx, objectName, objectLength, ioutil.NopCloser(bytes.NewReader(content)), metadata, etag) err = r.client.putObject(ctx, objectName, objectLength, io.NopCloser(bytes.NewReader(content)), metadata, etag)
if err != nil { if err != nil {
r.logger.Debugf("error in writing object to OCI object storage %s, err %s", req.Key, err) r.logger.Debugf("error in writing object to OCI object storage %s, err %s", req.Key, err)
return fmt.Errorf("failed to write object to OCI Object storage : %w", err) return fmt.Errorf("failed to write object to OCI Object storage : %w", err)

View File

@ -15,7 +15,7 @@ package postgresql
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -54,7 +54,7 @@ func TestPostgresqlQueryBuildQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var qq query.Query var qq query.Query
err = json.Unmarshal(data, &qq) err = json.Unmarshal(data, &qq)

View File

@ -15,7 +15,7 @@ package query
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -85,7 +85,7 @@ func TestQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var q Query var q Query
err = json.Unmarshal(data, &q) err = json.Unmarshal(data, &q)

View File

@ -15,7 +15,7 @@ package redis
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -47,7 +47,7 @@ func TestMongoQuery(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
data, err := ioutil.ReadFile(test.input) data, err := os.ReadFile(test.input)
assert.NoError(t, err) assert.NoError(t, err)
var qq query.Query var qq query.Query
err = json.Unmarshal(data, &qq) err = json.Unmarshal(data, &qq)

View File

@ -15,7 +15,7 @@ package rethinkdb
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -66,7 +66,7 @@ func NewRethinkDBStateStore(logger logger.Logger) *RethinkDB {
// Init parses metadata, initializes the RethinkDB client, and ensures the state table exists. // Init parses metadata, initializes the RethinkDB client, and ensures the state table exists.
func (s *RethinkDB) Init(metadata state.Metadata) error { func (s *RethinkDB) Init(metadata state.Metadata) error {
r.Log.Out = ioutil.Discard r.Log.Out = io.Discard
r.SetTags("rethinkdb", "json") r.SetTags("rethinkdb", "json")
cfg, err := metadataToConfig(metadata.Properties, s.logger) cfg, err := metadataToConfig(metadata.Properties, s.logger)
if err != nil { if err != nil {

View File

@ -18,7 +18,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"testing" "testing"
@ -320,7 +320,7 @@ func TestBlobStorage(t *testing.T) {
url := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", storageAccountName, containerName, blobName) url := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", storageAccountName, containerName, blobName)
resp, httpErr := http.Get(url) // nolint:gosec resp, httpErr := http.Get(url) // nolint:gosec
assert.NoError(t, httpErr) assert.NoError(t, httpErr)
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
resp.Body.Close() resp.Body.Close()
if shoudBePublic { if shoudBePublic {

View File

@ -17,7 +17,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path" "path"
@ -225,7 +224,7 @@ func isYaml(fileName string) bool {
} }
func readTestConfiguration(filePath string) ([]byte, error) { func readTestConfiguration(filePath string) ([]byte, error) {
b, err := ioutil.ReadFile(filePath) b, err := os.ReadFile(filePath)
if err != nil { if err != nil {
return nil, fmt.Errorf("error reading file %s", filePath) return nil, fmt.Errorf("error reading file %s", filePath)
} }

View File

@ -17,8 +17,8 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"io" "io"
"io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -45,7 +45,7 @@ func NewStandaloneComponents(componentPath string) *StandaloneComponents {
// LoadComponents loads dapr components from a given directory. // LoadComponents loads dapr components from a given directory.
func (s *StandaloneComponents) LoadComponents() ([]Component, error) { func (s *StandaloneComponents) LoadComponents() ([]Component, error) {
dir := s.componentsPath dir := s.componentsPath
files, err := ioutil.ReadDir(dir) files, err := os.ReadDir(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,7 +56,7 @@ func (s *StandaloneComponents) LoadComponents() ([]Component, error) {
if !file.IsDir() && s.isYaml(file.Name()) { if !file.IsDir() && s.isYaml(file.Name()) {
path := filepath.Join(dir, file.Name()) path := filepath.Join(dir, file.Name())
b, err := ioutil.ReadFile(path) b, err := os.ReadFile(path)
if err != nil { if err != nil {
log.Printf("error reading file %s : %s", path, err) log.Printf("error reading file %s : %s", path, err)

View File

@ -15,7 +15,7 @@ package utils
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -118,7 +118,7 @@ func (s *server) handleGet() []byte {
} }
func (s *server) handlePost(r *http.Request) { func (s *server) handlePost(r *http.Request) {
data, err := ioutil.ReadAll(r.Body) data, err := io.ReadAll(r.Body)
defer r.Body.Close() defer r.Body.Close()
if err == nil { if err == nil {

View File

@ -18,7 +18,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -151,7 +150,7 @@ func RetryModifier(jobType string, retries int) func(string) string {
// GetTestFile loads the content of a BPMN process file. The function also accepts a list of // GetTestFile loads the content of a BPMN process file. The function also accepts a list of
// modifier functions which allows to manipulate the content of the returned BPMN file. // modifier functions which allows to manipulate the content of the returned BPMN file.
func GetTestFile(fileName string, modifiers ...func(string) string) ([]byte, error) { func GetTestFile(fileName string, modifiers ...func(string) string) ([]byte, error) {
dataBytes, err := ioutil.ReadFile("../processes/" + fileName) dataBytes, err := os.ReadFile("../processes/" + fileName)
if err != nil { if err != nil {
return nil, err return nil, err
} }