Skip to content

Commit

Permalink
signer: replace uses of deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Nov 20, 2022
1 parent b27c723 commit e7d48f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
43 changes: 22 additions & 21 deletions signer/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"encoding/hex"
"encoding/pem"
"errors"
"io/ioutil"
"math/big"
"net"
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"regexp"
"sort"
Expand All @@ -31,6 +31,7 @@ import (
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/log"
"github.com/cloudflare/cfssl/signer"

"github.com/google/certificate-transparency-go"
"github.com/zmap/zlint/v3/lint"
)
Expand Down Expand Up @@ -215,13 +216,13 @@ func TestSign(t *testing.T) {
}

// not a csr
certPem, err := ioutil.ReadFile("../../helpers/testdata/cert.pem")
certPem, err := os.ReadFile("../../helpers/testdata/cert.pem")
if err != nil {
t.Fatal(err)
}

// csr with ip as hostname
pem, err := ioutil.ReadFile("testdata/ip.csr")
pem, err := os.ReadFile("testdata/ip.csr")
if err != nil {
t.Fatal(err)
}
Expand All @@ -239,7 +240,7 @@ func TestSign(t *testing.T) {
t.Fatal("A bad case failed to raise an error")
}

pem, err = ioutil.ReadFile("testdata/ex.csr")
pem, err = os.ReadFile("testdata/ex.csr")
validReq = signer.SignRequest{
Request: string(pem),
Hosts: []string{"example.com"},
Expand Down Expand Up @@ -295,7 +296,7 @@ const (
func testSignFile(t *testing.T, certFile string) ([]byte, error) {
s := newTestSigner(t)

pem, err := ioutil.ReadFile(certFile)
pem, err := os.ReadFile(certFile)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -369,7 +370,7 @@ func TestSignCSRs(t *testing.T) {
s := newTestSigner(t)
hostname := "cloudflare.com"
for _, test := range csrTests {
csr, err := ioutil.ReadFile(test.file)
csr, err := os.ReadFile(test.file)
if err != nil {
t.Fatal("CSR loading error:", err)
}
Expand Down Expand Up @@ -397,7 +398,7 @@ func TestECDSASigner(t *testing.T) {
s := newCustomSigner(t, testECDSACaFile, testECDSACaKeyFile)
hostname := "cloudflare.com"
for _, test := range csrTests {
csr, err := ioutil.ReadFile(test.file)
csr, err := os.ReadFile(test.file)
if err != nil {
t.Fatal("CSR loading error:", err)
}
Expand Down Expand Up @@ -449,7 +450,7 @@ func TestCAIssuing(t *testing.T) {
s := newCustomSigner(t, caFile, caKeyFile)
s.policy = CAPolicy
for j, csr := range interCSRs {
csrBytes, _ := ioutil.ReadFile(csr)
csrBytes, _ := os.ReadFile(csr)
certBytes, err := s.Sign(signer.SignRequest{Hosts: signer.SplitHosts(hostname), Request: string(csrBytes)})
if err != nil {
t.Fatal(err)
Expand All @@ -458,7 +459,7 @@ func TestCAIssuing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
keyBytes, _ := ioutil.ReadFile(interKeys[j])
keyBytes, _ := os.ReadFile(interKeys[j])
interKey, _ := helpers.ParsePrivateKeyPEM(keyBytes)
interSigner := &Signer{
ca: interCert,
Expand All @@ -467,7 +468,7 @@ func TestCAIssuing(t *testing.T) {
sigAlgo: signer.DefaultSigAlgo(interKey),
}
for _, anotherCSR := range interCSRs {
anotherCSRBytes, _ := ioutil.ReadFile(anotherCSR)
anotherCSRBytes, _ := os.ReadFile(anotherCSR)
bytes, err := interSigner.Sign(
signer.SignRequest{
Hosts: signer.SplitHosts(hostname),
Expand Down Expand Up @@ -564,7 +565,7 @@ func TestPopulateSubjectFromCSR(t *testing.T) {

}
func TestOverrideSubject(t *testing.T) {
csrPEM, err := ioutil.ReadFile(fullSubjectCSR)
csrPEM, err := os.ReadFile(fullSubjectCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -624,7 +625,7 @@ func TestOverrideSubject(t *testing.T) {

func TestOverwriteHosts(t *testing.T) {
for _, csrFile := range []string{testCSR, testSANCSR} {
csrPEM, err := ioutil.ReadFile(csrFile)
csrPEM, err := os.ReadFile(csrFile)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -702,7 +703,7 @@ func TestOverwriteHosts(t *testing.T) {
}

func TestOverrideValidity(t *testing.T) {
csrPEM, err := ioutil.ReadFile(fullSubjectCSR)
csrPEM, err := os.ReadFile(fullSubjectCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -904,7 +905,7 @@ func TestCASignPathlen(t *testing.T) {
}

for _, testCase := range csrPathlenTests {
csrPEM, err := ioutil.ReadFile(testCase.csrFile)
csrPEM, err := os.ReadFile(testCase.csrFile)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -964,7 +965,7 @@ func TestCASignPathlen(t *testing.T) {
}

func TestNoWhitelistSign(t *testing.T) {
csrPEM, err := ioutil.ReadFile(fullSubjectCSR)
csrPEM, err := os.ReadFile(fullSubjectCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1019,7 +1020,7 @@ func TestNoWhitelistSign(t *testing.T) {
}

func TestWhitelistSign(t *testing.T) {
csrPEM, err := ioutil.ReadFile(fullSubjectCSR)
csrPEM, err := os.ReadFile(fullSubjectCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1088,7 +1089,7 @@ func TestWhitelistSign(t *testing.T) {
}

func TestNameWhitelistSign(t *testing.T) {
csrPEM, err := ioutil.ReadFile(fullSubjectCSR)
csrPEM, err := os.ReadFile(fullSubjectCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1160,7 +1161,7 @@ func TestNameWhitelistSign(t *testing.T) {
}

func TestExtensionSign(t *testing.T) {
csrPEM, err := ioutil.ReadFile(testCSR)
csrPEM, err := os.ReadFile(testCSR)
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1270,7 +1271,7 @@ func TestCTFailure(t *testing.T) {
t.Fatalf("%v", err)
}
var pem []byte
pem, err = ioutil.ReadFile("testdata/ex.csr")
pem, err = os.ReadFile("testdata/ex.csr")
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1307,7 +1308,7 @@ func TestCTSuccess(t *testing.T) {
t.Fatalf("%v", err)
}
var pem []byte
pem, err = ioutil.ReadFile("testdata/ex.csr")
pem, err = os.ReadFile("testdata/ex.csr")
if err != nil {
t.Fatalf("%v", err)
}
Expand Down Expand Up @@ -1335,7 +1336,7 @@ func TestReturnPrecert(t *testing.T) {
if err != nil {
t.Fatalf("%v", err)
}
csr, err := ioutil.ReadFile("testdata/ex.csr")
csr, err := os.ReadFile("testdata/ex.csr")
if err != nil {
t.Fatalf("%v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions signer/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"math/big"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

Expand Down Expand Up @@ -130,7 +130,7 @@ func verifyRemoteInfo(t *testing.T, remoteConfig *config.Config) {
t.Fatal("remote info failed:", err)
}

caBytes, err := ioutil.ReadFile(testCaFile)
caBytes, err := os.ReadFile(testCaFile)
caBytes = bytes.TrimSpace(caBytes)
if err != nil {
t.Fatal("fail to read test CA cert:", err)
Expand Down Expand Up @@ -187,7 +187,7 @@ func verifyRemoteSign(t *testing.T, remoteConfig *config.Config) {

hosts := []string{"cloudflare.com"}
for _, test := range testsuite.CSRTests {
csr, err := ioutil.ReadFile(test.File)
csr, err := os.ReadFile(test.File)
if err != nil {
t.Fatal("CSR loading error:", err)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestRemoteSignBadServerAndOverride(t *testing.T) {
s := newRemoteSigner(t, remoteConfig.Signing)

hosts := []string{"cloudflare.com"}
csr, err := ioutil.ReadFile("../local/testdata/rsa2048.csr")
csr, err := os.ReadFile("../local/testdata/rsa2048.csr")
if err != nil {
t.Fatal("CSR loading error:", err)
}
Expand Down
6 changes: 3 additions & 3 deletions signer/universal/universal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package universal

import (
"bytes"
"io/ioutil"
"math/big"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -300,7 +300,7 @@ func checkInfo(t *testing.T, s signer.Signer, name string, profile *config.Signi
t.Fatalf("Expected usage for profile %s to be %+v, got %+v", name, profile.Usage, resp.Usage)
}

caBytes, err := ioutil.ReadFile(testCaFile)
caBytes, err := os.ReadFile(testCaFile)
caBytes = bytes.TrimSpace(caBytes)
if err != nil {
t.Fatal("fail to read test CA cert:", err)
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestUniversalRemoteAndLocalSign(t *testing.T) {
checkSign := func(name string, profile *config.SigningProfile) {
hosts := []string{"cloudflare.com"}
for _, test := range testsuite.CSRTests {
csr, err := ioutil.ReadFile(test.File)
csr, err := os.ReadFile(test.File)
if err != nil {
t.Fatalf("CSR loading error (%s): %v", name, err)
}
Expand Down

0 comments on commit e7d48f1

Please sign in to comment.