2023-03-02 13:05:24 +01:00
|
|
|
package jwk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJWK(t *testing.T) {
|
|
|
|
privateKey, err := Generate(DefaultKeySize)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-07-26 15:14:49 +02:00
|
|
|
keySet, err := RS256PublicKeySet(privateKey)
|
2023-03-02 13:05:24 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata := map[string]any{
|
|
|
|
"Foo": "bar",
|
|
|
|
"Test": 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
signature, err := Sign(privateKey, metadata)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Signature: %s", signature)
|
|
|
|
|
|
|
|
matches, err := Verify(keySet, signature, metadata)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !matches {
|
|
|
|
t.Error("signature should match")
|
|
|
|
}
|
|
|
|
}
|