32 lines
610 B
Go
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
|
|
}
|