internal/publickey: add eddsa tests
Added tests for EdDSA keys. Subsequently, some fixes were introduced. Also, ECDSA's test names were fixed to avoid collusions. As a bonus some unused code were removed.main
parent
365a8d3ee2
commit
a7afee7530
@ -0,0 +1,75 @@
|
||||
package publickey_test
|
||||
|
||||
import (
|
||||
"mercan.dev/dumb-jose/internal/publickey"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
ValidEdDSAPublicKey = `{
|
||||
"crv": "Ed25519",
|
||||
"x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo"
|
||||
}`
|
||||
|
||||
InvalidEdDSACurveType = `{
|
||||
"crv": "Ed448",
|
||||
"x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo"
|
||||
}`
|
||||
|
||||
InvalidEdDSACurvePoint = `{
|
||||
"crv": "Ed25519",
|
||||
"x": "AQAB"
|
||||
}`
|
||||
)
|
||||
|
||||
var (
|
||||
IncompleteEdDSAPublicKeyPermutation = []string{
|
||||
`{ "crv": "Ed25519" }`,
|
||||
`{ "x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" }`,
|
||||
}
|
||||
|
||||
MalformedEdDSAPublicKey = []string{
|
||||
`Wait this isn't even JSON!`,
|
||||
`{ "crv": "Ed25519", "x": 123456790 }`,
|
||||
`{ "crv": Ed25519, "x": "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" }`,
|
||||
}
|
||||
)
|
||||
|
||||
func TestEdDSAValidCurvePoint(t *testing.T) {
|
||||
_, err := publickey.ParseEdDSAPublicKey([]byte(ValidEdDSAPublicKey))
|
||||
if err != nil {
|
||||
t.Fatalf("Expected pass while parsing, found error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdDSAInvalidCurveTypeDenial(t *testing.T) {
|
||||
_, err := publickey.ParseEdDSAPublicKey([]byte(InvalidEdDSACurveType))
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to fail for but didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdDSAInvalidCurvePointDenial(t *testing.T) {
|
||||
_, err := publickey.ParseEdDSAPublicKey([]byte(InvalidEdDSACurvePoint))
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to fail for but didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdDSAIncompletePublicKeyDenial(t *testing.T) {
|
||||
for _, key := range IncompleteEdDSAPublicKeyPermutation {
|
||||
_, err := publickey.ParseEdDSAPublicKey([]byte(key))
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to fail for %s but didn't", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdDSAMalformedPublicKeyDenial(t *testing.T) {
|
||||
for _, key := range MalformedEdDSAPublicKey {
|
||||
_, err := publickey.ParseEdDSAPublicKey([]byte(key))
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to fail for %s but didn't", key)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
package publickey
|
||||
|
||||
type JWKPublicKeyHeader interface{}
|
Loading…
Reference in New Issue