add HTTP Request to TokenVerifier (#404)

The request might be needed to verify the token.

Fixes #403.
This commit is contained in:
Jonathan Amsterdam 2025-09-03 16:23:42 -04:00 • committed by GitHub
commit d0c5943f25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,13 +7,13 @@ package auth
import (
"context"
"errors"
"net/http"
"testing"
"time"
)
func TestVerify(t *testing.T) {
ctx := context.Background()
verifier := func(_ context.Context, token string) (*TokenInfo, error) {
verifier := func(_ context.Context, token string, _ *http.Request) (*TokenInfo, error) {
switch token {
case "valid":
return &TokenInfo{Expiration: time.Now().Add(time.Hour)}, nil
@ -67,7 +67,9 @@ func TestVerify(t *testing.T) {
},
} {
t.Run(tt.name, func(t *testing.T) {
_, gotMsg, gotCode := verify(ctx, verifier, tt.opts, tt.header)
_, gotMsg, gotCode := verify(&http.Request{
Header: http.Header{"Authorization": {tt.header}},
}, verifier, tt.opts)
if gotMsg != tt.wantMsg || gotCode != tt.wantCode {
t.Errorf("got (%q, %d), want (%q, %d)", gotMsg, gotCode, tt.wantMsg, tt.wantCode)
}