auth/authmw/token_test.go

32 lines
610 B
Go
Raw Normal View History

2023-10-27 19:46:54 +00:00
package authmw
import (
"context"
"testing"
"git.t-juice.club/microfilm/auth"
"github.com/golang-jwt/jwt/v5"
"github.com/google/go-cmp/cmp"
)
func TestClaimsFromContext(t *testing.T) {
claims := &auth.MicrofilmClaims{
Role: "admin",
RegisteredClaims: jwt.RegisteredClaims{
Issuer: "test",
Subject: "subject",
},
}
ctx := context.WithValue(context.Background(), ctxKeyClaims, claims)
retrieved, err := ClaimsFromCtx(ctx)
if err != nil {
t.Fatalf("Unable to retrieve claims")
}
if diff := cmp.Diff(claims, retrieved); diff != "" {
t.Fatalf("Claims diff: %s", diff)
}
return
}