auth/authmw/token_test.go
2023-10-27 21:46:54 +02:00

32 lines
610 B
Go

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
}