github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/protocol/outofbandv2/oobv2_integration_test.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package outofbandv2_test 8 9 import ( 10 "fmt" 11 "testing" 12 13 "github.com/google/uuid" 14 "github.com/stretchr/testify/require" 15 16 "github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service" 17 "github.com/hyperledger/aries-framework-go/pkg/didcomm/dispatcher/outbound" 18 "github.com/hyperledger/aries-framework-go/pkg/didcomm/packer" 19 "github.com/hyperledger/aries-framework-go/pkg/didcomm/packer/anoncrypt" 20 "github.com/hyperledger/aries-framework-go/pkg/didcomm/packer/authcrypt" 21 "github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/outofbandv2" 22 "github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/presentproof" 23 "github.com/hyperledger/aries-framework-go/pkg/didcomm/transport" 24 "github.com/hyperledger/aries-framework-go/pkg/doc/did" 25 "github.com/hyperledger/aries-framework-go/pkg/doc/jose" 26 "github.com/hyperledger/aries-framework-go/pkg/framework/aries" 27 vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" 28 mockdidcomm "github.com/hyperledger/aries-framework-go/pkg/mock/didcomm" 29 mockdiddoc "github.com/hyperledger/aries-framework-go/pkg/mock/diddoc" 30 mockstore "github.com/hyperledger/aries-framework-go/pkg/mock/storage" 31 mockvdr "github.com/hyperledger/aries-framework-go/pkg/mock/vdr" 32 "github.com/hyperledger/aries-framework-go/pkg/vdr/peer" 33 ) 34 35 func TestIntegration(t *testing.T) { 36 storeProv := mockstore.NewMockStoreProvider() 37 38 ariesOpts := []aries.Option{ 39 aries.WithStoreProvider(storeProv), 40 aries.WithOutboundTransports(&mockdidcomm.MockOutboundTransport{ 41 ExpectedResponse: "foo", 42 AcceptValue: true, 43 }), 44 aries.WithMediaTypeProfiles([]string{transport.MediaTypeDIDCommV2Profile}), 45 aries.WithPacker( 46 func(prov packer.Provider) (packer.Packer, error) { 47 return authcrypt.New(prov, jose.A256CBCHS512) 48 }, 49 func(prov packer.Provider) (packer.Packer, error) { 50 return anoncrypt.New(prov, jose.A256GCM) 51 }, 52 ), 53 } 54 55 agent1, err := aries.New(ariesOpts...) 56 require.NoError(t, err) 57 58 ctx1, err := agent1.Context() 59 require.NoError(t, err) 60 61 oobSvc1, err := outofbandv2.New(ctx1) 62 require.NoError(t, err) 63 64 vdr1 := ctx1.VDRegistry() 65 66 // create other agent's "peer" DID, and save it to primary agent's VDR 67 docSave := getOOBV2PeerDoc(t) 68 69 // which we then save to agent1's vdr 70 _, err = vdr1.Create("peer", docSave, vdrapi.WithOption("store", true)) 71 require.NoError(t, err) 72 73 connID, err := oobSvc1.AcceptInvitation(&outofbandv2.Invitation{ 74 ID: uuid.New().String(), 75 Type: outofbandv2.InvitationMsgType, 76 From: docSave.ID, 77 Body: &outofbandv2.InvitationBody{}, 78 }) 79 require.NoError(t, err) 80 81 lookup := ctx1.ConnectionLookup() 82 83 connRec, err := lookup.GetConnectionRecord(connID) 84 require.NoError(t, err) 85 86 outbound1, err := outbound.NewOutbound(ctx1) 87 require.NoError(t, err) 88 89 msg := service.NewDIDCommMsgMap(presentproof.ProposePresentationV3{ 90 ID: uuid.New().String(), 91 Type: presentproof.ProposePresentationMsgTypeV3, 92 Body: presentproof.ProposePresentationV3Body{}, 93 Attachments: nil, 94 }) 95 96 err = outbound1.SendToDID(msg, connRec.MyDID, connRec.TheirDID) 97 require.NoError(t, err) 98 } 99 100 func getOOBV2PeerDoc(t *testing.T) *did.Doc { 101 t.Helper() 102 103 var ( 104 peerVDR vdrapi.VDR 105 docSave *did.Doc 106 ) 107 108 agent, err := aries.New( 109 aries.WithStoreProvider(mockstore.NewMockStoreProvider()), 110 aries.WithMediaTypeProfiles([]string{transport.MediaTypeDIDCommV2Profile}), 111 aries.WithVDR(&mockvdr.MockVDR{ 112 AcceptValue: true, 113 StoreErr: nil, 114 ReadFunc: func(didID string, opts ...vdrapi.DIDMethodOption) (*did.DocResolution, error) { 115 didVal, err := did.Parse(didID) 116 if err != nil { 117 return nil, fmt.Errorf("dummy VDR: %w", err) 118 } 119 120 return &did.DocResolution{ 121 DIDDocument: mockdiddoc.GetMockDIDDocWithDIDCommV2Bloc(t, didVal.MethodSpecificID), 122 }, nil 123 }, 124 CreateFunc: func(doc *did.Doc, opts ...vdrapi.DIDMethodOption) (*did.DocResolution, error) { 125 res, err := peerVDR.Create(doc, opts...) 126 if err != nil { 127 return nil, err 128 } 129 130 docSave = res.DIDDocument 131 132 return res, nil 133 }, 134 UpdateFunc: nil, 135 DeactivateFunc: nil, 136 CloseErr: nil, 137 }), 138 ) 139 require.NoError(t, err) 140 141 ctx, err := agent.Context() 142 require.NoError(t, err) 143 144 peerVDR, err = peer.New(ctx.StorageProvider()) 145 require.NoError(t, err) 146 147 oobSvc, err := outofbandv2.New(ctx) 148 require.NoError(t, err) 149 150 _, err = oobSvc.AcceptInvitation(&outofbandv2.Invitation{ 151 ID: uuid.New().String(), 152 Type: outofbandv2.InvitationMsgType, 153 From: "did:peer:dummyDID", 154 Body: &outofbandv2.InvitationBody{}, 155 }) 156 require.NoError(t, err) 157 158 require.NotNil(t, docSave) 159 160 return docSave 161 }