From 407954d0dfe3bcf6053ad9a6799d7bd276b0202e Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:44:57 -0700 Subject: [PATCH 1/3] chore: prepare v2.13.0 for release --- CHANGELOG.md | 2 +- version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80f6b6f..ecdef5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## [Unreleased] +## v2.13.0 (2023-02-17) - Adds `StatelessRate` object struct, `BetaGetStatelessRates` function to get ephemeral rates. - Adds `LowestStatelessRate`, `LowestStatelessRateWithCarrier` and `LowestStatelessRateWithCarrierAndService` functions to get the lowest stateless rate from a list of stateless rates. diff --git a/version.go b/version.go index 15f54cc..48c0d3a 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package easypost -const Version = "2.12.0" +const Version = "2.13.0" From 9651b901a1126316e02fbe50b25bc3c89b71fc7d Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:19:25 -0700 Subject: [PATCH 2/3] fix: security issues --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- client.go | 4 +++- tests/fixture_test.go | 12 ++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b023677..9bfe40f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,4 +51,4 @@ jobs: - name: Run Gosec uses: securego/gosec@master with: - args: -exclude-dir=examples ./... + args: -tests -exclude-dir=examples ./... diff --git a/Makefile b/Makefile index 344e647..1a8369e 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ release: ## gosec - Run gosec to scan for security issues scan: - gosec ./... + gosec -tests --exclude-dir=examples ./... ## test - Test the project test: diff --git a/client.go b/client.go index ca4cea8..4d9395a 100644 --- a/client.go +++ b/client.go @@ -165,7 +165,9 @@ func (c *Client) do(ctx context.Context, method, path string, in, out interface{ if err != nil { return err } - defer res.Body.Close() + if err := res.Body.Close(); err != nil { + return err + } if res.StatusCode >= 200 && res.StatusCode <= 299 { if out != nil { return json.NewDecoder(res.Body).Decode(out) diff --git a/tests/fixture_test.go b/tests/fixture_test.go index 5d3e46a..cbba7dd 100644 --- a/tests/fixture_test.go +++ b/tests/fixture_test.go @@ -39,13 +39,17 @@ func readFixtureData() Fixture { parentDir := filepath.Dir(currentDir) filePath := fmt.Sprintf("%s%s", parentDir, "/examples/official/fixtures/client-library-fixtures.json") + /* #nosec */ data, err := os.Open(filePath) if err != nil { fmt.Fprintln(os.Stderr, "error opening fixture file:", err) os.Exit(1) } - defer data.Close() + if err := data.Close(); err != nil { + fmt.Fprintln(os.Stderr, "error closing fixture file:", err) + os.Exit(1) + } byteData, _ := ioutil.ReadAll(data) @@ -185,13 +189,17 @@ func (fixture *Fixture) EventBody() []byte { parentDir := filepath.Dir(currentDir) filePath := fmt.Sprintf("%s%s", parentDir, "/examples/official/fixtures/event-body.json") + /* #nosec */ data, err := os.Open(filePath) if err != nil { fmt.Fprintln(os.Stderr, "error opening fixture file:", err) os.Exit(1) } - defer data.Close() + if err := data.Close(); err != nil { + fmt.Fprintln(os.Stderr, "error closing fixture file:", err) + os.Exit(1) + } scanner := bufio.NewScanner(data) var eventBody []byte From 4d45d1c896e826df743bfcb45bd2ace93533b396 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:34:36 -0700 Subject: [PATCH 3/3] fix: defer via inline function to ignore errors --- client.go | 4 +--- tests/fixture_test.go | 10 ++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index 4d9395a..5842d70 100644 --- a/client.go +++ b/client.go @@ -165,9 +165,7 @@ func (c *Client) do(ctx context.Context, method, path string, in, out interface{ if err != nil { return err } - if err := res.Body.Close(); err != nil { - return err - } + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode <= 299 { if out != nil { return json.NewDecoder(res.Body).Decode(out) diff --git a/tests/fixture_test.go b/tests/fixture_test.go index cbba7dd..0e8a89a 100644 --- a/tests/fixture_test.go +++ b/tests/fixture_test.go @@ -46,10 +46,7 @@ func readFixtureData() Fixture { os.Exit(1) } - if err := data.Close(); err != nil { - fmt.Fprintln(os.Stderr, "error closing fixture file:", err) - os.Exit(1) - } + defer func() { _ = data.Close() }() byteData, _ := ioutil.ReadAll(data) @@ -196,10 +193,7 @@ func (fixture *Fixture) EventBody() []byte { os.Exit(1) } - if err := data.Close(); err != nil { - fmt.Fprintln(os.Stderr, "error closing fixture file:", err) - os.Exit(1) - } + defer func() { _ = data.Close() }() scanner := bufio.NewScanner(data) var eventBody []byte