@cryptotaxi247 / kubo / commits / a70d82e4b

go-ipfs-config: add test validating that createIdentity follows algorithm preference

Will Scott committed Apr 28, 2020 at 09:40 UTC a70d82e4ba8cefefc7829d10faf69049d79b7d7d
1 file changed +36
config/init_test.go new
+36
@@ -0,0 +1,36 @@
1 +package config
2 +
3 +import (
4 + "bytes"
5 + "testing"
6 +
7 + "github.com/ipfs/interface-go-ipfs-core/options"
8 + crypto_pb "github.com/libp2p/go-libp2p-core/crypto/pb"
9 +)
10 +
11 +func TestCreateIdentity(t *testing.T) {
12 + writer := bytes.NewBuffer(nil)
13 + id, err := CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.Ed25519Key)})
14 + if err != nil {
15 + t.Fatal(err)
16 + }
17 + pk, err := id.DecodePrivateKey("")
18 + if err != nil {
19 + t.Fatal(err)
20 + }
21 + if pk.Type() != crypto_pb.KeyType_Ed25519 {
22 + t.Fatal("unexpected type:", pk.Type())
23 + }
24 +
25 + id, err = CreateIdentity(writer, []options.KeyGenerateOption{options.Key.Type(options.RSAKey)})
26 + if err != nil {
27 + t.Fatal(err)
28 + }
29 + pk, err = id.DecodePrivateKey("")
30 + if err != nil {
31 + t.Fatal(err)
32 + }
33 + if pk.Type() != crypto_pb.KeyType_RSA {
34 + t.Fatal("unexpected type:", pk.Type())
35 + }
36 +}