mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
go-ipfs-config: add test validating that createIdentity follows algorithm preference
This commit is contained in:
parent
c6336c3303
commit
a70d82e4ba
36
config/init_test.go
Normal file
36
config/init_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/interface-go-ipfs-core/options"
|
||||
crypto_pb "github.com/libp2p/go-libp2p-core/crypto/pb"
|
||||
)
|
||||
|
||||
func TestCreateIdentity(t *testing.T) {
|
||||
writer := bytes.NewBuffer(nil)
|
||||
id, err := CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.Ed25519Key)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pk, err := id.DecodePrivateKey("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pk.Type() != crypto_pb.KeyType_Ed25519 {
|
||||
t.Fatal("unexpected type:", pk.Type())
|
||||
}
|
||||
|
||||
id, err = CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.RSAKey)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pk, err = id.DecodePrivateKey("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pk.Type() != crypto_pb.KeyType_RSA {
|
||||
t.Fatal("unexpected type:", pk.Type())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user