keypairs/keyfetch/uncached/fetch_test.go

86 lines
1.8 KiB
Go
Raw Permalink Normal View History

2019-02-21 00:10:42 +00:00
package uncached
import (
"crypto/ecdsa"
"crypto/rsa"
"errors"
"testing"
keypairs "github.com/big-squid/go-keypairs"
)
func TestJWKs(t *testing.T) {
urls := []string{
"https://bigsquid.auth0.com/.well-known/jwks.json",
}
for i := range urls {
url := urls[i]
_, keys, err := JWKs(url)
if nil != err {
t.Fatal(url, err)
}
for kid := range keys {
switch key := keys[kid].Key().(type) {
case *rsa.PublicKey:
_ = keypairs.ThumbprintRSAPublicKey(key)
case *ecdsa.PublicKey:
_ = keypairs.ThumbprintECPublicKey(key)
default:
t.Fatal(errors.New("unsupported interface type"))
}
}
}
}
func TestWellKnownJWKs(t *testing.T) {
urls := []string{
//"https://bigsquid.auth0.com/.well-known/jwks.json"
"https://bigsquid.auth0.com/",
}
for i := range urls {
url := urls[i]
_, keys, err := WellKnownJWKs(url)
if nil != err {
t.Fatal(url, err)
}
for kid := range keys {
switch key := keys[kid].Key().(type) {
case *rsa.PublicKey:
_ = keypairs.ThumbprintRSAPublicKey(key)
case *ecdsa.PublicKey:
_ = keypairs.ThumbprintECPublicKey(key)
default:
t.Fatal(errors.New("unsupported interface type"))
}
}
}
}
func TestOIDCJWKs(t *testing.T) {
urls := []string{
//"https://bigsquid.auth0.com/.well-known/openid-configuration"
//"https://bigsquid.auth0.com/.well-known/jwks.json"
"https://bigsquid.auth0.com/",
}
for i := range urls {
url := urls[i]
_, keys, err := OIDCJWKs(url)
if nil != err {
t.Fatal(url, err)
}
for kid := range keys {
switch key := keys[kid].Key().(type) {
case *rsa.PublicKey:
_ = keypairs.ThumbprintRSAPublicKey(key)
case *ecdsa.PublicKey:
_ = keypairs.ThumbprintECPublicKey(key)
default:
t.Fatal(errors.New("unsupported interface type"))
}
}
}
}