diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfe347d..99d9762 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,8 @@ on: branches: [ main ] env: - GO_VERSION: "1.26.9" - GOLANGCI_LINT_VERSION: "v2.9.0" + GO_VERSION: "1.27.3" + GOLANGCI_LINT_VERSION: "v2.15.0" permissions: {} diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index 7ad200b..1f3173d 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -1,7 +1,7 @@ name: "Security Scan" env: - GO_VERSION: "1.26.9" + GO_VERSION: "1.27.3" on: push: diff --git a/.golangci.yaml b/.golangci.yaml index 872067b..2acd902 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -6,26 +6,27 @@ run: linters: default: all disable: - - depguard - dupl + - gomodguard_v2 - exhaustruct + - exhaustruct_v5 - ireturn - nolintlint - paralleltest - testpackage - tparallel - wrapcheck - - zerologlint - goconst - noinlineerr # deprecated - wsl + - depguard settings: cyclop: max-complexity: 11 exhaustive: default-signifies-exhaustive: true - ignore-enum-members: POT.+ + ignore-constants: POT.+ funlen: lines: 80 mnd: diff --git a/message_digester_test.go b/message_digester_test.go index 2368b0f..5017ddb 100644 --- a/message_digester_test.go +++ b/message_digester_test.go @@ -2,7 +2,6 @@ package httpsig import ( "bufio" - "context" "net/http" "net/http/httptest" "strings" @@ -24,7 +23,12 @@ func TestContentDigesterVerify(t *testing.T) { { uc: "malformed content-digest header", msg: func() *Message { - req := httptest.NewRequest(http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) req.Header.Set("content-digest", ",") return MessageFromRequest(req) @@ -40,7 +44,12 @@ func TestContentDigesterVerify(t *testing.T) { { uc: "invalid digest value format", msg: func() *Message { - req := httptest.NewRequest(http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) req.Header.Set("content-digest", "sha-256") return MessageFromRequest(req) @@ -56,7 +65,12 @@ func TestContentDigesterVerify(t *testing.T) { { uc: "unknown algorithm", msg: func() *Message { - req := httptest.NewRequest(http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) req.Header.Set("content-digest", "md5=:eyJoZWxsbyI6ICJ3b3JsZCJ9:") return MessageFromRequest(req) @@ -71,7 +85,12 @@ func TestContentDigesterVerify(t *testing.T) { { uc: "digest mismatch", msg: func() *Message { - req := httptest.NewRequest(http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) req.Header.Set("content-digest", "sha-256=:eyJoZWxsbyI6ICJ3b3JsZCJ9:") return MessageFromRequest(req) @@ -86,7 +105,12 @@ func TestContentDigesterVerify(t *testing.T) { { uc: "successful request digest verification", msg: func() *Message { - req := httptest.NewRequest(http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) req.Header.Set("content-digest", "sha-256=:X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:") return MessageFromRequest(req) @@ -108,8 +132,12 @@ Content-Length: 23 {"message": "good dog"} ` - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://example.com/foo", - strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) resp, err := http.ReadResponse(bufio.NewReader(strings.NewReader(responseWithBody)), req) //nolint:bodyclose @@ -134,8 +162,12 @@ Content-Length: 23 {"message": "good dog"} ` - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://example.com/foo", - strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) req.Header.Set("content-digest", "sha-256=:X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:") @@ -175,7 +207,7 @@ func TestContentDigesterUpdate(t *testing.T) { alg: Sha256, msg: func() *Message { req, err := http.NewRequestWithContext( - context.TODO(), + t.Context(), http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`), @@ -197,7 +229,7 @@ func TestContentDigesterUpdate(t *testing.T) { uc: "digest for client-side request without specified algorithm", msg: func() *Message { req, err := http.NewRequestWithContext( - context.TODO(), + t.Context(), http.MethodGet, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`), @@ -222,8 +254,12 @@ func TestContentDigesterUpdate(t *testing.T) { uc: "digest for server-side response with specifying algorithm", alg: Sha512, msg: func() *Message { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://example.com/foo", - strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) return MessageForResponse(req, make(http.Header), []byte(`{"message": "good dog"}`), http.StatusOK) @@ -240,8 +276,12 @@ func TestContentDigesterUpdate(t *testing.T) { { uc: "digest for server-side response without specifying algorithm", msg: func() *Message { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://example.com/foo", - strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com/foo", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) return MessageForResponse(req, make(http.Header), []byte(`{"message": "good dog"}`), http.StatusOK) @@ -263,7 +303,7 @@ func TestContentDigesterUpdate(t *testing.T) { alg: Sha256, msg: func() *Message { req, err := http.NewRequestWithContext( - context.TODO(), + t.Context(), http.MethodPost, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`), @@ -289,7 +329,7 @@ func TestContentDigesterUpdate(t *testing.T) { uc: "replaces existing content-digest values without specified algorithm", msg: func() *Message { req, err := http.NewRequestWithContext( - context.TODO(), + t.Context(), http.MethodPost, "http://example.com/foo", strings.NewReader(`{"hello": "world"}`), diff --git a/message_test.go b/message_test.go index 7985916..44ee571 100644 --- a/message_test.go +++ b/message_test.go @@ -2,7 +2,6 @@ package httpsig import ( "bufio" - "context" "io" "net/http" "net/http/httptest" @@ -76,7 +75,12 @@ func TestMessageFromRequest(t *testing.T) { { uc: "outbound request without body", req: func() *http.Request { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://example.com?foo=bar", nil) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com?foo=bar", + nil, + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar") @@ -117,7 +121,12 @@ func TestMessageFromRequest(t *testing.T) { { uc: "inbound request without body", req: func() *http.Request { - req := httptest.NewRequest(http.MethodPost, "http://example.com?foo=bar", nil) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodPost, + "http://example.com?foo=bar", + nil, + ) req.Header.Set("X-Foo-Bar", "bar") return req @@ -156,8 +165,12 @@ func TestMessageFromRequest(t *testing.T) { { uc: "outbound request with body", req: func() *http.Request { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, - "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com?foo=bar", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar") @@ -198,7 +211,10 @@ func TestMessageFromRequest(t *testing.T) { { uc: "inbound request with body", req: func() *http.Request { - req := httptest.NewRequest(http.MethodPost, "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodPost, + "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) req.Header.Set("X-Foo-Bar", "bar") return req @@ -274,8 +290,12 @@ Content-Length: 23 { uc: "response without body", resp: func() *http.Response { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, - "http://example.com?foo=bar", nil) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com?foo=bar", + nil, + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar") @@ -334,8 +354,12 @@ Content-Length: 23 { uc: "response with body", resp: func() *http.Response { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodPost, - "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodPost, + "http://example.com?foo=bar", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar") @@ -416,8 +440,12 @@ func TestMessageForResponse(t *testing.T) { { uc: "response without body", req: func() *http.Request { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, - "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://example.com?foo=bar", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar") @@ -477,8 +505,12 @@ func TestMessageForResponse(t *testing.T) { { uc: "response with body", req: func() *http.Request { - req, err := http.NewRequestWithContext(context.TODO(), http.MethodPost, - "http://example.com?foo=bar", strings.NewReader(`{"hello": "world"}`)) + req, err := http.NewRequestWithContext( + t.Context(), + http.MethodPost, + "http://example.com?foo=bar", + strings.NewReader(`{"hello": "world"}`), + ) require.NoError(t, err) req.Header.Set("X-Foo-Bar", "bar")