From bf437da68fef7396214f3c96058d06ec8ee9e0a3 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:12:13 -0300 Subject: [PATCH] fix: removing deprecated references and updating NewProvider references for using a nil SNIConfig --- cache_test.go | 9 ++++----- direct.go | 7 +++---- direct_test.go | 24 ++++++++++++------------ test_support.go | 4 ++-- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/cache_test.go b/cache_test.go index 22f2e45..3c36192 100644 --- a/cache_test.go +++ b/cache_test.go @@ -2,7 +2,6 @@ package fronted import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -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 } @@ -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 { @@ -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") diff --git a/direct.go b/direct.go index d9e167b..fbfe839 100644 --- a/direct.go +++ b/direct.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand/v2" "net" "net/http" @@ -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 { @@ -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) @@ -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 diff --git a/direct_test.go b/direct_test.go index 06f2d42..793f632 100644 --- a/direct_test.go +++ b/direct_test.go @@ -4,7 +4,7 @@ import ( "crypto/x509" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -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") @@ -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()) @@ -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 } @@ -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()) @@ -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 } @@ -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()) @@ -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 } @@ -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()) @@ -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 @@ -699,5 +699,5 @@ func corruptMasquerades(cacheFile string) { if err != nil { return } - ioutil.WriteFile(cacheFile, messedUp, 0644) + os.WriteFile(cacheFile, messedUp, 0644) } diff --git a/test_support.go b/test_support.go index a1fb8ad..122b278 100644 --- a/test_support.go +++ b/test_support.go @@ -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), } }