Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Security Scan"

env:
GO_VERSION: "1.26.9"
GO_VERSION: "1.27.3"

on:
push:
Expand Down
7 changes: 4 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 58 additions & 18 deletions message_digester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httpsig

import (
"bufio"
"context"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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=:")

Expand Down Expand Up @@ -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"}`),
Expand All @@ -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"}`),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"}`),
Expand All @@ -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"}`),
Expand Down
60 changes: 46 additions & 14 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httpsig

import (
"bufio"
"context"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
Loading