mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-29 15:49:41 +08:00
46 lines
972 B
Go
46 lines
972 B
Go
package jwk
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/lestrrat-go/jwx/v2/jwa"
|
|
"github.com/lestrrat-go/jwx/v2/jwk"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerator(t *testing.T) {
|
|
for k, c := range []struct {
|
|
g KeyGenerator
|
|
name string
|
|
check func(ks jwk.Key)
|
|
}{
|
|
{
|
|
g: &RSAKeyGenerator{},
|
|
name: "generate_rsa_jwk",
|
|
check: func(ks jwk.Key) {
|
|
//assert.Len(t, ks, 2)
|
|
rsaKey, ok := (ks).(jwk.RSAPrivateKey)
|
|
if !ok {
|
|
t.Fail()
|
|
}
|
|
keyId, _ := rsaKey.Get(jwk.KeyIDKey)
|
|
assert.Equal(t, keyId, "my_key_id")
|
|
assert.Equal(t, jwa.RSA, rsaKey.KeyType())
|
|
buf, err := json.MarshalIndent(rsaKey, "", " ")
|
|
require.NoError(t, err)
|
|
t.Logf("%s\n", buf)
|
|
},
|
|
},
|
|
} {
|
|
t.Run(fmt.Sprintf("case=%d - %v", k, c.name), func(t *testing.T) {
|
|
keys, err := c.g.Generate("my_key_id")
|
|
require.NoError(t, err)
|
|
if err == nil {
|
|
c.check(keys)
|
|
}
|
|
})
|
|
}
|
|
}
|