Skip to content

Commit

Permalink
fix: removing deprecated references and updating NewProvider referenc…
Browse files Browse the repository at this point in the history
…es for using a nil SNIConfig
  • Loading branch information
WendelHime committed Jul 17, 2024
1 parent 878cb7b commit bf437da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
9 changes: 4 additions & 5 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fronted

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -13,7 +12,7 @@ import (
)

func TestCaching(t *testing.T) {
dir, err := ioutil.TempDir("", "direct_test")
dir, err := os.MkdirTemp("", "direct_test")
if !assert.NoError(t, err, "Unable to create temp dir") {
return
}
Expand All @@ -23,8 +22,8 @@ func TestCaching(t *testing.T) {
cloudsackID := "cloudsack"

providers := map[string]*Provider{
testProviderID: NewProvider(nil, "", nil, nil, nil),
cloudsackID: NewProvider(nil, "", nil, nil, nil),
testProviderID: NewProvider(nil, "", nil, nil, nil, nil),
cloudsackID: NewProvider(nil, "", nil, nil, nil, nil),
}

makeDirect := func() *direct {
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestCaching(t *testing.T) {

readCached := func() []*masquerade {
var result []*masquerade
b, err := ioutil.ReadFile(cacheFile)
b, err := os.ReadFile(cacheFile)
require.NoError(t, err, "Unable to read cache file")
err = json.Unmarshal(b, &result)
require.NoError(t, err, "Unable to unmarshal cache file")
Expand Down
7 changes: 3 additions & 4 deletions direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand/v2"
"net"
"net/http"
Expand Down Expand Up @@ -181,7 +180,7 @@ func doCheck(client *http.Client, method string, expectedStatus int, u string) b
return false
}
if resp.Body != nil {
io.Copy(ioutil.Discard, resp.Body)
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
if resp.StatusCode != expectedStatus {
Expand Down Expand Up @@ -219,7 +218,7 @@ func (d *direct) RoundTripHijack(req *http.Request) (*http.Response, net.Conn, e
var err error
if isIdempotent && req.Body != nil {
// store body in-memory to be able to replay it if necessary
body, err = ioutil.ReadAll(req.Body)
body, err = io.ReadAll(req.Body)
if err != nil {
err := fmt.Errorf("unable to read request body: %v", err)
op.FailIf(err)
Expand All @@ -235,7 +234,7 @@ func (d *direct) RoundTripHijack(req *http.Request) (*http.Response, net.Conn, e
if !isIdempotent {
return req.Body
}
return ioutil.NopCloser(bytes.NewReader(body))
return io.NopCloser(bytes.NewReader(body))
}

tries := 1
Expand Down
24 changes: 12 additions & 12 deletions direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/http/httputil"
Expand All @@ -23,7 +23,7 @@ import (
)

func TestDirectDomainFronting(t *testing.T) {
dir, err := ioutil.TempDir("", "direct_test")
dir, err := os.MkdirTemp("", "direct_test")
require.NoError(t, err, "Unable to create temp dir")
defer os.RemoveAll(dir)
cacheFile := filepath.Join(dir, "cachefile.2")
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestHostAliasesBasic(t *testing.T) {
"abc.forbidden.com": "abc.cloudsack.biz",
"def.forbidden.com": "def.cloudsack.biz",
}
p := NewProvider(alias, "https://ttt.cloudsack.biz/ping", masq, nil, nil)
p := NewProvider(alias, "https://ttt.cloudsack.biz/ping", masq, nil, nil, nil)

certs := x509.NewCertPool()
certs.AddCert(cloudSack.Certificate())
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestHostAliasesBasic(t *testing.T) {
}

var result CDNResult
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if !assert.NoError(t, err) {
continue
}
Expand Down Expand Up @@ -300,14 +300,14 @@ func TestHostAliasesMulti(t *testing.T) {
"abc.forbidden.com": "abc.cloudsack.biz",
"def.forbidden.com": "def.cloudsack.biz",
}
p1 := NewProvider(alias1, "https://ttt.cloudsack.biz/ping", masq1, nil, nil)
p1 := NewProvider(alias1, "https://ttt.cloudsack.biz/ping", masq1, nil, nil, nil)

masq2 := []*Masquerade{{Domain: "example.com", IpAddress: sadCloudAddr}}
alias2 := map[string]string{
"abc.forbidden.com": "abc.sadcloud.io",
"def.forbidden.com": "def.sadcloud.io",
}
p2 := NewProvider(alias2, "https://ttt.sadcloud.io/ping", masq2, nil, nil)
p2 := NewProvider(alias2, "https://ttt.sadcloud.io/ping", masq2, nil, nil, nil)

certs := x509.NewCertPool()
certs.AddCert(cloudSack.Certificate())
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestHostAliasesMulti(t *testing.T) {
}

var result CDNResult
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if !assert.NoError(t, err) {
continue
}
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestPassthrough(t *testing.T) {
masq := []*Masquerade{{Domain: "example.com", IpAddress: cloudSackAddr}}
alias := map[string]string{}
passthrough := []string{"*.ok.cloudsack.biz", "abc.cloudsack.biz"}
p := NewProvider(alias, "https://ttt.cloudsack.biz/ping", masq, nil, passthrough)
p := NewProvider(alias, "https://ttt.cloudsack.biz/ping", masq, nil, passthrough, nil)

certs := x509.NewCertPool()
certs.AddCert(cloudSack.Certificate())
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestPassthrough(t *testing.T) {
}

var result CDNResult
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if !assert.NoError(t, err) {
continue
}
Expand Down Expand Up @@ -506,7 +506,7 @@ func TestCustomValidators(t *testing.T) {
alias := map[string]string{
"abc.forbidden.com": "abc.sadcloud.io",
}
p := NewProvider(alias, "https://ttt.sadcloud.io/ping", masq, validator, nil)
p := NewProvider(alias, "https://ttt.sadcloud.io/ping", masq, validator, nil, nil)

certs := x509.NewCertPool()
certs.AddCert(sadCloud.Certificate())
Expand Down Expand Up @@ -674,7 +674,7 @@ func newCDN(providerID, domain string) (*httptest.Server, string, error) {

func corruptMasquerades(cacheFile string) {
log.Debug("Corrupting masquerades")
data, err := ioutil.ReadFile(cacheFile)
data, err := os.ReadFile(cacheFile)
if err != nil {
log.Error(err)
return
Expand All @@ -699,5 +699,5 @@ func corruptMasquerades(cacheFile string) {
if err != nil {
return
}
ioutil.WriteFile(cacheFile, messedUp, 0644)
os.WriteFile(cacheFile, messedUp, 0644)
}
4 changes: 2 additions & 2 deletions test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func trustedCACerts(t *testing.T) *x509.CertPool {

func testProviders() map[string]*Provider {
return map[string]*Provider{
testProviderID: NewProvider(testHosts, pingTestURL, testMasquerades, nil, nil),
testProviderID: NewProvider(testHosts, pingTestURL, testMasquerades, nil, nil, nil),
}
}

func testProvidersWithHosts(hosts map[string]string) map[string]*Provider {
return map[string]*Provider{
testProviderID: NewProvider(hosts, pingTestURL, testMasquerades, nil, nil),
testProviderID: NewProvider(hosts, pingTestURL, testMasquerades, nil, nil, nil),
}
}

0 comments on commit bf437da

Please sign in to comment.