mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-06 18:10:16 +00:00

- add ed5519 HTTP signature support - refactor truststore package - add P12 trust store support close #72
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package test
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"testing"
|
|
|
|
"github.com/ncarlier/webhookd/pkg/assert"
|
|
"github.com/ncarlier/webhookd/pkg/logger"
|
|
"github.com/ncarlier/webhookd/pkg/truststore"
|
|
)
|
|
|
|
func TestTrustStoreWithNoKeyID(t *testing.T) {
|
|
logger.Init("warn")
|
|
|
|
ts, err := truststore.New("test-key-01.pem")
|
|
assert.Nil(t, err, "")
|
|
assert.NotNil(t, ts, "")
|
|
pubkey := ts.GetPublicKey("test")
|
|
assert.True(t, pubkey == nil, "")
|
|
pubkey = ts.GetPublicKey("default")
|
|
assert.NotNil(t, pubkey, "")
|
|
_, ok := pubkey.(*rsa.PublicKey)
|
|
assert.True(t, ok, "")
|
|
}
|
|
|
|
func TestTrustStoreWithKeyID(t *testing.T) {
|
|
logger.Init("warn")
|
|
|
|
ts, err := truststore.New("test-key-02.pem")
|
|
assert.Nil(t, err, "")
|
|
assert.NotNil(t, ts, "")
|
|
pubkey := ts.GetPublicKey("test")
|
|
assert.NotNil(t, pubkey, "")
|
|
_, ok := pubkey.(*rsa.PublicKey)
|
|
assert.True(t, ok, "")
|
|
}
|
|
|
|
func TestTrustStoreWithCertificate(t *testing.T) {
|
|
logger.Init("warn")
|
|
|
|
ts, err := truststore.New("test-cert.pem")
|
|
assert.Nil(t, err, "")
|
|
assert.NotNil(t, ts, "")
|
|
pubkey := ts.GetPublicKey("test.localnet")
|
|
assert.NotNil(t, pubkey, "")
|
|
_, ok := pubkey.(*rsa.PublicKey)
|
|
assert.True(t, ok, "")
|
|
}
|
|
|
|
func TestTrustStoreWithMultipleEntries(t *testing.T) {
|
|
logger.Init("warn")
|
|
|
|
ts, err := truststore.New("test-multi.pem")
|
|
assert.Nil(t, err, "")
|
|
assert.NotNil(t, ts, "")
|
|
pubkey := ts.GetPublicKey("test.localnet")
|
|
assert.NotNil(t, pubkey, "")
|
|
_, ok := pubkey.(*rsa.PublicKey)
|
|
assert.True(t, ok, "")
|
|
pubkey = ts.GetPublicKey("foo")
|
|
assert.NotNil(t, pubkey, "")
|
|
_, ok = pubkey.(*rsa.PublicKey)
|
|
assert.True(t, ok, "")
|
|
}
|