github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/common/service/destination_interop_test.go (about) 1 // +build ACAPyInterop 2 3 /* 4 Copyright SecureKey Technologies Inc. All Rights Reserved. 5 6 SPDX-License-Identifier: Apache-2.0 7 */ 8 9 package service 10 11 import ( 12 "testing" 13 14 "github.com/btcsuite/btcutil/base58" 15 "github.com/stretchr/testify/require" 16 17 mockdiddoc "github.com/hyperledger/aries-framework-go/pkg/mock/diddoc" 18 "github.com/hyperledger/aries-framework-go/pkg/vdr/fingerprint" 19 ) 20 21 func TestCreateDestinationFromLegacyDoc(t *testing.T) { 22 t.Run("successfully prepared destination", func(t *testing.T) { 23 doc := mockdiddoc.GetMockIndyDoc(t) 24 dest, err := CreateDestination(doc) 25 require.NoError(t, err) 26 require.NotNil(t, dest) 27 require.Equal(t, dest.ServiceEndpoint, "https://localhost:8090") 28 require.Equal(t, doc.Service[0].RoutingKeys, dest.RoutingKeys) 29 }) 30 } 31 32 func TestB58ToDIDKeys(t *testing.T) { 33 t.Run("convert recipient keys in did doc", func(t *testing.T) { 34 didDoc := mockdiddoc.GetMockIndyDoc(t) 35 36 recipientKeys := convertAnyB58Keys(didDoc.Service[0].RecipientKeys) 37 require.NotNil(t, recipientKeys) 38 require.Len(t, recipientKeys, 1) 39 40 pk, err := fingerprint.PubKeyFromDIDKey(recipientKeys[0]) 41 require.NoError(t, err) 42 require.ElementsMatch(t, didDoc.VerificationMethod[0].Value, pk) 43 }) 44 45 t.Run("no keys given", func(t *testing.T) { 46 recipientKeys := convertAnyB58Keys(nil) 47 require.Nil(t, recipientKeys) 48 }) 49 50 t.Run("some keys are converted", func(t *testing.T) { 51 inKeys := []string{ 52 "6SFxbqdqGKtVVmLvXDnq9JP4ziZCG2fJzETpMYHt1VNx", 53 "#key1", 54 "6oDmCnt5w4h2hEQ12hwvD8w5JdvMDPYMzKNv5yPVomFu", 55 "did:key:z6MkjtX1C5tGbsNxcGBdCnkfzPw4pHq3fuufgFNkBpFtviAL", 56 "QEaG6QrDbx7dQ7U5Bm1Bqvx3psrGEqSieZACZ1LyU62", 57 "/path#fragment", 58 "9onu2hZrqtcoiVTkBStZ4N8iLYd24bmuHUvx9w3jb9av", 59 "GTcPhsGS3XdkWL5mS8sxsTLzwPfSBCYVY93QeT95U6NQ", 60 "?query=value", 61 "FFPJcCWHGchhuiE5hV1BTRaiBzXpZfgYdsSPFHu6DSAC", 62 "", 63 "@!~unexpected data~!@", 64 } 65 expectedKeys := []string{ 66 "did:key:z6MkjtX1C5tGbsNxcGBdCnkfzPw4pHq3fuufgFNkBpFtviAL", 67 "#key1", 68 "did:key:z6MkkFUoo38XGcBVojEhiGum4EV58DCCdGnigLHqvFMWiz3H", 69 "did:key:z6MkjtX1C5tGbsNxcGBdCnkfzPw4pHq3fuufgFNkBpFtviAL", 70 "did:key:z6MkerVcrLfHZ9SajtxAkkir2wUwsQ9hg85oQfU62pyMtgsQ", 71 "/path#fragment", 72 "did:key:z6MkoG3wcwpJBS7GpzJSs1rPuTgiA7tsUV2FyVqszD1kWNNJ", 73 "did:key:z6MkuusSJ7WsP58DcpvU7hqoiYtzkxwHb5nrE9xLUj76PK9n", 74 "?query=value", 75 "did:key:z6MktheMCSkicACB2D4nP3y2JX8i1ZofyYvuKtMK5Zs78ewa", 76 "", 77 "@!~unexpected data~!@", 78 } 79 80 outKeys := convertAnyB58Keys(inKeys) 81 82 require.Equal(t, len(expectedKeys), len(outKeys)) 83 84 for i := range outKeys { 85 require.Equal(t, expectedKeys[i], outKeys[i]) 86 87 // if we expect the key to be converted, check if it's converted correctly 88 if inKeys[i] != expectedKeys[i] { 89 pk, err := fingerprint.PubKeyFromDIDKey(outKeys[i]) 90 require.NoError(t, err) 91 92 pkb58 := base58.Encode(pk) 93 require.Equal(t, inKeys[i], pkb58) 94 } 95 } 96 }) 97 }