From 980de9f12375d7d9f9dbd8acb830c12f8723769f Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Thu, 24 Nov 2022 19:36:38 +0300 Subject: [PATCH] Bump Golang to 1.19.3 --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- ci/test.sh | 3 +++ config_test.go | 7 +++---- go.mod | 8 ++++---- go.sum | 6 ++++++ main.go | 5 ++++- proxy.go | 10 +++++----- proxy_test.go | 15 +++++++-------- 10 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff22c10..dbdb102 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: ~1.19.3 - uses: actions/cache@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84b8ac7..5182e4f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: ~1.19.3 - uses: actions/cache@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d59054..1af7178 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: - name: Setup Golang uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: ~1.19.3 - uses: actions/cache@v1 with: diff --git a/ci/test.sh b/ci/test.sh index e3ed76f..d918131 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -2,3 +2,6 @@ export GO111MODULE="on" go test -tags 'watch' -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg github.com/aerokube/ggr + +go install golang.org/x/vuln/cmd/govulncheck@latest +"$(go env GOPATH)"/bin/govulncheck -tags production ./... diff --git a/config_test.go b/config_test.go index 091d705..32f9e52 100644 --- a/config_test.go +++ b/config_test.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "testing" @@ -167,7 +166,7 @@ func TestFindWithPlatformPrefix(t *testing.T) { } func TestReadNotExistingConfig(t *testing.T) { - tmp, err := ioutil.TempFile("", "config") + tmp, err := os.CreateTemp("", "config") if err != nil { t.Fatal(err) } @@ -183,7 +182,7 @@ func TestReadNotExistingConfig(t *testing.T) { } func TestParseInvalidConfig(t *testing.T) { - tmp, err := ioutil.TempFile("", "config") + tmp, err := os.CreateTemp("", "config") defer os.Remove(tmp.Name()) if err != nil { t.Fatal(err) @@ -212,7 +211,7 @@ func TestParseConfigWithoutNamespace(t *testing.T) { } func testParseConfig(t *testing.T, config string) { - tmp, err := ioutil.TempFile("", "config") + tmp, err := os.CreateTemp("", "config") defer os.Remove(tmp.Name()) if err != nil { t.Fatal(err) diff --git a/go.mod b/go.mod index 3cb9317..5027bb3 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/aerokube/ggr -go 1.18 +go 1.19 require ( - github.com/aandryashin/matchers v0.0.0-20160729131923-5eb67beb188b + github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40 github.com/abbot/go-http-auth v0.4.1-0.20220112235402-e1cee1c72f2f - golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 + golang.org/x/net v0.2.0 ) require ( github.com/fsnotify/fsnotify v1.5.4 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/sys v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index d76955c..3bbf1ae 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/aandryashin/matchers v0.0.0-20160729131923-5eb67beb188b h1:2hJ49uel4j48uteFY3ybBiSB35Ml86IZkSXAb+rj0lQ= github.com/aandryashin/matchers v0.0.0-20160729131923-5eb67beb188b/go.mod h1:cbmYNkm9xeQlNoWEPtOUcvNok2gSD7ErMnYkRW+eHi8= +github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e h1:ogUKYFNcdYUIBSLibE4+EjbTJazoHr5JsWWx21Lpn8c= +github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e/go.mod h1:cbmYNkm9xeQlNoWEPtOUcvNok2gSD7ErMnYkRW+eHi8= github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40 h1:zSKVi4h3Kv0HvNGjWPOsOEJIxtvd3PRMlVA/fcCB45g= github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40/go.mod h1:gvg2/m9OQ4ZwK4Qk/mnfgokCb4qDN4BGyle+QGw4VOc= github.com/abbot/go-http-auth v0.4.1-0.20220112235402-e1cee1c72f2f h1:R2ZVGCZzU95oXFJxncosHS9LsX8N4/MYUdGGWOb2cFk= @@ -10,11 +12,15 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5U golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go index ce77168..7becf99 100644 --- a/main.go +++ b/main.go @@ -111,7 +111,10 @@ func init() { go func() { for { <-sig - loadQuotaFiles(quotaDir) + err := loadQuotaFiles(quotaDir) + if err != nil { + log.Printf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [%v]\n", err) + } } }() } diff --git a/proxy.go b/proxy.go index 5e2ec87..d23b84a 100644 --- a/proxy.go +++ b/proxy.go @@ -7,12 +7,12 @@ import ( "encoding/xml" "fmt" "io" - "io/ioutil" "log" "net" "net/http" "net/http/httputil" "net/url" + "os" "reflect" "strings" "sync" @@ -421,7 +421,7 @@ func proxy(w http.ResponseWriter, r *http.Request) { confLock.RUnlock() if ok { if r.Body != nil { - if body, err := ioutil.ReadAll(r.Body); err == nil { + if body, err := io.ReadAll(r.Body); err == nil { r.Body.Close() var msg map[string]interface{} if err := json.Unmarshal(body, &msg); err == nil { @@ -429,7 +429,7 @@ func proxy(w http.ResponseWriter, r *http.Request) { body, _ = json.Marshal(msg) r.ContentLength = int64(len(body)) } - r.Body = ioutil.NopCloser(bytes.NewReader(body)) + r.Body = io.NopCloser(bytes.NewReader(body)) } } if h.Scheme != "" { @@ -570,7 +570,7 @@ func withCloseNotifier(handler http.HandlerFunc) http.HandlerFunc { } func readConfig(fn string, browsers *Browsers) error { - file, err := ioutil.ReadFile(fn) + file, err := os.ReadFile(fn) if err != nil { return fmt.Errorf("error reading configuration file %s: %v", fn, err) } @@ -625,7 +625,7 @@ func requireBasicAuth(authenticator *auth.BasicAuth, handler func(http.ResponseW }) } -//WithSuitableAuthentication handles basic authentication and guest quota processing +// WithSuitableAuthentication handles basic authentication and guest quota processing func WithSuitableAuthentication(authenticator *auth.BasicAuth, handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { if rootToken != "" { diff --git a/proxy_test.go b/proxy_test.go index a3be70d..b9f3cbd 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "net" "net/http" "net/http/httptest" @@ -100,7 +99,7 @@ func TestPing(t *testing.T) { AssertThat(t, rsp.Body, Is{Not{nil}}) var data map[string]interface{} - bt, readErr := ioutil.ReadAll(rsp.Body) + bt, readErr := io.ReadAll(rsp.Body) AssertThat(t, readErr, Is{nil}) jsonErr := json.Unmarshal(bt, &data) AssertThat(t, jsonErr, Is{nil}) @@ -125,7 +124,7 @@ func TestStatus(t *testing.T) { AssertThat(t, rsp.Body, Is{Not{nil}}) var data map[string]interface{} - bt, readErr := ioutil.ReadAll(rsp.Body) + bt, readErr := io.ReadAll(rsp.Body) AssertThat(t, readErr, Is{nil}) jsonErr := json.Unmarshal(bt, &data) AssertThat(t, jsonErr, Is{nil}) @@ -785,7 +784,7 @@ func TestStartSessionWithOverriddenBasicAuth(t *testing.T) { func TestStartSessionWithPrefixVersion(t *testing.T) { mux := http.NewServeMux() mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) r.Body.Close() var sess map[string]map[string]string err := json.Unmarshal(body, &sess) @@ -839,7 +838,7 @@ func TestCreateSessionW3CBrowserNotSet2(t *testing.T) { func TestStartSessionWithDefaultVersion(t *testing.T) { mux := http.NewServeMux() mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) r.Body.Close() w.Write([]byte(`{"sessionId":"123"}`)) var sess map[string]map[string]string @@ -878,7 +877,7 @@ func TestStartSessionWithDefaultVersion(t *testing.T) { func TestStartSessionWithDefaultVersionW3C(t *testing.T) { mux := http.NewServeMux() mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) r.Body.Close() var sess map[string]map[string]map[string]interface{} err := json.Unmarshal(body, &sess) @@ -1416,7 +1415,7 @@ func TestProxyJsonRequest(t *testing.T) { func TestProxyPlainRequest(t *testing.T) { mux := http.NewServeMux() mux.HandleFunc("/wd/hub/session/", func(w http.ResponseWriter, r *http.Request) { - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) r.Body.Close() AssertThat(t, string(body), EqualTo{"request"}) }) @@ -1685,7 +1684,7 @@ func TestFileExists(t *testing.T) { tmpDir := os.TempDir() AssertThat(t, fileExists(tmpDir), Is{false}) AssertThat(t, fileExists(filepath.Join(tmpDir, "missing-file")), Is{false}) - f, err := ioutil.TempFile(tmpDir, "testfile") + f, err := os.CreateTemp(tmpDir, "testfile") AssertThat(t, err, Is{nil}) AssertThat(t, fileExists(f.Name()), Is{true}) }