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
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
push:

jobs:
testgo:
name: Test Go
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true

- name: Lint
run: go vet ./...

- name: Test
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic

- name: golangci-lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.57
10 changes: 8 additions & 2 deletions alg_hmac/alg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func TestHMAC(t *testing.T) {
baseFunc: func() string {
// return different data each time
key := make([]byte, 32)
rand.Read(key)
_, err := rand.Read(key)
if err != nil {
panic(err)
}
return string(key)
},
wantSignErr: nil,
Expand All @@ -55,7 +58,10 @@ func TestHMAC(t *testing.T) {
name: "different key",
keyFunc: func() []byte {
key := make([]byte, 32)
rand.Read(key)
_, err := rand.Read(key)
if err != nil {
panic(err)
}
return key
},
baseFunc: func() string { return `hmac base` },
Expand Down
2 changes: 1 addition & 1 deletion e2e/client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestE2E(t *testing.T) {
mux.Handle("/", verifier(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
attr := httpsig.AttributesFromContext(r.Context()).(userAttributes)
msg := fmt.Sprintf("hello, %s!", attr.Username)
w.Write([]byte(msg))
_, _ = w.Write([]byte(msg))
})))

defer server.Close()
Expand Down
6 changes: 3 additions & 3 deletions example/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

func main() {
// Example public key only, do not use for anything other than this example
// as the private key is hard-coded in the client
// Example public key only, do not use for anything other than this example
// as the private key is hard-coded in the client
keyString := `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqIVYZVLCrPZHGHjP17CTW0/+D9Lf
w0EkjqF7xB4FivAxzic30tMM4GF+hR6Dxh71Z50VGGdldkkDXZCnTNnoXQ==
Expand Down Expand Up @@ -61,7 +61,7 @@ w0EkjqF7xB4FivAxzic30tMM4GF+hR6Dxh71Z50VGGdldkkDXZCnTNnoXQ==
mux.Handle("/", verifier(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
attr := httpsig.AttributesFromContext(r.Context()).(exampleAttributes)
msg := fmt.Sprintf("hello, %s!", attr.Username)
w.Write([]byte(msg))
_, _ = w.Write([]byte(msg))
})))

err = http.ListenAndServe("localhost:9091", mux)
Expand Down
4 changes: 2 additions & 2 deletions integrationtest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestECDSA(t *testing.T) {
_, _, err = v.Parse(w, r, now)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
}
}))
defer svr.Close()
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestECDSA_InvalidSignature(t *testing.T) {
_, _, err = v.Parse(w, r, now)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
}
}))
defer svr.Close()
Expand Down
4 changes: 2 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func Middleware(opts MiddlewareOpts) func(next http.Handler) http.Handler {

if errors.As(err, new(*http.MaxBytesError)) {
w.WriteHeader(http.StatusRequestEntityTooLarge)
w.Write([]byte(http.StatusText(http.StatusRequestEntityTooLarge)))
_, _ = w.Write([]byte(http.StatusText(http.StatusRequestEntityTooLarge)))
return
}

if err != nil {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
_, _ = w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
return
}

Expand Down
2 changes: 0 additions & 2 deletions signer/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/common-fate/httpsig/contentdigest"
"github.com/common-fate/httpsig/signature"
"github.com/common-fate/httpsig/sigparams"
"github.com/google/go-cmp/cmp"
Expand All @@ -17,7 +16,6 @@ func TestSigner_Sign(t *testing.T) {
keyID string
alg Algorithm
tag string
digester contentdigest.Digester
now time.Time
nonce string
}
Expand Down
3 changes: 0 additions & 3 deletions verifier/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ func TestVerifier_Parse(t *testing.T) {
Authority string
Scheme string
}
type args struct {
req func() *http.Request
}
tests := []struct {
name string
fields fields
Expand Down